Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bio: optimise bvec iteration

__bio_for_each_bvec(), __bio_for_each_segment() and bio_copy_data_iter()
fall under conditions of bvec_iter_advance_single(), which is a faster
and slimmer version of bvec_iter_advance(). Add
bio_advance_iter_single() and convert them.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
22b56c29 6b6667aa

+17 -4
+2 -2
block/bio.c
··· 1212 1212 1213 1213 flush_dcache_page(dst_bv.bv_page); 1214 1214 1215 - bio_advance_iter(src, src_iter, bytes); 1216 - bio_advance_iter(dst, dst_iter, bytes); 1215 + bio_advance_iter_single(src, src_iter, bytes); 1216 + bio_advance_iter_single(dst, dst_iter, bytes); 1217 1217 } 1218 1218 } 1219 1219 EXPORT_SYMBOL(bio_copy_data_iter);
+15 -2
include/linux/bio.h
··· 148 148 /* TODO: It is reasonable to complete bio with error here. */ 149 149 } 150 150 151 + /* @bytes should be less or equal to bvec[i->bi_idx].bv_len */ 152 + static inline void bio_advance_iter_single(const struct bio *bio, 153 + struct bvec_iter *iter, 154 + unsigned int bytes) 155 + { 156 + iter->bi_sector += bytes >> 9; 157 + 158 + if (bio_no_advance_iter(bio)) 159 + iter->bi_size -= bytes; 160 + else 161 + bvec_iter_advance_single(bio->bi_io_vec, iter, bytes); 162 + } 163 + 151 164 #define __bio_for_each_segment(bvl, bio, iter, start) \ 152 165 for (iter = (start); \ 153 166 (iter).bi_size && \ 154 167 ((bvl = bio_iter_iovec((bio), (iter))), 1); \ 155 - bio_advance_iter((bio), &(iter), (bvl).bv_len)) 168 + bio_advance_iter_single((bio), &(iter), (bvl).bv_len)) 156 169 157 170 #define bio_for_each_segment(bvl, bio, iter) \ 158 171 __bio_for_each_segment(bvl, bio, iter, (bio)->bi_iter) ··· 174 161 for (iter = (start); \ 175 162 (iter).bi_size && \ 176 163 ((bvl = mp_bvec_iter_bvec((bio)->bi_io_vec, (iter))), 1); \ 177 - bio_advance_iter((bio), &(iter), (bvl).bv_len)) 164 + bio_advance_iter_single((bio), &(iter), (bvl).bv_len)) 178 165 179 166 /* iterate over multi-page bvec */ 180 167 #define bio_for_each_bvec(bvl, bio, iter) \