io_uring: retry in case of short read on block device
PATCH 1/1 io_uring: retry in case of short read on block device
In case of buffered reading from block device, when short read happens, we should retry to read more, otherwise the IO will be completed partially, for example, the following fio expects to read 2MB, but it can only read 1M or less bytes:
fio --name=onessd --filename=/dev/nvme0n1 --filesize=2M \ --rw=randread --bs=2M --direct=0 --overwrite=0 --numjobs=1 \ --iodepth=1 --time_based=0 --runtime=2 --ioengine=io_uring \ --registerfiles --fixedbufs --gtod_reduce=1 --group_reporting
Fix the issue by allowing short read retry for block device, which sets FMODE_BUF_RASYNC really.
--- fs/io_uring.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/io_uring.c +7 -1
@@ -3268,6 +3268,12 @@ static inline int io_iter_do_read(struct io_kiocb *req, struct iov_iter *iter)return -EINVAL ; } +static bool need_read_all (struct io_kiocb *req) +{ +return req->flags &REQ_F_ISREG || +S_ISBLK (file_inode (req->file)->i_mode); +} +static int io_read (struct io_kiocb *req,unsigned int issue_flags) {struct iovec inline_vecs[UIO_FASTIOV ], *iovec = inline_vecs;
@@ -3322,7 +3328,7 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags) }else if (ret == -EIOCBQUEUED ) { goto out_free; }else if (ret <=0 || ret == io_size || !force_nonblock || - (req->flags &REQ_F_NOWAIT ) || !(req->flags &REQ_F_ISREG )) { + (req->flags &REQ_F_NOWAIT ) || !need_read_all (req)) {/* read all, failed, already did sync or don't want to retry */ goto done; }
Signature · 1 line
2.31.1
Quoted 10 lines · Ming Lei
In case of buffered reading from block device, when short read happens, we should retry to read more, otherwise the IO will be completed partially, for example, the following fio expects to read 2MB, but it can only read 1M or less bytes:
fio --name=onessd --filename=/dev/nvme0n1 --filesize=2M \ --rw=randread --bs=2M --direct=0 --overwrite=0 --numjobs=1 \ --iodepth=1 --time_based=0 --runtime=2 --ioengine=io_uring \ --registerfiles --fixedbufs --gtod_reduce=1 --group_reporting
Quoted 6 lines
Fix the issue by allowing short read retry for block device, which sets
FMODE_BUF_RASYNCreally.Fixes 9a173346bd9e ("io_uring: fix short read retries for non-reg files")Cc Pavel Begunkov <[email protected]>Signed-off-by Ming Lei <[email protected]>
Hello Jens and Pavel,
Any comments on this fix?
Thanks,
Ming
Quoted 5 lines · Ming Lei
In case of buffered reading from block device, when short read happens, we should retry to read more, otherwise the IO will be completed partially, for example, the following fio expects to read 2MB, but it can only read 1M or less bytes:
Quoted 7 lines
fio --name=onessd --filename=/dev/nvme0n1 --filesize=2M \ --rw=randread --bs=2M --direct=0 --overwrite=0 --numjobs=1 \ --iodepth=1 --time_based=0 --runtime=2 --ioengine=io_uring \ --registerfiles --fixedbufs --gtod_reduce=1 --group_reportingFix the issue by allowing short read retry for block device, which sets
FMODE_BUF_RASYNCreally.
Should note that overhead on touching inode shouldn't be of concern at this point, so all looks good
Quoted 34 lines
Fixes 9a173346bd9e ("io_uring: fix short read retries for non-reg files")Cc Pavel Begunkov <[email protected]>Signed-off-by Ming Lei <[email protected]>--- fs/io_uring.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/io_uring.c +7
-1@@ -3268,6 +3268,12 @@ static inline int io_iter_do_read(struct io_kiocb *req, struct iov_iter *iter)return -EINVAL ; } +static bool need_read_all (struct io_kiocb *req) +{ +return req->flags &REQ_F_ISREG || +S_ISBLK (file_inode (req->file)->i_mode); +} +static int io_read (struct io_kiocb *req,unsigned int issue_flags) {struct iovec inline_vecs[UIO_FASTIOV ], *iovec = inline_vecs;@@ -3322,7 +3328,7 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags) }else if (ret == -EIOCBQUEUED ) { goto out_free; }else if (ret <=0 || ret == io_size || !force_nonblock || - (req->flags &REQ_F_NOWAIT ) || !(req->flags &REQ_F_ISREG )) { + (req->flags &REQ_F_NOWAIT ) || !need_read_all (req)) {/* read all, failed, already did sync or don't want to retry */ goto done; }
Signature · 1 line
Pavel Begunkov
Quoted 5 lines · Ming Lei
In case of buffered reading from block device, when short read happens, we should retry to read more, otherwise the IO will be completed partially, for example, the following fio expects to read 2MB, but it can only read 1M or less bytes:
Quoted 7 lines
fio --name=onessd --filename=/dev/nvme0n1 --filesize=2M \ --rw=randread --bs=2M --direct=0 --overwrite=0 --numjobs=1 \ --iodepth=1 --time_based=0 --runtime=2 --ioengine=io_uring \ --registerfiles --fixedbufs --gtod_reduce=1 --group_reportingFix the issue by allowing short read retry for block device, which sets
FMODE_BUF_RASYNCreally.
Applied, thanks Ming.
Signature · 1 line
Jens Axboe