Message ID | 20230315123233.121593-2-p.raghav@samsung.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2319650wrd; Wed, 15 Mar 2023 06:10:43 -0700 (PDT) X-Google-Smtp-Source: AK7set8+2BpEx6bQ4S3lZmfCT+MO2yjF+W9cLXR2LNxJXr09ygTxp1YyCB9LhCmP+jwjr62LOE/s X-Received: by 2002:a17:90b:3b89:b0:234:ba6f:c980 with SMTP id pc9-20020a17090b3b8900b00234ba6fc980mr43777860pjb.17.1678885842327; Wed, 15 Mar 2023 06:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678885842; cv=none; d=google.com; s=arc-20160816; b=jPg/mmWJhBeqkvBBQyYbQvtR1vW3QxLz4JG07cZTV2DM6pUJcyOlRweSeVPQhnvx7s DOYoqE7nhweB8YLhwZr/m9GH9gBF2UbMrUoCugEbfSCdqVSVKfMvkCmNmZeTwXwaKJdm IrQAIGDZXaUISxm0cln3vrqcrKMk/N6Q31D6E+FyZOfso12UiLWqoh0kn/VEDdJPqSvC dBlaLS/tf6kTj8TCnomJBl57CKpC04fYaS4Z+yijADG76O/PcFA45Xbj19bPRuyOVZbz ZERv8IvzNwg1x9RYgstXkFSVl9ZgH5qfZEQEJypV51PFx2KQEL40VwEQkcQnWnj/jphH R/vQ== 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=Dyt/yPdeYY+WSauc7HCejFF6ehE2pQBkEGu9AWh2ZjE=; b=iVt2ZSTvR/jLbORd1TPg7qaIJiy2MJoPoRgZreGj1qnaJRCRa6KGQjA/Ejs5JFRjOA mMcKn7L5IyMeQ5/vp7ECrVmFwssv3DXUO3IlzlW0j4DmTaT4fPfPDWbGa7APfx5H2ZIu kye5pIA2vNLcRlM50CfWNsS4lvvtuwW0uaL9sg7ASPFvUoWR65gKByI3jRDWtnuj/th8 kW5oYJXdjMcjYbC5X7f6VvraQRUyZl8ahCDxNQ/WdR74yBw9qOseYVe43AEM4DZD0wCw vNT4f1c/XB/tmBkm5XHDLiIJKPNMw2vmrs8uRRKfAPVD8/kdoFfY3PdLPTmxivfPwPrh dpbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=nBeOb9g4; 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 k2-20020a17090a39c200b00233d4df537asi1581107pjf.158.2023.03.15.06.10.06; Wed, 15 Mar 2023 06:10:42 -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=nBeOb9g4; 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 S232760AbjCOMe1 (ORCPT <rfc822;ruipengqi7@gmail.com> + 99 others); Wed, 15 Mar 2023 08:34:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232656AbjCOMeB (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 15 Mar 2023 08:34:01 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A17A9F23B for <linux-kernel@vger.kernel.org>; Wed, 15 Mar 2023 05:32:44 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230315123237euoutp02a4adc75b3d397c6c663384bae69de38f~Ml7NG4mgY2729527295euoutp02y for <linux-kernel@vger.kernel.org>; Wed, 15 Mar 2023 12:32:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230315123237euoutp02a4adc75b3d397c6c663384bae69de38f~Ml7NG4mgY2729527295euoutp02y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1678883557; bh=Dyt/yPdeYY+WSauc7HCejFF6ehE2pQBkEGu9AWh2ZjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nBeOb9g47+WTg0gPxup2I2BPLrkSw+oMGg6E1+/Fv6cjB0d1wJU/olmOnbTN1+W+x A9x8m2a9PBcQWg/2hjC09UBMDLEaQcPF6aHtaQ0OnA9qPg9NJ0uBu0Jh526Olghp1A lJJOTS9swRM/LeXUbPt6wyEui41MZYWZWxXTMPWs= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230315123235eucas1p2a826de56db29b259200ca5b32853ec59~Ml7LWvFV91506715067eucas1p2v; Wed, 15 Mar 2023 12:32:35 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 2D.70.09503.3EAB1146; Wed, 15 Mar 2023 12:32:35 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230315123234eucas1p2503d83ad0180cecde02e924d7b143535~Ml7K6PVSi2825828258eucas1p2k; Wed, 15 Mar 2023 12:32:34 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230315123234eusmtrp15eee728631fe9cf040f7e0e808da32d1~Ml7K5pMfN1056310563eusmtrp1v; Wed, 15 Mar 2023 12:32:34 +0000 (GMT) X-AuditID: cbfec7f2-ea5ff7000000251f-16-6411bae3a382 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 5E.AF.09583.2EAB1146; Wed, 15 Mar 2023 12:32:34 +0000 (GMT) Received: from localhost (unknown [106.210.248.172]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230315123234eusmtip1bb76bd37b558769186fe3dea555acaba~Ml7KooprZ1241212412eusmtip1o; Wed, 15 Mar 2023 12:32:34 +0000 (GMT) From: Pankaj Raghav <p.raghav@samsung.com> To: hubcap@omnibond.com, senozhatsky@chromium.org, martin@omnibond.com, willy@infradead.org, minchan@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, axboe@kernel.dk, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, gost.dev@samsung.com, mcgrof@kernel.org, devel@lists.orangefs.org, Pankaj Raghav <p.raghav@samsung.com> Subject: [RFC PATCH 1/3] filemap: convert page_endio to folio_endio Date: Wed, 15 Mar 2023 13:32:31 +0100 Message-Id: <20230315123233.121593-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315123233.121593-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrHKsWRmVeSWpSXmKPExsWy7djPc7qPdwmmGMz6K2YxZ/0aNovVd/vZ LF4f/sRosX/zFCaLmwd2Mlm03+1jsth7S9tiz96TLBaXd81hs7i35j+rxcn1/5ktbkx4ymix 7Ot7d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zmspV/eaDxvSksgxnzUy3h9Jr S1T8vrT8/pin/y7dte+toBJLcUaioRZzUXEiAFEdsWVhAwAA X-CMS-MailID: 20230315123234eucas1p2503d83ad0180cecde02e924d7b143535 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20230315123234eucas1p2503d83ad0180cecde02e924d7b143535 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230315123234eucas1p2503d83ad0180cecde02e924d7b143535 References: <20230315123233.121593-1-p.raghav@samsung.com> <CGME20230315123234eucas1p2503d83ad0180cecde02e924d7b143535@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, URIBL_BLOCKED autolearn=unavailable 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?1760439401036495879?= X-GMAIL-MSGID: =?utf-8?q?1760439401036495879?= |
Series |
convert page_endio to folio_endio
|
|
Commit Message
Pankaj Raghav
March 15, 2023, 12:32 p.m. UTC
page_endio() already works on folios by converting a page in to a folio as
the first step. Convert page_endio to folio_endio by taking a folio as the
first parameter.
Instead of doing a page to folio conversion in the page_endio()
function, the consumers of this API do this conversion and call the
folio_endio() function in this patch.
The following patches will convert the consumers of this API to use native
folio functions to pass to folio_endio().
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
drivers/block/zram/zram_drv.c | 2 +-
fs/mpage.c | 2 +-
fs/orangefs/inode.c | 2 +-
include/linux/pagemap.h | 2 +-
mm/filemap.c | 8 +++-----
5 files changed, 7 insertions(+), 9 deletions(-)
Comments
On Wed, Mar 15, 2023 at 01:32:31PM +0100, Pankaj Raghav wrote: > page_endio() already works on folios by converting a page in to a folio as > the first step. Convert page_endio to folio_endio by taking a folio as the > first parameter. > > Instead of doing a page to folio conversion in the page_endio() > function, the consumers of this API do this conversion and call the > folio_endio() function in this patch. > The following patches will convert the consumers of this API to use native > folio functions to pass to folio_endio(). > > Signed-off-by: Pankaj Raghav <p.raghav@samsung.com> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Perhaps the hard thing is what tree would this go through? Luis
On 3/15/23 13:32, Pankaj Raghav wrote: > page_endio() already works on folios by converting a page in to a folio as > the first step. Convert page_endio to folio_endio by taking a folio as the > first parameter. > > Instead of doing a page to folio conversion in the page_endio() > function, the consumers of this API do this conversion and call the > folio_endio() function in this patch. > The following patches will convert the consumers of this API to use native > folio functions to pass to folio_endio(). > > Signed-off-by: Pankaj Raghav <p.raghav@samsung.com> > --- > drivers/block/zram/zram_drv.c | 2 +- > fs/mpage.c | 2 +- > fs/orangefs/inode.c | 2 +- > include/linux/pagemap.h | 2 +- > mm/filemap.c | 8 +++----- > 5 files changed, 7 insertions(+), 9 deletions(-) > > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > index aa490da3cef2..f441251c9138 100644 > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -610,7 +610,7 @@ static void zram_page_end_io(struct bio *bio) > { > struct page *page = bio_first_page_all(bio); > > - page_endio(page, op_is_write(bio_op(bio)), > + folio_endio(page_folio(page), op_is_write(bio_op(bio)), > blk_status_to_errno(bio->bi_status)); > bio_put(bio); > } > diff --git a/fs/mpage.c b/fs/mpage.c > index 22b9de5ddd68..40e86e839e77 100644 > --- a/fs/mpage.c > +++ b/fs/mpage.c > @@ -50,7 +50,7 @@ static void mpage_end_io(struct bio *bio) > > bio_for_each_segment_all(bv, bio, iter_all) { > struct page *page = bv->bv_page; > - page_endio(page, bio_op(bio), > + folio_endio(page_folio(page), bio_op(bio), > blk_status_to_errno(bio->bi_status)); > } > Can't this be converted to use 'bio_for_each_folio_all()' instead of bio_for_each_segment_all()? Cheers, Hannes
Can we take a step back and figure out if page_endio is a good idea to start with? The zram usage seems clearly wrong to me. zram is a block driver and does not own the pages, so it shouldn't touch any of the page state. It seems like this mostly operates on it's own pages allocated using alloc_page so the harm might not be horrible at least. orangefs uses it on readahead pages, with ret known for the whole iteration. So one quick loop for the success and one for the failure case would look simpler an more obvious. mpage really should use separate end_io handler for read vs write as well like most other aops do. So overall I'd be happier to just kill the helper.
Hi Christoph, On 2023-03-15 15:56, Christoph Hellwig wrote: > Can we take a step back and figure out if page_endio is a good > idea to start with? > > The zram usage seems clearly wrong to me. zram is a block driver > and does not own the pages, so it shouldn't touch any of the page > state. It seems like this mostly operates on it's own > pages allocated using alloc_page so the harm might not be horrible > at least. > It looks like this endio function is called when alloc_page is used (for partial IO) to trigger writeback from the user space `echo "idle" > /sys/block/zram0/writeback`. I don't understand when you say the harm might not be horrible if we don't call folio_endio here. Do you think it is just safe to remove the call to folio_endio function? > orangefs uses it on readahead pages, with ret known for the whole > iteration. So one quick loop for the success and one for the > failure case would look simpler an more obvious. > Got it. Something like this? @@ -266,18 +266,23 @@ static void orangefs_readahead(struct readahead_control *rac) iov_iter_xarray(&iter, ITER_DEST, i_pages, offset, readahead_length(rac)); /* read in the pages. */ - if ((ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, - &offset, &iter, readahead_length(rac), - inode->i_size, NULL, NULL, rac->file)) < 0) + if ((ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, &offset, &iter, + readahead_length(rac), inode->i_size, + NULL, NULL, rac->file)) < 0) { gossip_debug(GOSSIP_FILE_DEBUG, - "%s: wait_for_direct_io failed. \n", __func__); - else - ret = 0; + "%s: wait_for_direct_io failed. \n", __func__); - /* clean up. */ - while ((page = readahead_page(rac))) { - page_endio(page, false, ret); - put_page(page); + while ((folio = readahead_folio(rac))) { + folio_clear_uptodate(folio); + folio_set_error(folio); + folio_unlock(folio); + } + return; + } + + while ((folio = readahead_folio(rac))) { + folio_mark_uptodate(folio); + folio_unlock(folio); } } > mpage really should use separate end_io handler for read vs write > as well like most other aops do. > I don't know if this is the right abstraction to do the switch, but let me know what you think: @@ -59,7 +59,8 @@ static void mpage_end_io(struct bio *bio) static struct bio *mpage_bio_submit(struct bio *bio) { - bio->bi_end_io = mpage_end_io; + bio->bi_end_io = (op_is_write(bio_op(bio))) ? mpage_write_end_io : + mpage_read_end_io; guard_bio_eod(bio); submit_bio(bio); return NULL; And mpage_{write,read}_end_io will iterate over the folio and call the respective functions. > So overall I'd be happier to just kill the helper.
On Thu, Mar 16, 2023 at 11:04:54AM +0100, Pankaj Raghav wrote: > It looks like this endio function is called when alloc_page is used (for > partial IO) to trigger writeback from the user space `echo "idle" > > /sys/block/zram0/writeback`. Yes. > I don't understand when you say the harm might not be horrible if we don't > call folio_endio here. Do you think it is just safe to remove the call to > folio_endio function? I suspect so. It doesn't seem like the involved pages are ever locked or have the writeback set, so it should be fine. > + while ((folio = readahead_folio(rac))) { > + folio_clear_uptodate(folio); > + folio_set_error(folio); > + folio_unlock(folio); > + } > + return; > + } > + > + while ((folio = readahead_folio(rac))) { > + folio_mark_uptodate(folio); > + folio_unlock(folio); > } > } Looks good. > @@ -59,7 +59,8 @@ static void mpage_end_io(struct bio *bio) > static struct bio *mpage_bio_submit(struct bio *bio) > { > - bio->bi_end_io = mpage_end_io; > + bio->bi_end_io = (op_is_write(bio_op(bio))) ? mpage_write_end_io : > + mpage_read_end_io; > guard_bio_eod(bio); > submit_bio(bio); > return NULL; > And mpage_{write,read}_end_io will iterate over the folio and call the > respective functions. Yes, although I'd do it with a good old if/else and with less braces. It might make sense to split mpage_bio_submit as well, though.
On Thu, Mar 16, 2023 at 11:04:54AM +0100, Pankaj Raghav wrote: > - /* clean up. */ > - while ((page = readahead_page(rac))) { > - page_endio(page, false, ret); > - put_page(page); > + while ((folio = readahead_folio(rac))) { > + folio_clear_uptodate(folio); > + folio_set_error(folio); > + folio_unlock(folio); > + } > + return; > + } > + > + while ((folio = readahead_folio(rac))) { > + folio_mark_uptodate(folio); > + folio_unlock(folio); > } readahead_folio() is a bit too heavy-weight for that, IMO. I'd do this as; while ((folio = readahead_folio(rac))) { if (!ret) folio_mark_uptodate(folio); folio_unlock(folio); } (there's no need to call folio_set_error(), nor folio_clear_uptodate())
On 2023-03-17 16:31, Matthew Wilcox wrote: >> + >> + while ((folio = readahead_folio(rac))) { >> + folio_mark_uptodate(folio); >> + folio_unlock(folio); >> } > > readahead_folio() is a bit too heavy-weight for that, IMO. I'd do this > as; > > while ((folio = readahead_folio(rac))) { > if (!ret) > folio_mark_uptodate(folio); > folio_unlock(folio); > } > This looks good. > (there's no need to call folio_set_error(), nor folio_clear_uptodate()) I am trying to understand why these calls are not needed for the error case. I see similar pattern, for e.g. in iomap_finish_folio_read() where we call these functions for the error case. If we don't need to call these anymore, can the mpage code also be shortened like this: -static void mpage_end_io(struct bio *bio) +static void mpage_read_end_io(struct bio *bio) { - struct bio_vec *bv; - struct bvec_iter_all iter_all; + struct folio_iter fi; + int err = blk_status_to_errno(bio->bi_status); - bio_for_each_segment_all(bv, bio, iter_all) { - struct page *page = bv->bv_page; - page_endio(page, bio_op(bio), - blk_status_to_errno(bio->bi_status)); + bio_for_each_folio_all(fi, bio) { + struct folio *folio = fi.folio; + + if (!err) + folio_mark_uptodate(folio); + folio_unlock(folio); + } + + bio_put(bio); +} + +static void mpage_write_end_io(struct bio *bio) +{ .... +
Hi Willy, On 2023-03-17 17:14, Pankaj Raghav wrote: > On 2023-03-17 16:31, Matthew Wilcox wrote: >>> + >>> + while ((folio = readahead_folio(rac))) { >>> + folio_mark_uptodate(folio); >>> + folio_unlock(folio); >>> } >> >> readahead_folio() is a bit too heavy-weight for that, IMO. I'd do this >> as; >> >> while ((folio = readahead_folio(rac))) { >> if (!ret) >> folio_mark_uptodate(folio); >> folio_unlock(folio); >> } >> > > This looks good. > >> (there's no need to call folio_set_error(), nor folio_clear_uptodate()) > > I am trying to understand why these calls are not needed for the error case. > I see similar pattern, for e.g. in iomap_finish_folio_read() where we call these > functions for the error case. > I am planning to send the next version. It would be great if I can get a rationale for your statement regarding not needing to call folio_set_error() or folio_clear_uptodate(). > If we don't need to call these anymore, can the mpage code also be shortened like this: > > -static void mpage_end_io(struct bio *bio) > +static void mpage_read_end_io(struct bio *bio) > { > - struct bio_vec *bv; > - struct bvec_iter_all iter_all; > + struct folio_iter fi; > + int err = blk_status_to_errno(bio->bi_status); > > - bio_for_each_segment_all(bv, bio, iter_all) { > - struct page *page = bv->bv_page; > - page_endio(page, bio_op(bio), > - blk_status_to_errno(bio->bi_status)); > + bio_for_each_folio_all(fi, bio) { > + struct folio *folio = fi.folio; > + > + if (!err) > + folio_mark_uptodate(folio); > + folio_unlock(folio); > + } > + > + bio_put(bio); > +} > + > +static void mpage_write_end_io(struct bio *bio) > +{ > .... > +
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index aa490da3cef2..f441251c9138 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -610,7 +610,7 @@ static void zram_page_end_io(struct bio *bio) { struct page *page = bio_first_page_all(bio); - page_endio(page, op_is_write(bio_op(bio)), + folio_endio(page_folio(page), op_is_write(bio_op(bio)), blk_status_to_errno(bio->bi_status)); bio_put(bio); } diff --git a/fs/mpage.c b/fs/mpage.c index 22b9de5ddd68..40e86e839e77 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -50,7 +50,7 @@ static void mpage_end_io(struct bio *bio) bio_for_each_segment_all(bv, bio, iter_all) { struct page *page = bv->bv_page; - page_endio(page, bio_op(bio), + folio_endio(page_folio(page), bio_op(bio), blk_status_to_errno(bio->bi_status)); } diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c index aefdf1d3be7c..b12d099510ea 100644 --- a/fs/orangefs/inode.c +++ b/fs/orangefs/inode.c @@ -276,7 +276,7 @@ static void orangefs_readahead(struct readahead_control *rac) /* clean up. */ while ((page = readahead_page(rac))) { - page_endio(page, false, ret); + folio_endio(page_folio(page), false, ret); put_page(page); } } diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index fdcd595d2294..80eab64b834f 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1076,7 +1076,7 @@ int filemap_migrate_folio(struct address_space *mapping, struct folio *dst, #else #define filemap_migrate_folio NULL #endif -void page_endio(struct page *page, bool is_write, int err); +void folio_endio(struct folio *folio, bool is_write, int err); void folio_end_private_2(struct folio *folio); void folio_wait_private_2(struct folio *folio); diff --git a/mm/filemap.c b/mm/filemap.c index a34abfe8c654..a89940f74974 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1626,13 +1626,11 @@ void folio_end_writeback(struct folio *folio) EXPORT_SYMBOL(folio_end_writeback); /* - * After completing I/O on a page, call this routine to update the page + * After completing I/O on a folio, call this routine to update the folio * flags appropriately */ -void page_endio(struct page *page, bool is_write, int err) +void folio_endio(struct folio *folio, bool is_write, int err) { - struct folio *folio = page_folio(page); - if (!is_write) { if (!err) { folio_mark_uptodate(folio); @@ -1653,7 +1651,7 @@ void page_endio(struct page *page, bool is_write, int err) folio_end_writeback(folio); } } -EXPORT_SYMBOL_GPL(page_endio); +EXPORT_SYMBOL_GPL(folio_endio); /** * __folio_lock - Get a lock on the folio, assuming we need to sleep to get it.