diff mbox series

[v6,1/3] block: Added folio-lized version of bio_add_hw_page()

Message ID 20240627104552.11177-2-kundan.kumar@samsung.com (mailing list archive)
State New, archived
Headers show
Series block: add larger order folio instead of pages | expand

Commit Message

Kundan Kumar June 27, 2024, 10:45 a.m. UTC
Added new bio_add_hw_folio() function. This is a prep patch.

Signed-off-by: Kundan Kumar <kundan.kumar@samsung.com>
---
 block/bio.c | 33 ++++++++++++++++++++++++++++-----
 block/blk.h |  4 ++++
 2 files changed, 32 insertions(+), 5 deletions(-)

Comments

Christoph Hellwig June 28, 2024, 6:40 a.m. UTC | #1
On Thu, Jun 27, 2024 at 04:15:50PM +0530, Kundan Kumar wrote:
> Added new bio_add_hw_folio() function. This is a prep patch.
> 
> Signed-off-by: Kundan Kumar <kundan.kumar@samsung.com>
> ---
>  block/bio.c | 33 ++++++++++++++++++++++++++++-----
>  block/blk.h |  4 ++++
>  2 files changed, 32 insertions(+), 5 deletions(-)
> 
> diff --git a/block/bio.c b/block/bio.c
> index e9e809a63c59..6c2db8317ae5 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -979,6 +979,31 @@ bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
>  int bio_add_hw_page(struct request_queue *q, struct bio *bio,
>  		struct page *page, unsigned int len, unsigned int offset,
>  		unsigned int max_sectors, bool *same_page)
> +{
> +	struct folio *folio = page_folio(page);
> +	size_t folio_offset = (folio_page_idx(folio, page) << PAGE_SHIFT) +
> +			       offset;

Probably purely subjective, but I find this more readable:

	size_t folio_offset =
		(folio_page_idx(folio, page) << PAGE_SHIFT) + offset;

> +	return bio_add_hw_folio(q, bio, folio, len, folio_offset, max_sectors,
> +				same_page);

... or just open code it here:

	return bio_add_hw_folio(q, bio, folio, len,
			(folio_page_idx(folio, page) << PAGE_SHIFT) + offset,
			max_sectors, same_page);

> +		if (bvec_try_merge_hw_page(q, bv, folio_page(folio, 0), len,
> +					   offset, same_page)) {

Eventually bvec_try_merge_hw_page should be folio-ized as well.  But
we can do this separately if you don't want to take it on.
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index e9e809a63c59..6c2db8317ae5 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -979,6 +979,31 @@  bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
 int bio_add_hw_page(struct request_queue *q, struct bio *bio,
 		struct page *page, unsigned int len, unsigned int offset,
 		unsigned int max_sectors, bool *same_page)
+{
+	struct folio *folio = page_folio(page);
+	size_t folio_offset = (folio_page_idx(folio, page) << PAGE_SHIFT) +
+			       offset;
+
+	return bio_add_hw_folio(q, bio, folio, len, folio_offset, max_sectors,
+				same_page);
+}
+
+/**
+ * bio_add_hw_folio - attempt to add a folio to a bio with hw constraints
+ * @q: the target queue
+ * @bio: destination bio
+ * @folio: folio to add
+ * @len: vec entry length
+ * @offset: vec entry offset in the folio
+ * @max_sectors: maximum number of sectors that can be added
+ * @same_page: return if the segment has been merged inside the same folio
+ *
+ * Add a folio to a bio while respecting the hardware max_sectors, max_segment
+ * and gap limitations.
+ */
+int bio_add_hw_folio(struct request_queue *q, struct bio *bio,
+		struct folio *folio, size_t len, size_t offset,
+		unsigned int max_sectors, bool *same_page)
 {
 	unsigned int max_size = max_sectors << SECTOR_SHIFT;
 
@@ -992,8 +1017,8 @@  int bio_add_hw_page(struct request_queue *q, struct bio *bio,
 	if (bio->bi_vcnt > 0) {
 		struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
 
-		if (bvec_try_merge_hw_page(q, bv, page, len, offset,
-				same_page)) {
+		if (bvec_try_merge_hw_page(q, bv, folio_page(folio, 0), len,
+					   offset, same_page)) {
 			bio->bi_iter.bi_size += len;
 			return len;
 		}
@@ -1010,9 +1035,7 @@  int bio_add_hw_page(struct request_queue *q, struct bio *bio,
 			return 0;
 	}
 
-	bvec_set_page(&bio->bi_io_vec[bio->bi_vcnt], page, len, offset);
-	bio->bi_vcnt++;
-	bio->bi_iter.bi_size += len;
+	bio_add_folio_nofail(bio, folio, len, offset);
 	return len;
 }
 
diff --git a/block/blk.h b/block/blk.h
index d0a986d8ee50..8c27fd7cc6de 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -529,6 +529,10 @@  int bio_add_hw_page(struct request_queue *q, struct bio *bio,
 		struct page *page, unsigned int len, unsigned int offset,
 		unsigned int max_sectors, bool *same_page);
 
+int bio_add_hw_folio(struct request_queue *q, struct bio *bio,
+		struct folio *folio, size_t len, size_t offset,
+		unsigned int max_sectors, bool *same_page);
+
 /*
  * Clean up a page appropriately, where the page may be pinned, may have a
  * ref taken on it or neither.