Skip to content

Commit 4d63306

Browse files
Ming Leiaxboe
authored andcommitted
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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 81214ba commit 4d63306

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

block/blk-merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ static unsigned blk_bvec_map_sg(struct request_queue *q,
483483

484484
offset = (total + bvec->bv_offset) % PAGE_SIZE;
485485
idx = (total + bvec->bv_offset) / PAGE_SIZE;
486-
pg = nth_page(bvec->bv_page, idx);
486+
pg = bvec_nth_page(bvec->bv_page, idx);
487487

488488
sg_set_page(*sg, pg, seg_size, offset);
489489

include/linux/bvec.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ struct bvec_iter_all {
5151
unsigned done;
5252
};
5353

54+
static inline struct page *bvec_nth_page(struct page *page, int idx)
55+
{
56+
return idx == 0 ? page : nth_page(page, idx);
57+
}
58+
5459
/*
5560
* various member access, note that bio_data should of course not be used
5661
* on highmem page vectors
@@ -87,8 +92,8 @@ struct bvec_iter_all {
8792
PAGE_SIZE - bvec_iter_offset((bvec), (iter)))
8893

8994
#define bvec_iter_page(bvec, iter) \
90-
nth_page(mp_bvec_iter_page((bvec), (iter)), \
91-
mp_bvec_iter_page_idx((bvec), (iter)))
95+
bvec_nth_page(mp_bvec_iter_page((bvec), (iter)), \
96+
mp_bvec_iter_page_idx((bvec), (iter)))
9297

9398
#define bvec_iter_bvec(bvec, iter) \
9499
((struct bio_vec) { \
@@ -171,7 +176,7 @@ static inline void mp_bvec_last_segment(const struct bio_vec *bvec,
171176
unsigned total = bvec->bv_offset + bvec->bv_len;
172177
unsigned last_page = (total - 1) / PAGE_SIZE;
173178

174-
seg->bv_page = nth_page(bvec->bv_page, last_page);
179+
seg->bv_page = bvec_nth_page(bvec->bv_page, last_page);
175180

176181
/* the whole segment is inside the last page */
177182
if (bvec->bv_offset >= last_page * PAGE_SIZE) {

0 commit comments

Comments
 (0)