Message ID | 20230414110821.21548-3-p.raghav@samsung.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp306095vqo; Fri, 14 Apr 2023 04:28:07 -0700 (PDT) X-Google-Smtp-Source: AKy350a7dcvQtoJvYR155Pl4T+nOXqWnIj+ysaXGYiMahttFLX2dSiQNoF4LdUTeESRslbiOD9pn X-Received: by 2002:a17:90b:f84:b0:246:fc58:d77b with SMTP id ft4-20020a17090b0f8400b00246fc58d77bmr5121154pjb.44.1681471687196; Fri, 14 Apr 2023 04:28:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681471687; cv=none; d=google.com; s=arc-20160816; b=XPm7VSIoM2Eg2l/zdsKTsRTB5RL0uuSG7/QD3GVrWEM/roWz5LweT4nrPgq2Np3t46 Yzuts6jGsWkyfoOmfuHfGB6WwxJjhZeiiJooisGtsUBru5T2rlF+cbfYNw3lyYpc3uUt n1aHpa0UmoRrj/ELw93+acmtx8aG0jcb3wZtIcwMJnS5HLba79x0B+iexTnzuyi3bvcg Tlawbem8BsmvlK0SisqhiN2lkqbADEHE9HMf0N8TY53qa0pRIqcFAMbb5FjaAMlT7Ymh 6q92IA5Nh1qyFefUF5lBbP1qtlJTv5jR/CFYv+ySJaMrANOFLi5+Yc7Amvt8jc/VvDlv Lvfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :mime-version:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=lOgNCG8+j9glN6g01kkt3qiHQuDvi5vkCnsii6V5uAc=; b=HX3I90jCqZdNWx5tFW0Y19Xytan3ZJmTv09GLz83X7+dZdHNvW8u9AKRLxqiM6SR51 HWN4jgB1Zy/Fx4ValPioilPFZzVCf9GV8psDsl1NmECffjwEgul3TIH8D4BELWL3y5f8 hcExcC2dbmuyyYkbqV2HuJ97eMGaF5lOqNcgmeSFG7Y5JVuPe3kqeT7hf46Z5wkHzy5t WMwaeMrqm+DhQ1wjGwYUszrL/8octxj9JPlSw642sURWsLZuejylAedtdfqSC9ZlSEZF /cx7cFXzZqxg1nXAArxV1UJVmcFNWABzmEiPLSbpAxVAYuBpCCzJwphD22Tgtnc9RUSl 8lJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="iWE/tHfM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c3-20020a17090a8d0300b002402275fc56si4303726pjo.118.2023.04.14.04.27.52; Fri, 14 Apr 2023 04:28:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="iWE/tHfM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231132AbjDNLIi (ORCPT <rfc822;leviz.kernel.dev@gmail.com> + 99 others); Fri, 14 Apr 2023 07:08:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230321AbjDNLIb (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 14 Apr 2023 07:08:31 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60C7F1717 for <linux-kernel@vger.kernel.org>; Fri, 14 Apr 2023 04:08:29 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230414110827euoutp01e003a67f45a557b560b5457253025ed5~VyISSYGrd1324913249euoutp015 for <linux-kernel@vger.kernel.org>; Fri, 14 Apr 2023 11:08:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230414110827euoutp01e003a67f45a557b560b5457253025ed5~VyISSYGrd1324913249euoutp015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1681470507; bh=lOgNCG8+j9glN6g01kkt3qiHQuDvi5vkCnsii6V5uAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iWE/tHfMioyKOEecs7lOsNIQD2wiGi4J7iD8mokUHLffG+SDIfB67l00xjQU6B7l8 SDbJgpoQjal9+YvVKmOUsjsoV0e9GkVPr184l8ekaZjt7e13/2G9v/YrDEpYeXsTjY tm5O2pRzURtX+2At0XfxyEaJTluNzrFPEvCtFcCs= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230414110826eucas1p2801083c055bbebf8b958862c5a463047~VyIRh-Xsc3134131341eucas1p21; Fri, 14 Apr 2023 11:08:26 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 1D.25.09966.A2439346; Fri, 14 Apr 2023 12:08:26 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230414110826eucas1p2c5afcbd64c536a803751b41d03eb9e99~VyIRPTb5z0087400874eucas1p2A; Fri, 14 Apr 2023 11:08:26 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230414110826eusmtrp201580c3c89bd58675a349e7c6c7667b0~VyIROq8NL0913109131eusmtrp2V; Fri, 14 Apr 2023 11:08:26 +0000 (GMT) X-AuditID: cbfec7f4-d39ff700000026ee-e8-6439342a5fc5 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id FD.39.34412.A2439346; Fri, 14 Apr 2023 12:08:26 +0100 (BST) Received: from localhost (unknown [106.210.248.243]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230414110826eusmtip2f71aa69c101c25276f134b498a5df907~VyIRCV4Yn2606126061eusmtip2f; Fri, 14 Apr 2023 11:08:26 +0000 (GMT) From: Pankaj Raghav <p.raghav@samsung.com> To: brauner@kernel.org, willy@infradead.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mcgrof@kernel.org, gost.dev@samsung.com, hare@suse.de, Pankaj Raghav <p.raghav@samsung.com> Subject: [RFC 2/4] buffer: add alloc_folio_buffers() helper Date: Fri, 14 Apr 2023 13:08:19 +0200 Message-Id: <20230414110821.21548-3-p.raghav@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414110821.21548-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Sa0hTYRjHe3fm2XE4Oc7KB7O0dTOb617HZlphdKI++KWIAm3p8VJz2ubK MkIrlkuadsNLC+1m5qqRM2tm1IyctzAScjNQyllpmXjBVlLL0zHqy8vveZ7//7nAS2Diq16B RKoqk1GrFEoJLuTXNn5vDw9bFZG4zHMinDKa7+DU5+cjiHI+s/Ko+mvnJ58nzXyqo86IU47C PkSN3jwloNp/2r2oCbcR3yCkLZVhdHWVHqebiif4tKGmCtGW1mx6tHoOXe0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KLy1JVcjILy6xVYo2tDDSM7S00DMysdQz NDaPtTIyVdK3s0lJzcksSy3St0vQyzi4O66gW7Di48f/bA2Ml3m7GDk4JARMJNa3sXUxcnEI CSxllNh4YjZrFyMnUFxC4vbCJkYIW1jiz7UuqKLnjBIn52xjB2lmE9CSaOxkB6kREUiVOH3i I1gNs8AyRok1c1+wgSSEBawl+nsfMoPUswioSqybLgYS5hWwlJh6YzMzxHx5if0Hz4LZnAJW Em+WXQBrFQKqad+yhAWiXlDi5MwnYDYzUH3z1tnMExgFZiFJzUKSWsDItIpRJLW0ODc9t9hI rzgxt7g0L10vOT93EyMwerYd+7llB+PKVx/1DjEycTAeYpTgYFYS4f3hYpoixJuSWFmVWpQf X1Sak1p8iNEU6OyJzFKiyfnA+M0riTc0MzA1NDGzNDC1NDNWEuf1LOhIFBJITyxJzU5NLUgt gulj4uCUamCa+16y507ZkiPKpbof33/4c6v73aW7PjEptosKFrDFRIgEnt56I9QpaX1l3f5d 1TvNml4+PZddfO+gGt/K7zOic8xEk07sjeypyP70/qDA758tBjlG00PqJnz+z1uvvrL/jp7l bFe9DfLhP6sfiNcKWNiHrby8hPX8lN/Z/h/dw7RF9y1fc0tn4UqvSQ+mBDU/vF3d+lTSQ9Wh T8ghRHu7xAqDrY/vvQv9lauusOJsj/RE9d8KdpZph7UWvpNYNH/z2yLd+A8nvt/1bDcUWXE3 T3PmJPXC/hsRokz8uj9nrb0deXbbPd8Oh5uv1oWph79dlbO/5NodwbSHLDle7438pinnCC6v nNIeYGH0Z/4XJZbijERDLeai4kQAKyWFnycDAAA= X-CMS-MailID: 20230414110826eucas1p2c5afcbd64c536a803751b41d03eb9e99 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20230414110826eucas1p2c5afcbd64c536a803751b41d03eb9e99 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230414110826eucas1p2c5afcbd64c536a803751b41d03eb9e99 References: <20230414110821.21548-1-p.raghav@samsung.com> <CGME20230414110826eucas1p2c5afcbd64c536a803751b41d03eb9e99@eucas1p2.samsung.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763150855858590208?= X-GMAIL-MSGID: =?utf-8?q?1763150855858590208?= |
Series | convert create_page_buffers to create_folio_buffers | |
Commit Message
Pankaj Raghav
April 14, 2023, 11:08 a.m. UTC
Folio version of alloc_page_buffers() helper. This is required to convert
create_page_buffers() to create_folio_buffers() later in the series.
It removes one call to compound_head() compared to alloc_page_buffers().
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
fs/buffer.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
Comments
On Fri, Apr 14, 2023 at 01:08:19PM +0200, Pankaj Raghav wrote: > Folio version of alloc_page_buffers() helper. This is required to convert > create_page_buffers() to create_folio_buffers() later in the series. > > It removes one call to compound_head() compared to alloc_page_buffers(). I would convert alloc_page_buffers() to folio_alloc_buffers() and add static struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size, bool retry) { return folio_alloc_buffers(page_folio(page), size, retry); } in buffer_head.h (there are only five callers, so this feels like a better tradeoff than creating a new function) > Signed-off-by: Pankaj Raghav <p.raghav@samsung.com> > --- > fs/buffer.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 59 insertions(+) > > diff --git a/fs/buffer.c b/fs/buffer.c > index 44380ff3a31f..0f9c2127543d 100644 > --- a/fs/buffer.c > +++ b/fs/buffer.c > @@ -900,6 +900,65 @@ struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size, > } > EXPORT_SYMBOL_GPL(alloc_page_buffers); > > +/* > + * Create the appropriate buffers when given a folio for data area and > + * the size of each buffer.. Use the bh->b_this_page linked list to > + * follow the buffers created. Return NULL if unable to create more > + * buffers. > + * > + * The retry flag is used to differentiate async IO (paging, swapping) > + * which may not fail from ordinary buffer allocations. > + */ > +struct buffer_head *alloc_folio_buffers(struct folio *folio, unsigned long size, > + bool retry) > +{ > + struct buffer_head *bh, *head; > + gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT; > + long offset; > + struct mem_cgroup *memcg, *old_memcg; > + > + if (retry) > + gfp |= __GFP_NOFAIL; > + > + /* The folio lock pins the memcg */ > + memcg = folio_memcg(folio); > + old_memcg = set_active_memcg(memcg); > + > + head = NULL; > + offset = folio_size(folio); > + while ((offset -= size) >= 0) { > + bh = alloc_buffer_head(gfp); > + if (!bh) > + goto no_grow; > + > + bh->b_this_page = head; > + bh->b_blocknr = -1; > + head = bh; > + > + bh->b_size = size; > + > + /* Link the buffer to its folio */ > + set_bh_folio(bh, folio, offset); > + } > +out: > + set_active_memcg(old_memcg); > + return head; > +/* > + * In case anything failed, we just free everything we got. > + */ > +no_grow: > + if (head) { > + do { > + bh = head; > + head = head->b_this_page; > + free_buffer_head(bh); > + } while (head); > + } > + > + goto out; > +} > +EXPORT_SYMBOL_GPL(alloc_folio_buffers); > + > static inline void > link_dev_buffers(struct page *page, struct buffer_head *head) > { > -- > 2.34.1 >
On 2023-04-14 15:06, Matthew Wilcox wrote: > On Fri, Apr 14, 2023 at 01:08:19PM +0200, Pankaj Raghav wrote: >> Folio version of alloc_page_buffers() helper. This is required to convert >> create_page_buffers() to create_folio_buffers() later in the series. >> >> It removes one call to compound_head() compared to alloc_page_buffers(). > > I would convert alloc_page_buffers() to folio_alloc_buffers() and > add > > static struct buffer_head *alloc_page_buffers(struct page *page, > unsigned long size, bool retry) > { > return folio_alloc_buffers(page_folio(page), size, retry); > } > > in buffer_head.h > > (there are only five callers, so this feels like a better tradeoff > than creating a new function) > That is a good idea and follows the usual pattern for folio conversion. I will send a new version soon with your other comments as well. -- Pankaj
diff --git a/fs/buffer.c b/fs/buffer.c index 44380ff3a31f..0f9c2127543d 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -900,6 +900,65 @@ struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size, } EXPORT_SYMBOL_GPL(alloc_page_buffers); +/* + * Create the appropriate buffers when given a folio for data area and + * the size of each buffer.. Use the bh->b_this_page linked list to + * follow the buffers created. Return NULL if unable to create more + * buffers. + * + * The retry flag is used to differentiate async IO (paging, swapping) + * which may not fail from ordinary buffer allocations. + */ +struct buffer_head *alloc_folio_buffers(struct folio *folio, unsigned long size, + bool retry) +{ + struct buffer_head *bh, *head; + gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT; + long offset; + struct mem_cgroup *memcg, *old_memcg; + + if (retry) + gfp |= __GFP_NOFAIL; + + /* The folio lock pins the memcg */ + memcg = folio_memcg(folio); + old_memcg = set_active_memcg(memcg); + + head = NULL; + offset = folio_size(folio); + while ((offset -= size) >= 0) { + bh = alloc_buffer_head(gfp); + if (!bh) + goto no_grow; + + bh->b_this_page = head; + bh->b_blocknr = -1; + head = bh; + + bh->b_size = size; + + /* Link the buffer to its folio */ + set_bh_folio(bh, folio, offset); + } +out: + set_active_memcg(old_memcg); + return head; +/* + * In case anything failed, we just free everything we got. + */ +no_grow: + if (head) { + do { + bh = head; + head = head->b_this_page; + free_buffer_head(bh); + } while (head); + } + + goto out; +} +EXPORT_SYMBOL_GPL(alloc_folio_buffers); + static inline void link_dev_buffers(struct page *page, struct buffer_head *head) {