diff options
author | Pavel Begunkov | 2021-10-20 20:00:48 +0100 |
---|---|---|
committer | Jens Axboe | 2021-10-21 08:27:17 -0600 |
commit | 6450fe1f668f410fe2ab69c79a52a0929a4a8296 (patch) | |
tree | 1bdb58baedf360a0e43ae05cdee388597de95545 | |
parent | 057178cf518e699695a4b614a7a08c350b1fdcfd (diff) |
block: optimise boundary blkdev_read_iter's checks
Combine pos and len checks and mark unlikely. Also, don't reexpand if
it's not truncated.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/fff34e613aeaae1ad12977dc4592cb1a1f5d3190.1634755800.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | block/fops.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/block/fops.c b/block/fops.c index 21d25ee0e4bf..8f733c919ed1 100644 --- a/block/fops.c +++ b/block/fops.c @@ -503,17 +503,20 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) size_t shorted = 0; ssize_t ret; - if (pos >= size) - return 0; - - size -= pos; - if (iov_iter_count(to) > size) { - shorted = iov_iter_count(to) - size; - iov_iter_truncate(to, size); + if (unlikely(pos + iov_iter_count(to) > size)) { + if (pos >= size) + return 0; + size -= pos; + if (iov_iter_count(to) > size) { + shorted = iov_iter_count(to) - size; + iov_iter_truncate(to, size); + } } ret = generic_file_read_iter(iocb, to); - iov_iter_reexpand(to, iov_iter_count(to) + shorted); + + if (unlikely(shorted)) + iov_iter_reexpand(to, iov_iter_count(to) + shorted); return ret; } |