axboe / liburing

Library providing helpers for the Linux kernel io_uring support
MIT License
2.7k stars 393 forks source link

How to use IO_POLL mode in io_uring? Do I have to use direct I/O? #1138

Closed aidosww closed 2 months ago

aidosww commented 2 months ago

Here i have a question. I'm using kernel version 5.10. When I use IORING_SETUP_IOPOLL,

  1. Do I have to use DIRECT I/O when opening a file?
  2. Can IO_POLL be used to write file data? Thanks a lot!
axboe commented 2 months ago

Yes you have to use O_DIRECT with IOPOLL, if you attempt to use it with buffered IO it will error with -EOPNOTSUPP. IOPOLL can be used for both read and write.

aidosww commented 2 months ago

Yes you have to use O_DIRECT with IOPOLL, if you attempt to use it with buffered IO it will error with -EOPNOTSUPP. IOPOLL can be used for both read and write.

Thanks, this helps me a lot. So when I use IOPOLL and open a file with O_DIRECT, the buffer applied at the user application must be 4K aligned.

1.Can io_uring_register_buffers be used in this case? 2.io_uring_prep_provide_buffers can only be used under DIRECT I/O? Can it only be used for reading files?​​​

isilence commented 2 months ago

1.Can io_uring_register_buffers be used in this case?

Yes

2.io_uring_prep_provide_buffers can only be used under DIRECT I/O?

No. It should work regardless whether it's buffered or direct io. However, I don't see much sense in using provided buffers for storage IO.

Can it only be used for reading files?​​​

Currently yes, but Jens is trying to merge some support for sends. In any case it's mostly a network feature.

aidosww commented 2 months ago

1.Can io_uring_register_buffers be used in this case?

Yes

2.io_uring_prep_provide_buffers can only be used under DIRECT I/O?

No. It should work regardless whether it's buffered or direct io. However, I don't see much sense in using provided buffers for storage IO.

Can it only be used for reading files?​​​

Currently yes, but Jens is trying to merge some support for sends. In any case it's mostly a network feature.

Thank you very much! I still have some confusions about using DIRECT I/O and IO_POLL. 1.Do I need to implement a set of functions similar to the page cache from the kernel in the user space? If not, will it affect the performance of file reading and writing if I only use io_uring_register_buffers?

isilence commented 2 months ago

1.Do I need to implement a set of functions similar to the page cache from the kernel in the user space?

Not sure what you mean, but without Direct IO you wouldn't have buffering (i.e. page cache) with everything that follows from it.

will it affect the performance of file reading and writing if I only use io_uring_register_buffers?

Registered buffers are not helpful for buffered reads, otherwise they can help to shed some cycles. It's always a good idea to use them, but with IOPOLL those cycles may shift into iopolling, so for actual numbers it's better for you to experiment and measure.

aidosww commented 2 months ago

OK,these comments are very helpful for me! Thanks