summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMing Lei <ming.lei@redhat.com>2019-02-27 07:40:10 -0500
committerJens Axboe <axboe@kernel.dk>2019-02-27 08:18:52 -0500
commit4d633062c1c0794a6b3836b7b55afba4599736e8 (patch)
tree548fd74a24fae2181f63fdde531ff63cc953d6c5
parent81214bab582eeda068e7904d57b6a3095e8f3855 (diff)
block: introduce bvec_nth_page()
Single-page bvec can often be seen in small BS workloads, so introduce bvec_nth_page() for avoiding to call nth_page() unnecessarily, which looks not cheap. Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--block/blk-merge.c2
-rw-r--r--include/linux/bvec.h11
2 files changed, 9 insertions, 4 deletions
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 066b66430523..c7e8a8273460 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -483,7 +483,7 @@ static unsigned blk_bvec_map_sg(struct request_queue *q,
483 483
484 offset = (total + bvec->bv_offset) % PAGE_SIZE; 484 offset = (total + bvec->bv_offset) % PAGE_SIZE;
485 idx = (total + bvec->bv_offset) / PAGE_SIZE; 485 idx = (total + bvec->bv_offset) / PAGE_SIZE;
486 pg = nth_page(bvec->bv_page, idx); 486 pg = bvec_nth_page(bvec->bv_page, idx);
487 487
488 sg_set_page(*sg, pg, seg_size, offset); 488 sg_set_page(*sg, pg, seg_size, offset);
489 489
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 30a57b68d017..4376f683c08a 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -51,6 +51,11 @@ struct bvec_iter_all {
51 unsigned done; 51 unsigned done;
52}; 52};
53 53
54static inline struct page *bvec_nth_page(struct page *page, int idx)
55{
56 return idx == 0 ? page : nth_page(page, idx);
57}
58
54/* 59/*
55 * various member access, note that bio_data should of course not be used 60 * various member access, note that bio_data should of course not be used
56 * on highmem page vectors 61 * on highmem page vectors
@@ -87,8 +92,8 @@ struct bvec_iter_all {
87 PAGE_SIZE - bvec_iter_offset((bvec), (iter))) 92 PAGE_SIZE - bvec_iter_offset((bvec), (iter)))
88 93
89#define bvec_iter_page(bvec, iter) \ 94#define bvec_iter_page(bvec, iter) \
90 nth_page(mp_bvec_iter_page((bvec), (iter)), \ 95 bvec_nth_page(mp_bvec_iter_page((bvec), (iter)), \
91 mp_bvec_iter_page_idx((bvec), (iter))) 96 mp_bvec_iter_page_idx((bvec), (iter)))
92 97
93#define bvec_iter_bvec(bvec, iter) \ 98#define bvec_iter_bvec(bvec, iter) \
94((struct bio_vec) { \ 99((struct bio_vec) { \
@@ -171,7 +176,7 @@ static inline void mp_bvec_last_segment(const struct bio_vec *bvec,
171 unsigned total = bvec->bv_offset + bvec->bv_len; 176 unsigned total = bvec->bv_offset + bvec->bv_len;
172 unsigned last_page = (total - 1) / PAGE_SIZE; 177 unsigned last_page = (total - 1) / PAGE_SIZE;
173 178
174 seg->bv_page = nth_page(bvec->bv_page, last_page); 179 seg->bv_page = bvec_nth_page(bvec->bv_page, last_page);
175 180
176 /* the whole segment is inside the last page */ 181 /* the whole segment is inside the last page */
177 if (bvec->bv_offset >= last_page * PAGE_SIZE) { 182 if (bvec->bv_offset >= last_page * PAGE_SIZE) {