liburing: liburing/io_uring not working in kernel version 5.9+ on Ubuntu

I’ve come across a weird issue where io_uring/liburing doesn’t seem to work on kernel versions 5.9+. I tried 3 different kernel versions: v5.8.18, v5.9.0, v5.9.10, and it only worked on v5.8.18.

These are the steps I took to reproduce this (in place of [VERSION] I put v5.8.18, v5.9.0 and v5.9.10 in the 3 runs):

apt update && \
apt install -y build-essential gcc make git && \
wget https://raw.githubusercontent.com/pimlie/ubuntu-mainline-kernel.sh/master/ubuntu-mainline-kernel.sh && \
chmod +x ubuntu-mainline-kernel.sh && \
mv ubuntu-mainline-kernel.sh /usr/local/bin/ && \
ubuntu-mainline-kernel.sh -i [VERSION] && \
git clone https://github.com/axboe/liburing.git && \
cd liburing && make -j && \
make install && cd .. && \
wget https://raw.githubusercontent.com/shuveb/io_uring-by-example/master/05_webserver_liburing/main.c

The main.c file downloaded above is an example io_uring web server server from: https://github.com/shuveb/io_uring-by-example

After this, I rebooted, then tried to compile and run:

gcc main.c -o server -luring && \
echo "done" && \
./server

Connecting to the server via [IP]:8000 in a browser (where IP is the server IP or whatever), should have resulted in a 404 like this: image But instead results in a page just infinitely loading, and when you close the tab/stop it from loading, only then it prints a 404 message to the command line (on kernel versions v5.9.0 and v5.9.10).

uname -a from all 3 runs: v5.8.18: Linux ubuntu-2gb-hel1-3 5.8.18-050818-generic #202011011237 SMP Sun Nov 1 12:40:15 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux v5.9.0: Linux ubuntu-2gb-hel1-2 5.9.0-050900-generic #202010112230 SMP Sun Oct 11 22:34:01 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux v5.9.10: Linux ubuntu-2gb-hel1-1 5.9.10-050910-generic #202011221708 SMP Sun Nov 22 18:07:21 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

These were all run on fresh installs as well, what could be the issue here?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

Thanks for trying. I just reproduced and verified the fix, so hopefully the next -stable will have it for you and it’ll work. I’m going to go ahead and close this one, please do re-test with the next 5.9-stable or 5.10-stable.

A quick guess - you are actually doing make -j, which basically turns into a fork bomb… This triggers the oom killer, and you get killed tasks while compiling. Try doing eg make -j8 - that will use 8 tasks for compiling. What’s best depends on your system, for max speed I like to use -jN, where N == 2*NCPUS for that system.

Usually when it stalls like that it’s waiting for a mount point or device, which turns out to be missing from initramfs for whatever reason. So if you’re game, you could try and ensure that any storage device (and filesystem) you are using is set to =y in the kernel .config file. Then repeat your make and the rest of the steps, try and boot that kernel.

Yes, I’m using read, not recv. Turns out with recv this behaves as I expected! Thanks so much, I’d never have figured this out, I’ve always assumed recv was the same as read except that you can pass flags.

well, it’s a io_uring specific behaviour, read(2) and et al. don’t do that.

Does this depend on the kind of file descriptor I’m reading from? I think when I was reading from stdin instead of a socket I did see the short reads.

It should not. There was some specific bits that can indirectly slightly shift the observable behaviour, but that’s not for sure

3. put a read request for like 128 bytes into the buffer, call io_uring_enter to_submit=1 min_complete=0
   (a this point the data from the remote side becomes visible in the buffer but there is no completion event)

Since not too long ago io_uring hides short reads from users by internally resubmitting IO, like

while (size)
    size -= kernel_read(size, ...);

It looks like it’s what you see. Can you confirm that you use read requests but not recv?