summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-09-25 13:38:25 -0700
committerKent Overstreet <kmo@daterainc.com>2014-06-17 18:25:59 -0700
commitbe646fb741b4ac289b9359296be3ddfe00567761 (patch)
treebc904ad9619ecaf8f0fef312c2bf322b8989cb81
parent0e4f3f4308ac5b8b74a9e06f00aabe767f70ec9e (diff)
Introduce blk_max_segment()
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
-rw-r--r--arch/x86/include/asm/io.h3
-rw-r--r--block/blk-merge.c51
-rw-r--r--drivers/xen/biomerge.c8
-rw-r--r--include/linux/blkdev.h1
4 files changed, 63 insertions, 0 deletions
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index b8237d8a1e0c..787abc48ea61 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -323,6 +323,9 @@ extern bool is_early_ioremap_ptep(pte_t *ptep);
#include <xen/xen.h>
struct bio_vec;
+extern bool xen_page_phys_mergeable(const struct page *p1,
+ const struct page *p2);
+
extern bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
const struct bio_vec *vec2);
diff --git a/block/blk-merge.c b/block/blk-merge.c
index c9aa3b35df72..8ff0237726e6 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -9,6 +9,57 @@
#include "blk.h"
+static unsigned int __blk_max_segment(struct request_queue *q, struct bio_vec *bv)
+{
+ unsigned len = bv->bv_len;
+
+ len = min_t(unsigned, len, blk_queue_cluster(q)
+ ? queue_max_segment_size(q)
+ : PAGE_SIZE);
+
+ len = min_t(unsigned, len,
+ queue_segment_boundary(q) + 1 -
+ (bvec_to_phys(bv) & queue_segment_boundary(q)));
+
+ return len;
+}
+
+#ifdef CONFIG_XEN
+unsigned int blk_max_segment(struct request_queue *q, struct bio_vec *bv)
+{
+ unsigned len = __blk_max_segment(q, bv);
+ unsigned ret;
+ struct page *next, *prev;
+
+ if (!xen_domain())
+ return len;
+
+ ret = min_t(unsigned, len, PAGE_SIZE - bv->bv_offset);
+ prev = bv->bv_page;
+
+ while (ret < len) {
+ next = nth_page(prev, 1);
+
+ if (!xen_page_phys_mergeable(prev, next))
+ break;
+
+ ret += min_t(unsigned, len - ret, PAGE_SIZE);
+ prev = next;
+ }
+
+ return ret;
+}
+
+#else
+
+unsigned int blk_max_segment(struct request_queue *q, struct bio_vec *bv)
+{
+ return __blk_max_segment(q, bv);
+}
+
+#endif
+EXPORT_SYMBOL(blk_max_segment);
+
static struct bio *blk_bio_discard_split(struct request_queue *q,
struct bio *bio,
struct bio_set *bs)
diff --git a/drivers/xen/biomerge.c b/drivers/xen/biomerge.c
index 0edb91c0de6b..d9fb59864f0b 100644
--- a/drivers/xen/biomerge.c
+++ b/drivers/xen/biomerge.c
@@ -3,6 +3,14 @@
#include <linux/export.h>
#include <xen/page.h>
+bool xen_page_phys_mergeable(const struct page *p1, const struct page *p2)
+{
+ unsigned long mfn1 = pfn_to_mfn(page_to_pfn(p1));
+ unsigned long mfn2 = pfn_to_mfn(page_to_pfn(p2));
+
+ return mfn1 + 1 == mfn2;
+}
+
bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
const struct bio_vec *vec2)
{
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 6e3eb56997d2..fd348a70f304 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -804,6 +804,7 @@ extern int blk_insert_cloned_request(struct request_queue *q,
extern void blk_delay_queue(struct request_queue *, unsigned long);
extern void blk_queue_split(struct request_queue *, struct bio **,
struct bio_set *);
+extern unsigned int blk_max_segment(struct request_queue *, struct bio_vec *);
extern void blk_recount_segments(struct request_queue *, struct bio *);
extern int scsi_verify_blk_ioctl(struct block_device *, unsigned int);
extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t,