I have been working on adding a new BPF-based I/O scheduler. It has both
kernel and user-space parts. In kernel space, using per-ctx, I implemented
a simple elevator that exposes a set of BPF hooks. The goal is to move the
policy side of I/O scheduling out of the kernel and into user space, which
should greatly increase flexibility and applicability. To verify that the
whole stack works end to end, I wrote a simple BPF example program. I am
calling this feature the UFQ (User-programmable Flexible Queueing) I/O
scheduler.
This patch depends on new BPF functionality that I have already posted to
the BPF community but that is not yet in mainline. Details are in the
thread:
https://lore.kernel.org/bpf/20260427165906.84420-1-kaitao.cheng@linux.dev/
To try it, you need to apply the patches from that series first.
I am looking for community feedback on whether this direction and the
implementation approach make sense, and what else we should
consider.
todo:
1. More thorough testing
2. Split the code into multiple sub-patches
3. Identify concrete use cases
Changes in v2:
- Remove bpf_request_put (Alexei Starovoitov)
- Update the UFQ README (Miguel Ojeda)
- Add bio merge support
- Fix synchronization issues during UFQ scheduler transitions
Link to v1:
https://lore.kernel.org/bpf/20260327114741.91500-1-pilgrimtao@gmail.com/
Kaitao Cheng (3):
bpf: Add KF_SPIN_LOCK flag for kfuncs under bpf_spin_lock
block: Introduce the UFQ I/O scheduler
tools/ufq_iosched: add BPF example scheduler and build scaffolding
block/Kconfig.iosched | 8 +
block/Makefile | 1 +
block/blk-merge.c | 28 +-
block/blk-mq.c | 8 +-
block/blk-mq.h | 2 +-
block/blk.h | 5 +
block/ufq-bpfops.c | 241 +++++++
block/ufq-iosched.c | 640 ++++++++++++++++++
block/ufq-iosched.h | 64 ++
block/ufq-kfunc.c | 131 ++++
include/linux/btf.h | 1 +
kernel/bpf/verifier.c | 20 +-
tools/ufq_iosched/.gitignore | 2 +
tools/ufq_iosched/Makefile | 262 +++++++
tools/ufq_iosched/README.md | 145 ++++
.../include/bpf-compat/gnu/stubs.h | 12 +
tools/ufq_iosched/include/ufq/common.bpf.h | 75 ++
tools/ufq_iosched/include/ufq/common.h | 90 +++
tools/ufq_iosched/include/ufq/simple_stat.h | 23 +
tools/ufq_iosched/ufq_simple.bpf.c | 604 +++++++++++++++++
tools/ufq_iosched/ufq_simple.c | 120 ++++
21 files changed, 2464 insertions(+), 18 deletions(-)
create mode 100644 block/ufq-bpfops.c
create mode 100644 block/ufq-iosched.c
create mode 100644 block/ufq-iosched.h
create mode 100644 block/ufq-kfunc.c
create mode 100644 tools/ufq_iosched/.gitignore
create mode 100644 tools/ufq_iosched/Makefile
create mode 100644 tools/ufq_iosched/README.md
create mode 100644 tools/ufq_iosched/include/bpf-compat/gnu/stubs.h
create mode 100644 tools/ufq_iosched/include/ufq/common.bpf.h
create mode 100644 tools/ufq_iosched/include/ufq/common.h
create mode 100644 tools/ufq_iosched/include/ufq/simple_stat.h
create mode 100644 tools/ufq_iosched/ufq_simple.bpf.c
create mode 100644 tools/ufq_iosched/ufq_simple.c
--
2.50.1 (Apple Git-155)