liburing: Question: will io_uring "block" current thread when reading regular file?
I try to create a database based on io_uring, therefore, I need to perform a lot of IO operations on regular files. After a lot of searching, I am confused about how io_uring works on the regular file.
According to lord of io_uring, io_uring works fine for regular files. However, after reading worker pool in io_uring, I think reading regular files will “block” the current thread(I am a kernel newbie, so correct me if am wrong 0.0) :
- After submission, io_uring will try to call a non-blocking read on the regular file.
- Because it is a regular file, non-blocking read always returns
Ready. // Non blocking IO with regular file - Read operation will execute in
complete inlinemode to read from the file system on the thread that callsio_uring_enter. “Blocking” happens here.
According to the above assumption, I write a simple program: submit multiple read operations in batch to io_uring and wait for completion in the end. With perf command:
sudo perf stat -a -e 'io_uring:io_uring_*' -- ./demo
I do not observe the hit on io_uring:io_uring_poll_arm and io_uring:io_uring_queue_async_work. Then I profile the program with flame graph, the flame graphs tell me that all of the cpus are used on reading from file system, which is inside the io_uring_enter syscall. All two profiles prove my thought.
So, reading from the file system is pretty expensive, will it block the thread?(Can not handle the task that is waked up by socket, etc.) Shall we be encouraged to submit the read operation on a regular file with async to put it on the worker pool?
Thanks!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (4 by maintainers)
Commits related to this issue
- iomap: propagate nowait to block layer There are reports of high io_uring submission latency for ext4 and xfs, which is due to iomap not propagating nowait flag to the block layer resulting in waitin... — committed to intel-lab-lkp/linux by isilence 2 years ago
- iomap: propagate nowait to block layer There are reports of high io_uring submission latency for ext4 and xfs, which is due to iomap not propagating nowait flag to the block layer resulting in waitin... — committed to intel-lab-lkp/linux by isilence 2 years ago
Yep, what @GalaxySnail said, just on the kernel side. Some exceptions on cases where we know it doesn’t work (eg we can check upfront), for those it goes straight to io-wq as a nonblocking attempt isn’t possible.
In general, any io-wq activity is not ideal. Seeing some on storage workloads isn’t a major source for concern however, that can happen even on cases that do fully support nonblocking issue. Examples of that include queue being quisced for whatever reason, or running out of resources.
I assume that it’s doing something like:
So it’s iomap. The (kernel) patch below should help, can you try it?