I want to use async IO in my program. After some searching, I found nowait was added to avoid the blocking in aio. How can I check my system(block-device、plug, etc) supports nowait or not?
I am using ubuntu 22.04 with kernel version 6.2.6
I want to use async IO in my program. After some searching, I found nowait was added to avoid the blocking in aio. How can I check my system(block-device、plug, etc) supports nowait or not?
I am using ubuntu 22.04 with kernel version 6.2.6
Copyright © 2021 Jogjafile Inc.
The short answer is that today, you can't tell if a device supports NOWAIT I/O.
Inside the kernel, the block device queue will be tagged with
QUEUE_FLAG_NOWAITif it supports NOWAIT I/O. You can query the flag state withblk_queue_nowait. But, the flag isn't exposed to user space. (It'd be a trivial patch though.)That leaves you with trying to develop some sort of probe for NOWAIT support, but I'm afraid there isn't a straightforward answer there either.
iocbstructure way back, so there's no way for older kernels that don't know about NOWAIT to say "no, I don't support this flag." The flag just goes into the kernel and the kernel ignores it.NOWAIT, there's no "I don't support this" error return. Instead, a few things can happen:EAGAINforever. So, that's one probe you can try: do NOWAIT reads and see if the device ever handles one of them.NOWAITI/O on an older kernel with occasional blockingio_submitcalls.EAGAIN. That's what you're looking for. If you occasionally seeEAGAIN, that indicates that NOWAIT is probably working.I would offer that you might not need to worry about NOWAIT for a new application right off the bat. Plan for
io_submitto block for a few tens of microseconds. If need be, put the I/O handling in its own thread.