linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Joanne Koong <joannelkoong@gmail.com>
Cc: brauner@kernel.org, hch@infradead.org, bfoster@redhat.com,
	linux-fsdevel@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH v3 8/8] iomap: use find_next_bit() for uptodate bitmap scanning
Date: Tue, 4 Nov 2025 17:42:58 -0800	[thread overview]
Message-ID: <20251105014258.GI196362@frogsfrogsfrogs> (raw)
In-Reply-To: <20251104205119.1600045-9-joannelkoong@gmail.com>

On Tue, Nov 04, 2025 at 12:51:19PM -0800, Joanne Koong wrote:
> Use find_next_bit()/find_next_zero_bit() for iomap uptodate bitmap
> scanning. This uses __ffs() internally and is more efficient for
> finding the next uptodate or non-uptodate bit than iterating through the
> the bitmap range testing every bit.
> 
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> Suggested-by: Christoph Hellwig <hch@infradead.org>

Here too!
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  fs/iomap/buffered-io.c | 52 ++++++++++++++++++++++++++----------------
>  1 file changed, 32 insertions(+), 20 deletions(-)
> 
> diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> index 3c9a4b773186..03dd524b69d2 100644
> --- a/fs/iomap/buffered-io.c
> +++ b/fs/iomap/buffered-io.c
> @@ -38,10 +38,28 @@ static inline bool ifs_is_fully_uptodate(struct folio *folio,
>  	return bitmap_full(ifs->state, i_blocks_per_folio(inode, folio));
>  }
>  
> -static inline bool ifs_block_is_uptodate(struct iomap_folio_state *ifs,
> -		unsigned int block)
> +/*
> + * Find the next uptodate block in the folio. end_blk is inclusive.
> + * If no uptodate block is found, this will return end_blk + 1.
> + */
> +static unsigned ifs_next_uptodate_block(struct folio *folio,
> +		unsigned start_blk, unsigned end_blk)
>  {
> -	return test_bit(block, ifs->state);
> +	struct iomap_folio_state *ifs = folio->private;
> +
> +	return find_next_bit(ifs->state, end_blk + 1, start_blk);
> +}
> +
> +/*
> + * Find the next non-uptodate block in the folio. end_blk is inclusive.
> + * If no non-uptodate block is found, this will return end_blk + 1.
> + */
> +static unsigned ifs_next_nonuptodate_block(struct folio *folio,
> +		unsigned start_blk, unsigned end_blk)
> +{
> +	struct iomap_folio_state *ifs = folio->private;
> +
> +	return find_next_zero_bit(ifs->state, end_blk + 1, start_blk);
>  }
>  
>  static bool ifs_set_range_uptodate(struct folio *folio,
> @@ -278,14 +296,11 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,
>  	 * to avoid reading in already uptodate ranges.
>  	 */
>  	if (ifs) {
> -		unsigned int i, blocks_skipped;
> +		unsigned int next, blocks_skipped;
>  
> -		/* move forward for each leading block marked uptodate */
> -		for (i = first; i <= last; i++)
> -			if (!ifs_block_is_uptodate(ifs, i))
> -				break;
> +		next = ifs_next_nonuptodate_block(folio, first, last);
> +		blocks_skipped = next - first;
>  
> -		blocks_skipped = i - first;
>  		if (blocks_skipped) {
>  			unsigned long block_offset = *pos & (block_size - 1);
>  			unsigned bytes_skipped =
> @@ -295,15 +310,15 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,
>  			poff += bytes_skipped;
>  			plen -= bytes_skipped;
>  		}
> -		first = i;
> +		first = next;
>  
>  		/* truncate len if we find any trailing uptodate block(s) */
> -		while (++i <= last) {
> -			if (ifs_block_is_uptodate(ifs, i)) {
> +		if (++next <= last) {
> +			next = ifs_next_uptodate_block(folio, next, last);
> +			if (next <= last) {
>  				plen -= iomap_bytes_to_truncate(*pos + plen,
> -						block_bits, last - i + 1);
> -				last = i - 1;
> -				break;
> +						block_bits, last - next + 1);
> +				last = next - 1;
>  			}
>  		}
>  	}
> @@ -634,7 +649,7 @@ bool iomap_is_partially_uptodate(struct folio *folio, size_t from, size_t count)
>  {
>  	struct iomap_folio_state *ifs = folio->private;
>  	struct inode *inode = folio->mapping->host;
> -	unsigned first, last, i;
> +	unsigned first, last;
>  
>  	if (!ifs)
>  		return false;
> @@ -646,10 +661,7 @@ bool iomap_is_partially_uptodate(struct folio *folio, size_t from, size_t count)
>  	first = from >> inode->i_blkbits;
>  	last = (from + count - 1) >> inode->i_blkbits;
>  
> -	for (i = first; i <= last; i++)
> -		if (!ifs_block_is_uptodate(ifs, i))
> -			return false;
> -	return true;
> +	return ifs_next_nonuptodate_block(folio, first, last) > last;
>  }
>  EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate);
>  
> -- 
> 2.47.3
> 
> 

  reply	other threads:[~2025-11-05  1:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-04 20:51 [PATCH v3 0/8] iomap: buffered io changes Joanne Koong
2025-11-04 20:51 ` [PATCH v3 1/8] iomap: account for unaligned end offsets when truncating read range Joanne Koong
2025-11-05  1:27   ` Darrick J. Wong
2025-11-06 17:08     ` Joanne Koong
2025-11-06 23:08       ` Darrick J. Wong
2025-11-04 20:51 ` [PATCH v3 2/8] docs: document iomap writeback's iomap_finish_folio_write() requirement Joanne Koong
2025-11-05  1:22   ` Darrick J. Wong
2025-11-04 20:51 ` [PATCH v3 3/8] iomap: optimize pending async writeback accounting Joanne Koong
2025-11-05  1:28   ` Darrick J. Wong
2025-11-04 20:51 ` [PATCH v3 4/8] iomap: simplify ->read_folio_range() error handling for reads Joanne Koong
2025-11-05  1:50   ` Darrick J. Wong
2025-11-06 17:17     ` Joanne Koong
2025-11-06 23:09       ` Darrick J. Wong
2025-11-04 20:51 ` [PATCH v3 5/8] iomap: simplify when reads can be skipped for writes Joanne Koong
2025-11-05  1:40   ` Darrick J. Wong
2025-11-04 20:51 ` [PATCH v3 6/8] iomap: use loff_t for file positions and offsets in writeback code Joanne Koong
2025-11-05  1:41   ` Darrick J. Wong
2025-11-04 20:51 ` [PATCH v3 7/8] iomap: use find_next_bit() for dirty bitmap scanning Joanne Koong
2025-11-05  1:42   ` Darrick J. Wong
2025-11-04 20:51 ` [PATCH v3 8/8] iomap: use find_next_bit() for uptodate " Joanne Koong
2025-11-05  1:42   ` Darrick J. Wong [this message]
2025-11-11 12:09 ` [PATCH v3 0/8] iomap: buffered io changes Christian Brauner
2025-11-11 18:05   ` 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=20251105014258.GI196362@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=bfoster@redhat.com \
    --cc=brauner@kernel.org \
    --cc=hch@infradead.org \
    --cc=joannelkoong@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=linux-fsdevel@vger.kernel.org \
    /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).