block: optimize bvec iteration in bvec_iter_advance
PATCH 1/1 block: optimize bvec iteration in bvec_iter_advance
There is no need to only iterate in chunks of PAGE_SIZE or less in bvec_iter_advance, given that the callers pass in the chunk length that they are operating on - either that already is less than PAGE_SIZE because they do classic page-based iteration, or it is larger because the caller operates on multi-page bvecs.
This should help optimizing shaving off a few cycles of the I/O hot path.
--- include/linux/bvec.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
include/linux/bvec.h +4 -3
@@ -112,14 +112,15 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, }while (bytes) { -unsigned iter_len =bvec_iter_len (bv, *iter); -unsigned len =min (bytes, iter_len); +const struct bio_vec *cur = bv + iter->bi_idx; +unsigned len =min3 (bytes, iter->bi_size, + cur->bv_len - iter->bi_bvec_done); bytes -= len; iter->bi_size -= len; iter->bi_bvec_done += len; -if (iter->bi_bvec_done ==__bvec_iter_bvec (bv, *iter)->bv_len) { +if (iter->bi_bvec_done == cur->bv_len) { iter->bi_bvec_done =0 ; iter->bi_idx++; }
Signature · 1 line
2.20.1
Quoted 3 lines · Christoph Hellwig
There is no need to only iterate in chunks of
PAGE_SIZEor less inbvec_iter_advance, given that the callers pass in the chunk length that they are operating on - either that already is less thanPAGE_SIZE
this? ^
Quoted 4 lines
because they do classic page-based iteration, or it is larger because the caller operates on multi-page bvecs.
This should help optimizing shaving off a few cycles of the I/O hot
optimizing || shaving off, both together sounds awkward.
Otherwise
Signature · 6 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Quoted 8 lines · Christoph Hellwig
There is no need to only iterate in chunks of
PAGE_SIZEor less inbvec_iter_advance, given that the callers pass in the chunk length that they are operating on - either that already is less thanPAGE_SIZEbecause they do classic page-based iteration, or it is larger because the caller operates on multi-page bvecs.This should help optimizing shaving off a few cycles of the I/O hot path.
Applied, thanks.
Signature · 1 line
Jens Axboe