linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-block@vger.kernel.org
Subject: Re: [PATCH v15 02/17] block: Add bio_for_each_folio_all()
Date: Mon, 19 Jul 2021 18:29:45 -0700	[thread overview]
Message-ID: <20210720012945.GO22357@magnolia> (raw)
In-Reply-To: <20210719184001.1750630-3-willy@infradead.org>

On Mon, Jul 19, 2021 at 07:39:46PM +0100, Matthew Wilcox (Oracle) wrote:
> Allow callers to iterate over each folio instead of each page.  The
> bio need not have been constructed using folios originally.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Whoops, I never did remember to circle back and ack this patch.
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  Documentation/core-api/kernel-api.rst |  1 +
>  include/linux/bio.h                   | 53 ++++++++++++++++++++++++++-
>  2 files changed, 53 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/core-api/kernel-api.rst b/Documentation/core-api/kernel-api.rst
> index 2a7444e3a4c2..b804605f705e 100644
> --- a/Documentation/core-api/kernel-api.rst
> +++ b/Documentation/core-api/kernel-api.rst
> @@ -279,6 +279,7 @@ Accounting Framework
>  Block Devices
>  =============
>  
> +.. kernel-doc:: include/linux/bio.h
>  .. kernel-doc:: block/blk-core.c
>     :export:
>  
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index ade93e2de6a1..a90a79ad7bd1 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -189,7 +189,7 @@ static inline void bio_advance_iter_single(const struct bio *bio,
>   */
>  #define bio_for_each_bvec_all(bvl, bio, i)		\
>  	for (i = 0, bvl = bio_first_bvec_all(bio);	\
> -	     i < (bio)->bi_vcnt; i++, bvl++)		\
> +	     i < (bio)->bi_vcnt; i++, bvl++)
>  
>  #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len)
>  
> @@ -314,6 +314,57 @@ static inline struct bio_vec *bio_last_bvec_all(struct bio *bio)
>  	return &bio->bi_io_vec[bio->bi_vcnt - 1];
>  }
>  
> +/**
> + * struct folio_iter - State for iterating all folios in a bio.
> + * @folio: The current folio we're iterating.  NULL after the last folio.
> + * @offset: The byte offset within the current folio.
> + * @length: The number of bytes in this iteration (will not cross folio
> + *	boundary).
> + */
> +struct folio_iter {
> +	struct folio *folio;
> +	size_t offset;
> +	size_t length;
> +	/* private: for use by the iterator */
> +	size_t _seg_count;
> +	int _i;
> +};
> +
> +static inline
> +void bio_first_folio(struct folio_iter *fi, struct bio *bio, int i)
> +{
> +	struct bio_vec *bvec = bio_first_bvec_all(bio) + i;
> +
> +	fi->folio = page_folio(bvec->bv_page);
> +	fi->offset = bvec->bv_offset +
> +			PAGE_SIZE * (bvec->bv_page - &fi->folio->page);
> +	fi->_seg_count = bvec->bv_len;
> +	fi->length = min(folio_size(fi->folio) - fi->offset, fi->_seg_count);
> +	fi->_i = i;
> +}
> +
> +static inline void bio_next_folio(struct folio_iter *fi, struct bio *bio)
> +{
> +	fi->_seg_count -= fi->length;
> +	if (fi->_seg_count) {
> +		fi->folio = folio_next(fi->folio);
> +		fi->offset = 0;
> +		fi->length = min(folio_size(fi->folio), fi->_seg_count);
> +	} else if (fi->_i + 1 < bio->bi_vcnt) {
> +		bio_first_folio(fi, bio, fi->_i + 1);
> +	} else {
> +		fi->folio = NULL;
> +	}
> +}
> +
> +/**
> + * bio_for_each_folio_all - Iterate over each folio in a bio.
> + * @fi: struct folio_iter which is updated for each folio.
> + * @bio: struct bio to iterate over.
> + */
> +#define bio_for_each_folio_all(fi, bio)				\
> +	for (bio_first_folio(&fi, bio, 0); fi.folio; bio_next_folio(&fi, bio))
> +
>  enum bip_flags {
>  	BIP_BLOCK_INTEGRITY	= 1 << 0, /* block layer owns integrity data */
>  	BIP_MAPPED_INTEGRITY	= 1 << 1, /* ref tag has been remapped */
> -- 
> 2.30.2
> 


  reply	other threads:[~2021-07-20  1:29 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-19 18:39 [PATCH v15 00/17] Folio support in block + iomap layers Matthew Wilcox (Oracle)
2021-07-19 18:39 ` [PATCH v15 01/17] block: Add bio_add_folio() Matthew Wilcox (Oracle)
2021-07-20  1:28   ` Darrick J. Wong
2021-07-20  6:42   ` Christoph Hellwig
2021-07-20 11:16     ` Matthew Wilcox
2021-07-22 16:27     ` Matthew Wilcox
2021-07-30  8:25   ` Ming Lei
2021-07-30 11:30     ` Matthew Wilcox
2021-07-19 18:39 ` [PATCH v15 02/17] block: Add bio_for_each_folio_all() Matthew Wilcox (Oracle)
2021-07-20  1:29   ` Darrick J. Wong [this message]
2021-07-20  1:59     ` Matthew Wilcox
2021-07-20  6:48   ` Christoph Hellwig
2021-07-23  2:40     ` Matthew Wilcox
2021-07-20 12:05   ` kernel test robot
2021-07-20 12:05   ` kernel test robot
2021-07-20 12:26   ` kernel test robot
2021-07-19 18:39 ` [PATCH v15 03/17] iomap: Convert to_iomap_page to take a folio Matthew Wilcox (Oracle)
2021-07-20  6:49   ` Christoph Hellwig
2021-07-19 18:39 ` [PATCH v15 04/17] iomap: Convert iomap_page_create " Matthew Wilcox (Oracle)
2021-07-20  6:50   ` Christoph Hellwig
2021-07-19 18:39 ` [PATCH v15 05/17] iomap: Convert iomap_page_release " Matthew Wilcox (Oracle)
2021-07-20  6:52   ` Christoph Hellwig
2021-07-20 11:29     ` Matthew Wilcox
2021-07-20 11:40       ` Christoph Hellwig
2021-07-19 18:39 ` [PATCH v15 06/17] iomap: Convert iomap_releasepage to use " Matthew Wilcox (Oracle)
2021-07-20  6:54   ` Christoph Hellwig
2021-07-20 23:56   ` Darrick J. Wong
2021-07-19 18:39 ` [PATCH v15 07/17] iomap: Convert iomap_invalidatepage " Matthew Wilcox (Oracle)
2021-07-20  6:55   ` Christoph Hellwig
2021-07-20 23:57   ` Darrick J. Wong
2021-07-19 18:39 ` [PATCH v15 08/17] iomap: Pass the iomap_page into iomap_set_range_uptodate Matthew Wilcox (Oracle)
2021-07-20  6:57   ` Christoph Hellwig
2021-07-20 11:36     ` Matthew Wilcox
2021-07-19 18:39 ` [PATCH v15 09/17] iomap: Use folio offsets instead of page offsets Matthew Wilcox (Oracle)
2021-07-20  6:59   ` Christoph Hellwig
2021-07-20 11:42     ` Matthew Wilcox
2021-07-19 18:39 ` [PATCH v15 10/17] iomap: Convert bio completions to use folios Matthew Wilcox (Oracle)
2021-07-20  7:08   ` Christoph Hellwig
2021-07-19 18:39 ` [PATCH v15 11/17] iomap: Convert readahead and readpage to use a folio Matthew Wilcox (Oracle)
2021-07-20  7:09   ` Christoph Hellwig
2021-07-19 18:39 ` [PATCH v15 12/17] iomap: Convert iomap_page_mkwrite " Matthew Wilcox (Oracle)
2021-07-20  7:13   ` Christoph Hellwig
2021-07-19 18:39 ` [PATCH v15 13/17] iomap: Convert iomap_write_begin and iomap_write_end to folios Matthew Wilcox (Oracle)
2021-07-20  7:15   ` Christoph Hellwig
2021-07-20 23:59   ` Darrick J. Wong
2021-07-19 18:39 ` [PATCH v15 14/17] iomap: Convert iomap_read_inline_data to take a folio Matthew Wilcox (Oracle)
2021-07-20  7:16   ` Christoph Hellwig
2021-07-19 18:39 ` [PATCH v15 15/17] iomap: Convert iomap_write_end_inline " Matthew Wilcox (Oracle)
2021-07-20  7:17   ` Christoph Hellwig
2021-07-19 18:40 ` [PATCH v15 16/17] iomap: Convert iomap_add_to_ioend " Matthew Wilcox (Oracle)
2021-07-20  7:20   ` Christoph Hellwig
2021-07-20 11:45     ` Matthew Wilcox
2021-07-21  0:12   ` Darrick J. Wong
2021-07-21  4:27     ` Christoph Hellwig
2021-07-21  4:31       ` Matthew Wilcox
2021-07-21 15:28         ` Darrick J. Wong
2021-07-19 18:40 ` [PATCH v15 17/17] iomap: Convert iomap_migrate_page to use folios Matthew Wilcox (Oracle)
2021-07-20  7:21   ` Christoph Hellwig
2021-07-20 13:30   ` kernel test robot
2021-07-21  0:02   ` Darrick J. Wong
2021-07-20  8:44 ` [PATCH v15 00/17] Folio support in block + iomap layers Christoph Hellwig
2021-07-20 11:08   ` Matthew Wilcox

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=20210720012945.GO22357@magnolia \
    --to=djwong@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.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).