From: "Darrick J. Wong" <djwong@kernel.org>
To: Joanne Koong <joannelkoong@gmail.com>
Cc: brauner@kernel.org, miklos@szeredi.hu, hch@infradead.org,
linux-fsdevel@vger.kernel.org, kernel-team@meta.com,
linux-xfs@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH v1 07/16] iomap: iterate through entire folio in iomap_readpage_iter()
Date: Wed, 3 Sep 2025 13:43:48 -0700 [thread overview]
Message-ID: <20250903204348.GO1587915@frogsfrogsfrogs> (raw)
In-Reply-To: <20250829235627.4053234-8-joannelkoong@gmail.com>
On Fri, Aug 29, 2025 at 04:56:18PM -0700, Joanne Koong wrote:
> Iterate through the entire folio in iomap_readpage_iter() in one go
> instead of in pieces. This will be needed for supporting user-provided
> async read folio callbacks (not yet added). This additionally makes the
> iomap_readahead_iter() logic simpler to follow.
This might be a good time to change the name since you're not otherwise
changing the function declaration, and there ought to be /some/
indication that the behavior isn't the same anymore.
Otherwise, this looks correct to me.
--D
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> ---
> fs/iomap/buffered-io.c | 76 ++++++++++++++++++------------------------
> 1 file changed, 33 insertions(+), 43 deletions(-)
>
> diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> index f26544fbcb36..75bbef386b62 100644
> --- a/fs/iomap/buffered-io.c
> +++ b/fs/iomap/buffered-io.c
> @@ -452,6 +452,7 @@ static int iomap_readpage_iter(struct iomap_iter *iter,
> loff_t length = iomap_length(iter);
> struct folio *folio = ctx->cur_folio;
> size_t poff, plen;
> + loff_t count;
> int ret;
>
> if (iomap->type == IOMAP_INLINE) {
> @@ -463,26 +464,30 @@ static int iomap_readpage_iter(struct iomap_iter *iter,
>
> /* zero post-eof blocks as the page may be mapped */
> ifs_alloc(iter->inode, folio, iter->flags);
> - iomap_adjust_read_range(iter->inode, folio, &pos, length, &poff, &plen);
> - if (plen == 0)
> - goto done;
>
> - if (iomap_block_needs_zeroing(iter, pos)) {
> - folio_zero_range(folio, poff, plen);
> - iomap_set_range_uptodate(folio, poff, plen);
> - } else {
> - iomap_read_folio_range_async(iter, ctx, pos, plen);
> - }
> + length = min_t(loff_t, length,
> + folio_size(folio) - offset_in_folio(folio, pos));
> + while (length) {
> + iomap_adjust_read_range(iter->inode, folio, &pos,
> + length, &poff, &plen);
> + count = pos - iter->pos + plen;
> + if (plen == 0)
> + return iomap_iter_advance(iter, &count);
>
> -done:
> - /*
> - * Move the caller beyond our range so that it keeps making progress.
> - * For that, we have to include any leading non-uptodate ranges, but
> - * we can skip trailing ones as they will be handled in the next
> - * iteration.
> - */
> - length = pos - iter->pos + plen;
> - return iomap_iter_advance(iter, &length);
> + if (iomap_block_needs_zeroing(iter, pos)) {
> + folio_zero_range(folio, poff, plen);
> + iomap_set_range_uptodate(folio, poff, plen);
> + } else {
> + iomap_read_folio_range_async(iter, ctx, pos, plen);
> + }
> +
> + length -= count;
> + ret = iomap_iter_advance(iter, &count);
> + if (ret)
> + return ret;
> + pos = iter->pos;
> + }
> + return 0;
> }
>
> static void iomap_readfolio_complete(const struct iomap_iter *iter,
> @@ -494,20 +499,6 @@ static void iomap_readfolio_complete(const struct iomap_iter *iter,
> folio_unlock(ctx->cur_folio);
> }
>
> -static int iomap_read_folio_iter(struct iomap_iter *iter,
> - struct iomap_readpage_ctx *ctx)
> -{
> - int ret;
> -
> - while (iomap_length(iter)) {
> - ret = iomap_readpage_iter(iter, ctx);
> - if (ret)
> - return ret;
> - }
> -
> - return 0;
> -}
> -
> int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops)
> {
> struct iomap_iter iter = {
> @@ -523,7 +514,7 @@ int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops)
> trace_iomap_readpage(iter.inode, 1);
>
> while ((ret = iomap_iter(&iter, ops)) > 0)
> - iter.status = iomap_read_folio_iter(&iter, &ctx);
> + iter.status = iomap_readpage_iter(&iter, &ctx);
>
> iomap_readfolio_complete(&iter, &ctx);
>
> @@ -537,16 +528,15 @@ static int iomap_readahead_iter(struct iomap_iter *iter,
> int ret;
>
> while (iomap_length(iter)) {
> - if (ctx->cur_folio &&
> - offset_in_folio(ctx->cur_folio, iter->pos) == 0) {
> - if (!ctx->folio_unlocked)
> - folio_unlock(ctx->cur_folio);
> - ctx->cur_folio = NULL;
> - }
> - if (!ctx->cur_folio) {
> - ctx->cur_folio = readahead_folio(ctx->rac);
> - ctx->folio_unlocked = false;
> - }
> + if (ctx->cur_folio && !ctx->folio_unlocked)
> + folio_unlock(ctx->cur_folio);
> + ctx->cur_folio = readahead_folio(ctx->rac);
> + /*
> + * We should never in practice hit this case since
> + * the iter length matches the readahead length.
> + */
> + WARN_ON(!ctx->cur_folio);
> + ctx->folio_unlocked = false;
> ret = iomap_readpage_iter(iter, ctx);
> if (ret)
> return ret;
> --
> 2.47.3
>
>
next prev parent reply other threads:[~2025-09-03 20:43 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 23:56 [PATCH v1 00/16] fuse: use iomap for buffered reads + readahead Joanne Koong
2025-08-29 23:56 ` [PATCH v1 01/16] iomap: move async bio read logic into helper function Joanne Koong
2025-09-03 20:16 ` Darrick J. Wong
2025-09-04 6:00 ` Christoph Hellwig
2025-09-04 21:44 ` Joanne Koong
2025-08-29 23:56 ` [PATCH v1 02/16] iomap: rename cur_folio_in_bio to folio_unlocked Joanne Koong
2025-09-03 20:26 ` [PATCH v1 02/16] iomap: rename cur_folio_in_bio to folio_unlockedOM Darrick J. Wong
2025-09-04 6:03 ` Christoph Hellwig
2025-09-04 22:06 ` Joanne Koong
2025-08-29 23:56 ` [PATCH v1 03/16] iomap: refactor read/readahead completion Joanne Koong
2025-09-04 6:05 ` Christoph Hellwig
2025-09-04 23:16 ` Joanne Koong
2025-08-29 23:56 ` [PATCH v1 04/16] iomap: use iomap_iter->private for stashing read/readahead bio Joanne Koong
2025-09-03 20:30 ` Darrick J. Wong
2025-09-04 6:07 ` Christoph Hellwig
2025-09-04 22:20 ` Joanne Koong
2025-09-04 23:15 ` Joanne Koong
2025-08-29 23:56 ` [PATCH v1 05/16] iomap: propagate iomap_read_folio() error to caller Joanne Koong
2025-09-03 20:32 ` Darrick J. Wong
2025-09-04 6:09 ` Christoph Hellwig
2025-09-04 21:13 ` Matthew Wilcox
2025-08-29 23:56 ` [PATCH v1 06/16] iomap: move read/readahead logic out of CONFIG_BLOCK guard Joanne Koong
2025-08-29 23:56 ` [PATCH v1 07/16] iomap: iterate through entire folio in iomap_readpage_iter() Joanne Koong
2025-09-03 20:43 ` Darrick J. Wong [this message]
2025-09-04 22:37 ` Joanne Koong
2025-09-04 6:14 ` Christoph Hellwig
2025-09-04 22:45 ` Joanne Koong
2025-08-29 23:56 ` [PATCH v1 08/16] iomap: rename iomap_readpage_iter() to iomap_readfolio_iter() Joanne Koong
2025-09-04 6:15 ` Christoph Hellwig
2025-09-04 22:47 ` Joanne Koong
2025-08-29 23:56 ` [PATCH v1 09/16] iomap: rename iomap_readpage_ctx struct to iomap_readfolio_ctx Joanne Koong
2025-09-03 20:44 ` Darrick J. Wong
2025-08-29 23:56 ` [PATCH v1 10/16] iomap: add iomap_start_folio_read() helper Joanne Koong
2025-09-03 20:52 ` Darrick J. Wong
2025-08-29 23:56 ` [PATCH v1 11/16] iomap: make start folio read and finish folio read public APIs Joanne Koong
2025-09-03 20:53 ` Darrick J. Wong
2025-09-04 6:15 ` Christoph Hellwig
2025-08-29 23:56 ` [PATCH v1 12/16] iomap: add iomap_read_ops for read and readahead Joanne Koong
2025-09-03 21:08 ` Darrick J. Wong
2025-09-04 20:58 ` Joanne Koong
2025-09-04 6:21 ` Christoph Hellwig
2025-09-04 21:38 ` Joanne Koong
2025-08-29 23:56 ` [PATCH v1 13/16] iomap: add a private arg " Joanne Koong
2025-08-30 1:54 ` Gao Xiang
2025-09-02 21:24 ` Joanne Koong
2025-09-03 1:55 ` Gao Xiang
2025-09-04 23:29 ` Joanne Koong
2025-09-05 2:21 ` Gao Xiang
2025-09-03 21:11 ` Darrick J. Wong
2025-08-29 23:56 ` [PATCH v1 14/16] fuse: use iomap for read_folio Joanne Koong
2025-09-03 21:13 ` Darrick J. Wong
2025-08-29 23:56 ` [PATCH v1 15/16] fuse: use iomap for readahead Joanne Koong
2025-09-03 21:17 ` Darrick J. Wong
2025-09-04 19:40 ` Joanne Koong
2025-09-04 19:46 ` Joanne Koong
2025-08-29 23:56 ` [PATCH v1 16/16] fuse: remove fuse_readpages_end() null mapping check Joanne Koong
2025-09-02 9:21 ` Miklos Szeredi
2025-09-02 21:19 ` Joanne Koong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250903204348.GO1587915@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=brauner@kernel.org \
--cc=hch@infradead.org \
--cc=joannelkoong@gmail.com \
--cc=kernel-team@meta.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).