Very quietly I take my leave,
As quietly as I came here;
Gently waving my sleeve,
I am not taking away a single cloud. - Xu Zhimo
-
man syscall or know more: linux-insides SysCall , linux-insides-zh SysCall
-
syscall interface (liburing interface wrapper syscall for cpu arch, man liburing help doc learn more):
/*
* System calls
*/
extern int io_uring_setup(unsigned entries, struct io_uring_params *p);
extern int io_uring_enter(int fd, unsigned to_submit,
unsigned min_complete, unsigned flags, sigset_t *sig);
extern int io_uring_register(int fd, unsigned int opcode, void *arg,
unsigned int nr_args);
-
linux kernel v6.3-rc2 interface ( syscall )
- io_uring_setup -> syscall --(soft interrupt)-->> sys_io_uring_setup -> SYSCALL_DEFINE2() > sysreturn io_uring_setup
- io_uring_enter -> syscall --(soft interrupt)-->> sys_io_uring_enter -> SYSCALL_DEFINE6(sysreturn io_uring_enter)
- io_uring_register -> syscall --(soft interrupt)-->> sys_io_uring_register -> SYSCALL_DEFINE4(io_uring_register)
-
see more support io_uring_op
-
io_uring kernel bug (fixed: io_put_kbuf):
- use liburing see readme, more detail: https://github.com/axboe/liburing
use cgo Notice: https://dave.cheney.net/2016/01/18/cgo-is-not-go
io_uring want learn more see those [updating]:
# see linux os kernel support uring kernel symbols
cat /proc/kallsyms | grep uring
# see syscall table idx no
ausyscall --dump
#sudo bpftrace -l | grep io_uring
#sudo perf list 'io_uring:*'
#sudo perf stat -e io_uring:io_uring_submit_sqe -- timeout 1 {process}
#sudo perf stat -e io_uring:io_uring_submit_sqe --timeout 1000 -p {pid}
#sudo perf stat -a -d -d -d --timeout 1000 -p {pid}
# when use io_uring check iou-***-*** kernel thread {wrk(work), sqp(sq-poll)} or old version {io_uring-sq(sq-poll)}
sudo bpftrace --btf -e 'kretprobe:create_io_thread { @[retval] = count(); } interval:s:1 { print(@); clear(@); } END { clear(@); }' | cat -s
#sudo bpftrace -e 'tracepoint:io_uring:io_uring_submit_sqe {printf("%s(%d)\n", comm, pid);}'
-
if need use golang runtime native support, please see this Note: #31908
-
3rd io_uring support for golang:
- https://github.com/hodgesds/iouring-go (old, no maintenance)
- https://github.com/godzie44/go-uring (use multi iouring impl golang net listener, acceptor,conn interface)
- https://github.com/Iceber/iouring-go (use epoll add eventfd IN event for io_uring peek cqe, depend epoll)
- https://github.com/ii64/gouring [√] (one to one liburing cp,test coverage ok,use userData need notice GC)
-
RocksDB MultiGet use IO Uring interface: https://github.com/facebook/rocksdb/wiki/MultiGet-Performance
- net IO for netpoll scenes (more unbounded work stream requests, S_IFSOCK type fd)
- tcp echo server, build & bench:
make build-echo make bench-echo
- storage IO for data file storage in HDD, NVMe SSD etc hardware scenes (more bounded work requests, eg: S_IFREG, S_ISBLK type fd)
- net IO
- redis: redis/redis#9440
- storage IO
https://sypalo.com/how-to-upgrade-ubuntu eg: upgrage linux kernel to v6.3-rc2 for Ubuntu 22.04.2 LTS
sudo apt-get upgrade
sudo apt-get update
# mainline: https://kernel.ubuntu.com/~kernel-ppa/mainline/?C=N;O=D ; u can chose latest linux kernel
sudo wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v6.3-rc2/amd64/linux-headers-6.3.0-060300rc2-generic_6.3.0-060300rc2.202303122031_amd64.deb
sudo wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v6.3-rc2/amd64/linux-headers-6.3.0-060300rc2_6.3.0-060300rc2.202303122031_all.deb
sudo wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v6.3-rc2/amd64/linux-image-unsigned-6.3.0-060300rc2-generic_6.3.0-060300rc2.202303122031_amd64.deb
sudo wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v6.3-rc2/amd64/linux-modules-6.3.0-060300rc2-generic_6.3.0-060300rc2.202303122031_amd64.deb
sudo apt install ./linux-*.deb
#restart
sudo reboot
Develop Tips:
- use UTM/VirtualBox/VMware install VM to run;
- use docker container to run;
- use vscode ssh remote or devcontainer to develop; recomend dev container with local env;
- bench net IO , server run in VM or physical machine;
- bench storage IO , server run in physical machine mount HDD, NVMe SSD etc hardware device;
- perf programe, cpu, memery, IO cost
Bench Tips:
- Bench net IO, use tcp tools:
- tcpdump check RST;
- netstat check es,cw,tw stat and static tcp send recv;
- ss static tcp stat;
- dstat report processors related statistics iowait,sys use;,send,recv;
- Bench storage IO, use storage IO tools:
- fio bench ioengine, check IOPS, bw;
- vmstat check io bi,bo, swap;
- iostat check device r/w tps, iowait;
sudo apt install moreutilscis
sudo apt install dstat
sudo apt install sysstat
sudo apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`
Perf tools:
- pprof(go): https://github.com/google/pprof
- gperftools(c/c++): https://github.com/gperftools/gperftools
- Linux kernel profiling with perf tutorial
- more perf tools : https://www.brendangregg.com/linuxperf.html
test VM
Distributor ID: Ubuntu
Description: Ubuntu Lunar Lobster (development branch)
Release: 23.04
Codename: lunar
Linux ubuntu2 6.2.0-18-generic #18-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 16 00:09:48 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
physical id 1
processor 4
cpu MHz : 1996.800
4 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
MemTotal: 2005084 kB
one cpu vcore, set affinity cpu 0 taskset -cp 0 $SRV_PID
(c pthread_setaffinity_np, syscall sched_setaffinity for thread pid)
go-netpoll | go-iouring | go-iouring-sqpoll | |
---|---|---|---|
c:300 bytes:128 | 38630 | 61884 | 78348 |
c:500 bytes:128 | 44235 | 65096 | 76976 |
c:1000 bytes:128 | 41551 | 62788 | 74774 |
c:2000 bytes:128 | 40133 | 64316 | 78213 |
c:300 bytes:512 | 42702 | 67029 | 82585 |
c:500 bytes:512 | 40298 | 61839 | 73856 |
c:1000 bytes:512 | 43908 | 65027 | 74533 |
c:2000 bytes:512 | 41182 | 63614 | 71960 |
c:300 bytes:1000 | 41143 | 65582 | 74441 |
c:500 bytes:1000 | 39191 | 63407 | 77784 |
c:1000 bytes:1000 | 42663 | 60978 | 74310 |
c:2000 bytes:1000 | 42207 | 58816 | 66598 |
- golang netpoll more workload(cpu), more G:M (init G:M, some M and G per connect);
- golang io_uring (sqp) less workload(cpu), less G:M (init G:M);
- https://unixism.net/loti/
- https://unixism.net/2020/04/io-uring-by-example-article-series/
- windows IORing: https://windows-internals.com/ioring-vs-io_uring-a-comparison-of-windows-and-linux-implementations/
- Diego Didona - Understanding Modern Storage APIs: A systematic study of libaio, SPDK, and io_uring , video
- awesome-iouring
- https://openanolis.cn/sig/high-perf-storage/doc/218455073889779745
- io_uring-and-networking-in-2023