Commit 4d633062 authored by Ming Lei's avatar Ming Lei Committed by Jens Axboe

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: default avatarMing Lei <ming.lei@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 81214bab
...@@ -483,7 +483,7 @@ static unsigned blk_bvec_map_sg(struct request_queue *q, ...@@ -483,7 +483,7 @@ static unsigned blk_bvec_map_sg(struct request_queue *q,
offset = (total + bvec->bv_offset) % PAGE_SIZE; offset = (total + bvec->bv_offset) % PAGE_SIZE;
idx = (total + bvec->bv_offset) / PAGE_SIZE; idx = (total + bvec->bv_offset) / PAGE_SIZE;
pg = nth_page(bvec->bv_page, idx); pg = bvec_nth_page(bvec->bv_page, idx);
sg_set_page(*sg, pg, seg_size, offset); sg_set_page(*sg, pg, seg_size, offset);
......
...@@ -51,6 +51,11 @@ struct bvec_iter_all { ...@@ -51,6 +51,11 @@ struct bvec_iter_all {
unsigned done; unsigned done;
}; };
static inline struct page *bvec_nth_page(struct page *page, int idx)
{
return idx == 0 ? page : nth_page(page, idx);
}
/* /*
* various member access, note that bio_data should of course not be used * various member access, note that bio_data should of course not be used
* on highmem page vectors * on highmem page vectors
...@@ -87,8 +92,8 @@ struct bvec_iter_all { ...@@ -87,8 +92,8 @@ struct bvec_iter_all {
PAGE_SIZE - bvec_iter_offset((bvec), (iter))) PAGE_SIZE - bvec_iter_offset((bvec), (iter)))
#define bvec_iter_page(bvec, iter) \ #define bvec_iter_page(bvec, iter) \
nth_page(mp_bvec_iter_page((bvec), (iter)), \ bvec_nth_page(mp_bvec_iter_page((bvec), (iter)), \
mp_bvec_iter_page_idx((bvec), (iter))) mp_bvec_iter_page_idx((bvec), (iter)))
#define bvec_iter_bvec(bvec, iter) \ #define bvec_iter_bvec(bvec, iter) \
((struct bio_vec) { \ ((struct bio_vec) { \
...@@ -171,7 +176,7 @@ static inline void mp_bvec_last_segment(const struct bio_vec *bvec, ...@@ -171,7 +176,7 @@ static inline void mp_bvec_last_segment(const struct bio_vec *bvec,
unsigned total = bvec->bv_offset + bvec->bv_len; unsigned total = bvec->bv_offset + bvec->bv_len;
unsigned last_page = (total - 1) / PAGE_SIZE; unsigned last_page = (total - 1) / PAGE_SIZE;
seg->bv_page = nth_page(bvec->bv_page, last_page); seg->bv_page = bvec_nth_page(bvec->bv_page, last_page);
/* the whole segment is inside the last page */ /* the whole segment is inside the last page */
if (bvec->bv_offset >= last_page * PAGE_SIZE) { if (bvec->bv_offset >= last_page * PAGE_SIZE) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment