Skip to content

Commit 6450fe1

Browse files
isilenceaxboe
authored andcommitted
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 <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/fff34e613aeaae1ad12977dc4592cb1a1f5d3190.1634755800.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 057178c commit 6450fe1

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

block/fops.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,17 +503,20 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
503503
size_t shorted = 0;
504504
ssize_t ret;
505505

506-
if (pos >= size)
507-
return 0;
508-
509-
size -= pos;
510-
if (iov_iter_count(to) > size) {
511-
shorted = iov_iter_count(to) - size;
512-
iov_iter_truncate(to, size);
506+
if (unlikely(pos + iov_iter_count(to) > size)) {
507+
if (pos >= size)
508+
return 0;
509+
size -= pos;
510+
if (iov_iter_count(to) > size) {
511+
shorted = iov_iter_count(to) - size;
512+
iov_iter_truncate(to, size);
513+
}
513514
}
514515

515516
ret = generic_file_read_iter(iocb, to);
516-
iov_iter_reexpand(to, iov_iter_count(to) + shorted);
517+
518+
if (unlikely(shorted))
519+
iov_iter_reexpand(to, iov_iter_count(to) + shorted);
517520
return ret;
518521
}
519522

0 commit comments

Comments
 (0)