axboe / liburing

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

Coalescing of sequential read requests #999

Closed andyg24 closed 9 months ago

andyg24 commented 9 months ago

If I add 100 sequential read requests (e.g. for blocks 0-99 of a file), they appear to be coalesced and executed atomically by the NVME. That is, io_uring_wait_cqe_nr(1) will block until all 100 reads complete.

I see how this helps with throughput, but this can be a problem for an application that cares about latency and is ready to handle individual block reads as soon as they complete.

Is there a flag to prevent this coalescing and if not, would it make sense to add one?

axboe commented 9 months ago

This isn't something that io_uring controls, this is all done by the block layer. io_uring sends off separate requests, and the lower levels may merge them. If your device is nvme0n1, then you can turn that off completely with:

# echo 2 > /sys/block/nvme0n1/queue/nomerges

In that same directory, there are also settings for max request size. So if you think that eg a 128K request is fine, but you don't want it larger than that, you could do:

# echo 128 > /sys/block/nvme0n1/queue/max_sectors_kb
andyg24 commented 9 months ago

Thanks, didn't realize there already was a setting.