io_uring/ 异步 I/O 机制与原理详解

io_uring/ 异步 I/O 机制与原理详解

源码路径rk3588/kernel-6.1/io_uring/
内核版本:Linux 6.1(RK3588 / ARM64)
文档目录linuxDoc/io_uring/

io_uring 是 Linux 的高性能异步 I/O 接口:用户态与内核 共享 SQ/CQ 环形队列,通过 io_uring_setup / io_uring_enter / io_uring_register 三个系统调用完成提交与收割,多数路径可避免传统 read/write + 线程池的 syscall 开销。


目录


一、子系统职责

职责 实现
环创建与 mmap io_uring.cio_uring_create、SQE 数组、CQ 环
批量提交 io_submit_sqesio_submit_sqeio_issue_sqe
完成上报 io_get_cqe__io_commit_cqring_flush、overflow 链表
操作分派 opdef.cio_op_defs[opcode]
同步路径放不下的 I/O io-wq.c:per-task worker 池
内核代提 SQ sqpoll.cIORING_SETUP_SQPOLL
预注册 fd/缓冲区 rsrc.cfiletable.c
块/NVMe 等驱动命令 uring_cmd.c + 驱动 io_uring_cmd
网络异步 net.c
poll/epoll/timeout poll.cepoll.ctimeout.c

二、架构分层

flowchart TB
    subgraph app [用户态]
        A1[liburing / 自研]
    end
    subgraph syscall [系统调用]
        S1[io_uring_setup]
        S2[io_uring_enter]
        S3[io_uring_register]
    end
    subgraph core [io_uring.c]
        C1[io_ring_ctx]
        C2[submit / complete]
    end
    subgraph dispatch [opdef + 模块]
        D1[rw.c fs.c net.c ...]
        D2[uring_cmd.c]
    end
    subgraph async [io-wq / sqpoll]
        W1[io-wq workers]
        W2[SQ poll thread]
    end
    subgraph kernel [内核子系统]
        K1[VFS block net]
    end
    app --> syscall --> core --> dispatch
    dispatch --> async
    dispatch --> kernel
    async --> kernel

三、数据流概览

  1. setup:分配 io_ring_ctx,mmap SQ ring、CQ ring、SQE 数组(offsets 由 io_uring_params 返回)
  2. submit:用户写 SQE、推进 sq.tailio_uring_enter(to_submit) 或 SQPOLL 线程调用 io_submit_sqes
  3. issue:每个 SQE 对应 io_kiocbio_issue_sqe 调用 prep(提交前)与 issue
  4. complete:结果写入 CQ,io_uring_enter(GETEVENTS) 或 eventfd 唤醒;支持 LINKmultishot pollCQE32

四、Kconfig 与模块划分

  • CONFIG_IO_URING:主开关,默认开启
  • CONFIG_IO_WQ:异步工作队列(被 io_uring 选中)
  • 各 opcode 在 opdef.c#if defined(CONFIG_NET) 等裁剪 prepio_eopnotsupp_prep

详见 源码目录与模块索引.md


五、RK3588 说明

  • 源码树中 无 Rockchip 补丁;行为由通用 6.1 io_uring 决定
  • RK3588(ARM64 + GIC + eMMC/NVMe + 千兆网)适用场景:高 QPS 存储、网络代理、用户态协议栈
  • 注意 memlock 限制(注册缓冲区)、big.LITTLE 上与 IORING_SETUP_SQ_AFF / IOWQ_AFF 绑核

详见 07


功能组专题

编号 文档
01 核心接口与环机制与实现详解.md
02 提交与完成路径机制与实现详解.md
03 操作码与opdef分派机制与实现详解.md
04 异步执行与SQPOLL机制与实现详解.md
05 轮询超时与取消机制与实现详解.md
06 资源注册与URING_CMD机制与实现详解.md
07 RK3588平台关联与使用场景详解.md

文章互动

阅读 --

留言

0 条留言

正在加载留言…