From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Ming Lei <ming.lei@redhat.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Christoph Hellwig <hch@lst.de>
Subject: [PATCH 1/2] block: integrity: enable multi-page bvec for bio integrity
Date: Tue, 23 Apr 2019 15:15:49 +0800 [thread overview]
Message-ID: <20190423071550.20806-2-ming.lei@redhat.com> (raw)
In-Reply-To: <20190423071550.20806-1-ming.lei@redhat.com>
bio integrity's bvec is same with the normal bvec, and it is pretty
straight-forward to enable multi-page bvec for bio integrity because
bio_for_each_integrity_vec() is based on for_each_bvec() which can
handle multi-page bvec well.
The integrity buffer can't be very big, for example, the max sectors
for one bio is 2560, one sector may take at most 8bytes for integrity
info, so the max size of integrity buffer is just 20k(<=5 pages). So
not like normal multi-page bvec convertion, this patch doesn't switch
blk_rq_map_integrity_sg() to iterate over multi-page bvec.
Cc: Martin K . Petersen <martin.petersen@oracle.com>,
Cc: Christoph Hellwig <hch@lst.de>,
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/bio-integrity.c | 18 ++++++++++++------
block/bio.c | 25 -------------------------
block/blk.h | 26 ++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 31 deletions(-)
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 1b633a3526d4..ba9d145315ed 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -143,18 +143,24 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
return 0;
}
- iv = bip->bip_vec + bip->bip_vcnt;
+ if (bip->bip_vcnt) {
+ iv = bip->bip_vec + bip->bip_vcnt - 1;
- if (bip->bip_vcnt &&
- bvec_gap_to_prev(bio->bi_disk->queue,
- &bip->bip_vec[bip->bip_vcnt - 1], offset))
- return 0;
+ if (bvec_gap_to_prev(bio->bi_disk->queue, iv, offset))
+ return 0;
+ if (page_is_mergeable(iv, page, len, offset, false)) {
+ iv->bv_len += len;
+ goto done;
+ }
+ }
+
+ iv = bip->bip_vec + bip->bip_vcnt;
iv->bv_page = page;
iv->bv_len = len;
iv->bv_offset = offset;
bip->bip_vcnt++;
-
+ done:
return len;
}
EXPORT_SYMBOL(bio_integrity_add_page);
diff --git a/block/bio.c b/block/bio.c
index c81ed2dfee53..89d1aa119a33 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -647,31 +647,6 @@ struct bio *bio_clone_fast(struct bio *bio, gfp_t gfp_mask, struct bio_set *bs)
}
EXPORT_SYMBOL(bio_clone_fast);
-static inline bool page_is_mergeable(const struct bio_vec *bv,
- struct page *page, unsigned int len, unsigned int off,
- bool same_page)
-{
- phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) +
- bv->bv_offset + bv->bv_len - 1;
- phys_addr_t page_addr = page_to_phys(page);
-
- if (vec_end_addr + 1 != page_addr + off)
- return false;
- if (xen_domain() && !xen_biovec_phys_mergeable(bv, page))
- return false;
-
- if ((vec_end_addr & PAGE_MASK) != page_addr) {
- if (same_page)
- return false;
- if (pfn_to_page(PFN_DOWN(vec_end_addr)) + 1 != page)
- return false;
- }
-
- WARN_ON_ONCE(same_page && (len + off) > PAGE_SIZE);
-
- return true;
-}
-
/*
* Check if the @page can be added to the current segment(@bv), and make
* sure to call it only if page_is_mergeable(@bv, @page) is true
diff --git a/block/blk.h b/block/blk.h
index e27fd1512e4b..1df54fa04edf 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -324,4 +324,30 @@ void blk_queue_free_zone_bitmaps(struct request_queue *q);
static inline void blk_queue_free_zone_bitmaps(struct request_queue *q) {}
#endif
+static inline bool page_is_mergeable(const struct bio_vec *bv,
+ struct page *page, unsigned int len, unsigned int off,
+ bool same_page)
+{
+ phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) +
+ bv->bv_offset + bv->bv_len - 1;
+ phys_addr_t page_addr = page_to_phys(page);
+
+ if (vec_end_addr + 1 != page_addr + off)
+ return false;
+ if (xen_domain() && !xen_biovec_phys_mergeable(bv, page))
+ return false;
+
+ if ((vec_end_addr & PAGE_MASK) != page_addr) {
+ if (same_page)
+ return false;
+ if (pfn_to_page(PFN_DOWN(vec_end_addr)) + 1 != page)
+ return false;
+ }
+
+ WARN_ON_ONCE(same_page && (len + off) > PAGE_SIZE);
+
+ return true;
+}
+
+
#endif /* BLK_INTERNAL_H */
--
2.9.5
next prev parent reply other threads:[~2019-04-23 7:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-23 7:15 [PATCH 0/2] block: enable multi-page bvec for bio integrity Ming Lei
2019-04-23 7:15 ` Ming Lei [this message]
2019-04-24 5:40 ` [PATCH 1/2] block: integrity: " Christoph Hellwig
2019-04-24 13:14 ` Martin K. Petersen
2019-04-24 13:18 ` Ming Lei
2019-04-23 7:15 ` [PATCH 2/2] block: integrity: simplify bio_integrity_prep Ming Lei
2019-04-24 5:42 ` Christoph Hellwig
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=20190423071550.20806-2-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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).