[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230503100220epcms2p33e69fd7d5f04b305c621799792e8155f@epcms2p3>
Date: Wed, 03 May 2023 19:02:20 +0900
From: Jinyoung CHOI <j-young.choi@...sung.com>
To: Jinyoung CHOI <j-young.choi@...sung.com>,
"axboe@...nel.dk" <axboe@...nel.dk>, "hch@....de" <hch@....de>,
"martin.petersen@...cle.com" <martin.petersen@...cle.com>,
"linux-block@...r.kernel.org" <linux-block@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH 02/15] block: blk-integiry: add helper functions for
bio_integrity_add_page
Add functions that use the hardware limit to merge the page with
integrity's bio_vec.
Using the added functions, the physically continuous pages are made of
one bio_vec.
Previously, physically continuous pages were not created as one
bio_vec, but separately created.
Cc: Christoph Hellwig <hch@....de>
Cc: Martin K. Petersen <martin.petersen@...cle.com>
Signed-off-by: Jinyoung Choi <j-young.choi@...sung.com>
---
block/bio-integrity.c | 58 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 4533eb491661..06b6a2c178d2 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -111,6 +111,64 @@ void bio_integrity_free(struct bio *bio)
bio->bi_opf &= ~REQ_INTEGRITY;
}
+/**
+ * bip_full - check if the bip is full
+ * @bip: bip to check
+ * @len: length of one segment to be added
+ *
+ * Return true if @bip is full and one segment with @len bytes can't be
+ * added to the bip, otherwise return false
+ */
+static inline bool bip_full(struct bio_integrity_payload *bip, unsigned int len)
+{
+ if (bip->bip_vcnt >= bip->bip_max_vcnt)
+ return true;
+ if (bip->bip_iter.bi_size > UINT_MAX - len)
+ return true;
+ return false;
+}
+
+/**
+ * bip_try_merge_hw_seg - try to merge a page into a segment, while
+ * obeying the hardware segment size limit
+ * @q: the target queue
+ * @bip: bip to check
+ * @page: page containing integrity metadata
+ * @len: number of bytes of integrity metadata in page
+ * @offset: start offset within page
+ * @same_page: return if the segment has been merged inside the same page
+ *
+ * Return true if @page is merged to @bip, otherwise return false
+ */
+static bool bip_try_merge_hw_seg(struct request_queue *q,
+ struct bio_integrity_payload *bip,
+ struct page *page, unsigned int len,
+ unsigned int offset, bool *same_page)
+{
+ struct bio_vec *bv = &bip->bip_vec[bip->bip_vcnt - 1];
+ unsigned long mask = queue_segment_boundary(q);
+ phys_addr_t addr1 = page_to_phys(bv->bv_page) + bv->bv_offset;
+ phys_addr_t addr2 = page_to_phys(page) + offset + len - 1;
+
+ if ((addr1 | mask) != (addr2 | mask))
+ return false;
+ if (bv->bv_len + len > queue_max_segment_size(q))
+ return false;
+
+ if (bip->bip_vcnt > 0) {
+ if (bio_page_is_mergeable(bv, page, len, offset, same_page)) {
+ if (bip->bip_iter.bi_size > UINT_MAX - len) {
+ *same_page = false;
+ return false;
+ }
+ bv->bv_len += len;
+ bip->bip_iter.bi_size += len;
+ return true;
+ }
+ }
+ return false;
+}
+
/**
* bio_integrity_add_page - Attach integrity metadata
* @bio: bio to update
--
2.34.1
Powered by blists - more mailing lists