Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Add bvec_folio and its kernel-doc
@ 2026-05-28 17:59 Matthew Wilcox (Oracle)
  2026-05-28 17:59 ` [PATCH v2 1/2] block: Add bvec_folio() Matthew Wilcox (Oracle)
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2026-05-28 17:59 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Matthew Wilcox (Oracle), linux-block, linux-kernel, io-uring,
	linux-mm, Leon Romanovsky, Christoph Hellwig

Add the convenience helper bvec_folio() to avoid references to bv_page.
Convert a few of the obvious users.

v2:
 - Tweak the kernel-doc (Christoph)
 - Add the bvec kerneldoc to the documentation build

Matthew Wilcox (Oracle) (2):
  block: Add bvec_folio()
  block: Include bvec.h kernel-doc in the htmldocs

 Documentation/core-api/kernel-api.rst |  1 +
 block/bio.c                           |  6 +++---
 include/linux/bio.h                   |  2 +-
 include/linux/bvec.h                  | 17 +++++++++++++++++
 io_uring/rsrc.c                       |  2 +-
 mm/page_io.c                          |  4 ++--
 6 files changed, 25 insertions(+), 7 deletions(-)

-- 
2.47.3



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/2] block: Add bvec_folio()
  2026-05-28 17:59 [PATCH v2 0/2] Add bvec_folio and its kernel-doc Matthew Wilcox (Oracle)
@ 2026-05-28 17:59 ` Matthew Wilcox (Oracle)
  2026-05-29  5:30   ` Christoph Hellwig
  2026-05-29  6:16   ` Hannes Reinecke
  2026-05-28 17:59 ` [PATCH v2 2/2] block: Include bvec.h kernel-doc in the htmldocs Matthew Wilcox (Oracle)
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2026-05-28 17:59 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Matthew Wilcox (Oracle), linux-block, linux-kernel, io-uring,
	linux-mm, Leon Romanovsky, Christoph Hellwig

This is a simple helper which replaces page_folio(bvec->bv_page).
Minor improvement in readability, but the real motivation is to reduce
the number of references to bvec->bv_page so that it can be changed
with less work.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Leon Romanovsky <leon@kernel.org>
---
 block/bio.c          |  6 +++---
 include/linux/bio.h  |  2 +-
 include/linux/bvec.h | 15 +++++++++++++++
 io_uring/rsrc.c      |  2 +-
 mm/page_io.c         |  4 ++--
 5 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index 5f10900b3f42..85aab3140909 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1300,7 +1300,7 @@ static void bio_free_folios(struct bio *bio)
 	int i;
 
 	bio_for_each_bvec_all(bv, bio, i) {
-		struct folio *folio = page_folio(bv->bv_page);
+		struct folio *folio = bvec_folio(bv);
 
 		if (!is_zero_folio(folio))
 			folio_put(folio);
@@ -1409,7 +1409,7 @@ int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen,
 
 static void bvec_unpin(struct bio_vec *bv, bool mark_dirty)
 {
-	struct folio *folio = page_folio(bv->bv_page);
+	struct folio *folio = bvec_folio(bv);
 	size_t nr_pages = (bv->bv_offset + bv->bv_len - 1) / PAGE_SIZE -
 			bv->bv_offset / PAGE_SIZE + 1;
 
@@ -1443,7 +1443,7 @@ static void bio_iov_iter_unbounce_read(struct bio *bio, bool is_error,
 			bvec_unpin(&bio->bi_io_vec[1 + i], mark_dirty);
 	}
 
-	folio_put(page_folio(bio->bi_io_vec[0].bv_page));
+	folio_put(bvec_folio(&bio->bi_io_vec[0]));
 }
 
 /**
diff --git a/include/linux/bio.h b/include/linux/bio.h
index dc17780d6c1e..6613ab4519bd 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -283,7 +283,7 @@ static inline void bio_first_folio(struct folio_iter *fi, struct bio *bio,
 		return;
 	}
 
-	fi->folio = page_folio(bvec->bv_page);
+	fi->folio = bvec_folio(bvec);
 	fi->offset = bvec->bv_offset +
 			PAGE_SIZE * folio_page_idx(fi->folio, bvec->bv_page);
 	fi->_seg_count = bvec->bv_len;
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index d36dd476feda..27ac3fcc6d9e 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -74,6 +74,21 @@ static inline void bvec_set_virt(struct bio_vec *bv, void *vaddr,
 	bvec_set_page(bv, virt_to_page(vaddr), len, offset_in_page(vaddr));
 }
 
+/**
+ * bvec_folio - Return the first folio referenced by this bvec
+ * @bv: bvec to access
+ *
+ * A bvec can contain non-folio memory, so this should only be called by
+ * the creator of the bvec; drivers have no business looking at the owner
+ * of the memory.  It may not even be the right interface for the caller
+ * to use as a bvec can span multiple folios.  You may be better off using
+ * something like bio_for_each_folio_all() which iterates over all folios.
+ */
+static inline struct folio *bvec_folio(const struct bio_vec *bv)
+{
+	return page_folio(bv->bv_page);
+}
+
 struct bvec_iter {
 	/*
 	 * Current device address in 512 byte sectors. Only updated by the bio
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 650303626be6..5d792f70ec1e 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -102,7 +102,7 @@ static void io_release_ubuf(void *priv)
 	unsigned int i;
 
 	for (i = 0; i < imu->nr_bvecs; i++) {
-		struct folio *folio = page_folio(imu->bvec[i].bv_page);
+		struct folio *folio = bvec_folio(&imu->bvec[i]);
 
 		unpin_user_folio(folio, 1);
 	}
diff --git a/mm/page_io.c b/mm/page_io.c
index 70cea9e24d2f..a59b73f8bdd9 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -490,7 +490,7 @@ static void sio_read_complete(struct kiocb *iocb, long ret)
 
 	if (ret == sio->len) {
 		for (p = 0; p < sio->pages; p++) {
-			struct folio *folio = page_folio(sio->bvec[p].bv_page);
+			struct folio *folio = bvec_folio(&sio->bvec[p]);
 
 			count_mthp_stat(folio_order(folio), MTHP_STAT_SWPIN);
 			count_memcg_folio_events(folio, PSWPIN, folio_nr_pages(folio));
@@ -500,7 +500,7 @@ static void sio_read_complete(struct kiocb *iocb, long ret)
 		count_vm_events(PSWPIN, sio->len >> PAGE_SHIFT);
 	} else {
 		for (p = 0; p < sio->pages; p++) {
-			struct folio *folio = page_folio(sio->bvec[p].bv_page);
+			struct folio *folio = bvec_folio(&sio->bvec[p]);
 
 			folio_unlock(folio);
 		}
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/2] block: Include bvec.h kernel-doc in the htmldocs
  2026-05-28 17:59 [PATCH v2 0/2] Add bvec_folio and its kernel-doc Matthew Wilcox (Oracle)
  2026-05-28 17:59 ` [PATCH v2 1/2] block: Add bvec_folio() Matthew Wilcox (Oracle)
@ 2026-05-28 17:59 ` Matthew Wilcox (Oracle)
  2026-05-29  5:31   ` Christoph Hellwig
  2026-05-29  6:17   ` Hannes Reinecke
  2026-05-28 23:30 ` [PATCH v2 0/2] Add bvec_folio and its kernel-doc William Kucharski
  2026-06-01  1:47 ` Jens Axboe
  3 siblings, 2 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2026-05-28 17:59 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Matthew Wilcox (Oracle), linux-block, linux-kernel, io-uring,
	linux-mm, Leon Romanovsky, Christoph Hellwig

People have gone to the trouble of writing this kernel-doc; the
least we can do is publish it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 Documentation/core-api/kernel-api.rst | 1 +
 include/linux/bvec.h                  | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/Documentation/core-api/kernel-api.rst b/Documentation/core-api/kernel-api.rst
index e8211c4ca662..4c4a57c1c094 100644
--- a/Documentation/core-api/kernel-api.rst
+++ b/Documentation/core-api/kernel-api.rst
@@ -307,6 +307,7 @@ Accounting Framework
 Block Devices
 =============
 
+.. kernel-doc:: include/linux/bvec.h
 .. kernel-doc:: include/linux/bio.h
 .. kernel-doc:: block/blk-core.c
    :export:
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 27ac3fcc6d9e..09d6bb76919e 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -262,6 +262,7 @@ static inline void *bvec_kmap_local(struct bio_vec *bvec)
 
 /**
  * memcpy_from_bvec - copy data from a bvec
+ * @to: Kernel virtual address to copy to.
  * @bvec: bvec to copy from
  *
  * Must be called on single-page bvecs only.
@@ -274,6 +275,7 @@ static inline void memcpy_from_bvec(char *to, struct bio_vec *bvec)
 /**
  * memcpy_to_bvec - copy data to a bvec
  * @bvec: bvec to copy to
+ * @from: Kernel virtual address to copy from.
  *
  * Must be called on single-page bvecs only.
  */
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/2] Add bvec_folio and its kernel-doc
  2026-05-28 17:59 [PATCH v2 0/2] Add bvec_folio and its kernel-doc Matthew Wilcox (Oracle)
  2026-05-28 17:59 ` [PATCH v2 1/2] block: Add bvec_folio() Matthew Wilcox (Oracle)
  2026-05-28 17:59 ` [PATCH v2 2/2] block: Include bvec.h kernel-doc in the htmldocs Matthew Wilcox (Oracle)
@ 2026-05-28 23:30 ` William Kucharski
  2026-06-01  1:47 ` Jens Axboe
  3 siblings, 0 replies; 9+ messages in thread
From: William Kucharski @ 2026-05-28 23:30 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: Jens Axboe, linux-block, linux-kernel, io-uring, linux-mm,
	Leon Romanovsky, Christoph Hellwig

For the series:

Reviewed-by: William Kucharski <william.kucharski@linux.dev>

> On May 28, 2026, at 11:59, Matthew Wilcox (Oracle) <willy@infradead.org> wrote:
> 
> Add the convenience helper bvec_folio() to avoid references to bv_page.
> Convert a few of the obvious users.
> 
> v2:
> - Tweak the kernel-doc (Christoph)
> - Add the bvec kerneldoc to the documentation build
> 
> Matthew Wilcox (Oracle) (2):
>  block: Add bvec_folio()
>  block: Include bvec.h kernel-doc in the htmldocs
> 
> Documentation/core-api/kernel-api.rst |  1 +
> block/bio.c                           |  6 +++---
> include/linux/bio.h                   |  2 +-
> include/linux/bvec.h                  | 17 +++++++++++++++++
> io_uring/rsrc.c                       |  2 +-
> mm/page_io.c                          |  4 ++--
> 6 files changed, 25 insertions(+), 7 deletions(-)
> 
> -- 
> 2.47.3
> 
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/2] block: Add bvec_folio()
  2026-05-28 17:59 ` [PATCH v2 1/2] block: Add bvec_folio() Matthew Wilcox (Oracle)
@ 2026-05-29  5:30   ` Christoph Hellwig
  2026-05-29  6:16   ` Hannes Reinecke
  1 sibling, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-05-29  5:30 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: Jens Axboe, linux-block, linux-kernel, io-uring, linux-mm,
	Leon Romanovsky, Christoph Hellwig

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/2] block: Include bvec.h kernel-doc in the htmldocs
  2026-05-28 17:59 ` [PATCH v2 2/2] block: Include bvec.h kernel-doc in the htmldocs Matthew Wilcox (Oracle)
@ 2026-05-29  5:31   ` Christoph Hellwig
  2026-05-29  6:17   ` Hannes Reinecke
  1 sibling, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-05-29  5:31 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: Jens Axboe, linux-block, linux-kernel, io-uring, linux-mm,
	Leon Romanovsky, Christoph Hellwig

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/2] block: Add bvec_folio()
  2026-05-28 17:59 ` [PATCH v2 1/2] block: Add bvec_folio() Matthew Wilcox (Oracle)
  2026-05-29  5:30   ` Christoph Hellwig
@ 2026-05-29  6:16   ` Hannes Reinecke
  1 sibling, 0 replies; 9+ messages in thread
From: Hannes Reinecke @ 2026-05-29  6:16 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle), Jens Axboe
  Cc: linux-block, linux-kernel, io-uring, linux-mm, Leon Romanovsky,
	Christoph Hellwig

On 5/28/26 19:59, Matthew Wilcox (Oracle) wrote:
> This is a simple helper which replaces page_folio(bvec->bv_page).
> Minor improvement in readability, but the real motivation is to reduce
> the number of references to bvec->bv_page so that it can be changed
> with less work.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Leon Romanovsky <leon@kernel.org>
> ---
>   block/bio.c          |  6 +++---
>   include/linux/bio.h  |  2 +-
>   include/linux/bvec.h | 15 +++++++++++++++
>   io_uring/rsrc.c      |  2 +-
>   mm/page_io.c         |  4 ++--
>   5 files changed, 22 insertions(+), 7 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@kernel.org>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/2] block: Include bvec.h kernel-doc in the htmldocs
  2026-05-28 17:59 ` [PATCH v2 2/2] block: Include bvec.h kernel-doc in the htmldocs Matthew Wilcox (Oracle)
  2026-05-29  5:31   ` Christoph Hellwig
@ 2026-05-29  6:17   ` Hannes Reinecke
  1 sibling, 0 replies; 9+ messages in thread
From: Hannes Reinecke @ 2026-05-29  6:17 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle), Jens Axboe
  Cc: linux-block, linux-kernel, io-uring, linux-mm, Leon Romanovsky,
	Christoph Hellwig

On 5/28/26 19:59, Matthew Wilcox (Oracle) wrote:
> People have gone to the trouble of writing this kernel-doc; the
> least we can do is publish it.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>   Documentation/core-api/kernel-api.rst | 1 +
>   include/linux/bvec.h                  | 2 ++
>   2 files changed, 3 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@kernel.org>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/2] Add bvec_folio and its kernel-doc
  2026-05-28 17:59 [PATCH v2 0/2] Add bvec_folio and its kernel-doc Matthew Wilcox (Oracle)
                   ` (2 preceding siblings ...)
  2026-05-28 23:30 ` [PATCH v2 0/2] Add bvec_folio and its kernel-doc William Kucharski
@ 2026-06-01  1:47 ` Jens Axboe
  3 siblings, 0 replies; 9+ messages in thread
From: Jens Axboe @ 2026-06-01  1:47 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: linux-block, linux-kernel, io-uring, linux-mm, Leon Romanovsky,
	Christoph Hellwig


On Thu, 28 May 2026 18:59:02 +0100, Matthew Wilcox (Oracle) wrote:
> Add the convenience helper bvec_folio() to avoid references to bv_page.
> Convert a few of the obvious users.
> 
> v2:
>  - Tweak the kernel-doc (Christoph)
>  - Add the bvec kerneldoc to the documentation build
> 
> [...]

Applied, thanks!

[1/2] block: Add bvec_folio()
      (no commit info)
[2/2] block: Include bvec.h kernel-doc in the htmldocs
      (no commit info)

Best regards,
-- 
Jens Axboe





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-06-01  1:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-28 17:59 [PATCH v2 0/2] Add bvec_folio and its kernel-doc Matthew Wilcox (Oracle)
2026-05-28 17:59 ` [PATCH v2 1/2] block: Add bvec_folio() Matthew Wilcox (Oracle)
2026-05-29  5:30   ` Christoph Hellwig
2026-05-29  6:16   ` Hannes Reinecke
2026-05-28 17:59 ` [PATCH v2 2/2] block: Include bvec.h kernel-doc in the htmldocs Matthew Wilcox (Oracle)
2026-05-29  5:31   ` Christoph Hellwig
2026-05-29  6:17   ` Hannes Reinecke
2026-05-28 23:30 ` [PATCH v2 0/2] Add bvec_folio and its kernel-doc William Kucharski
2026-06-01  1:47 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox