Linux block layer
 help / color / mirror / Atom feed
From: Kundan Kumar <kundan.kumar@samsung.com>
To: axboe@kernel.dk, hch@lst.de, willy@infradead.org, kbusch@kernel.org
Cc: linux-block@vger.kernel.org, joshi.k@samsung.com,
	mcgrof@kernel.org, anuj20.g@samsung.com, nj.shetty@samsung.com,
	c.gameti@samsung.com, gost.dev@samsung.com,
	Kundan Kumar <kundan.kumar@samsung.com>
Subject: [PATCH v5 1/3] block: Added folio-lized version of bio_add_hw_page()
Date: Wed, 19 Jun 2024 08:04:18 +0530	[thread overview]
Message-ID: <20240619023420.34527-2-kundan.kumar@samsung.com> (raw)
In-Reply-To: <20240619023420.34527-1-kundan.kumar@samsung.com>

Added new bio_add_hw_folio() function. This is a prep patch.

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

diff --git a/block/bio.c b/block/bio.c
index e9e809a63c59..c8914febb16e 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -964,7 +964,7 @@ bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
 }

 /**
- * bio_add_hw_page - attempt to add a page to a bio with hw constraints
+ * bio_add_hw_page - a wrapper around function bio_add_hw_folio
  * @q: the target queue
  * @bio: destination bio
  * @page: page to add
@@ -972,13 +972,35 @@ bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
  * @offset: vec entry offset
  * @max_sectors: maximum number of sectors that can be added
  * @same_page: return if the segment has been merged inside the same page
- *
- * Add a page to a bio while respecting the hardware max_sectors, max_segment
- * and gap limitations.
  */
 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 page
+ *
+ * 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, unsigned int len, unsigned int offset,
+               unsigned int max_sectors, bool *same_page)
 {
        unsigned int max_size = max_sectors << SECTOR_SHIFT;

@@ -992,8 +1014,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 +1032,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 79e8d5d4fe0c..d0bec44a2ffb 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -524,6 +524,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, unsigned int len, unsigned int 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.
--
2.25.1


  reply	other threads:[~2024-06-19  4:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20240619024142epcas5p22b2e0f83e526fc74fda62a4837bed544@epcas5p2.samsung.com>
2024-06-19  2:34 ` [PATCH v5 0/3] block: add larger order folio instead of pages Kundan Kumar
2024-06-19  2:34   ` Kundan Kumar [this message]
2024-06-20  3:47     ` [PATCH v5 1/3] block: Added folio-lized version of bio_add_hw_page() Matthew Wilcox
2024-06-19  2:34   ` [PATCH v5 2/3] block: add folio awareness instead of looping through pages Kundan Kumar
2024-06-19  7:47     ` Hannes Reinecke
2024-06-20  4:48       ` Kundan Kumar
2024-06-20  7:21         ` Hannes Reinecke
2024-06-19  2:34   ` [PATCH v5 3/3] block: unpin user pages belonging to a folio Kundan Kumar
2024-06-20  3:51     ` 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=20240619023420.34527-2-kundan.kumar@samsung.com \
    --to=kundan.kumar@samsung.com \
    --cc=anuj20.g@samsung.com \
    --cc=axboe@kernel.dk \
    --cc=c.gameti@samsung.com \
    --cc=gost.dev@samsung.com \
    --cc=hch@lst.de \
    --cc=joshi.k@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=nj.shetty@samsung.com \
    --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