Skip to main content

io_uring

Zero Copy, ring bazed communication channel.

  • Linux v5.1 - 2019-03-03
  • 场景
    • userspace <-> kernel 数据交互
    • async io
  • SQ - Submission Queue - struct io_uring_sqe
    • 应用
    • 维护 tail, kernel 消费 head
  • CQ - Completion Queue - struct io_uring_cqe
    • Kernel
    • 维护 tail, 应用 消费 head
int io_uring_setup(u32 nentries, struct io_uring_params *p);
int io_uring_enter(int ring_fd, u32 to_submit, u32 min_complete, u32 flags, sigset_t *sigset);

struct io_uring_params {
__u32 sq_entries;
__u32 cq_entries;
__u32 flags;
__u32 sq_thread_cpu;
__u32 sq_thread_idle;
__u32 features;
__u32 resv[4];
struct io_sqring_offsets sq_off;
struct io_cqring_offsets cq_off;
};

struct io_sqring_offsets {
__u32 head;
__u32 tail;
__u32 ring_mask;
__u32 ring_entries;
__u32 flags;
__u32 dropped;
__u32 array;
__u32 resv1;
__u64 resv2;
};

#define IORING_OFF_SQ_RING 0ULL
#define IORING_OFF_CQ_RING 0x8000000ULL
#define IORING_OFF_SQES 0x10000000ULL

// 通过 mmap 建立通道
sq->ring_ptr = mmap(
0,sq->ring_sz,
PROT_READ|PROT_WRITE|MAP_SHARED|MAP_POPULATE,
ring_fd,
IORING_OFF_SQ_RING
);