sched_ext 完整资源指南
项目概览
sched_ext是Linux内核的一个革命性特性,允许使用BPF实现内核线程调度器并动态加载。从Linux 6.12开始正式上游化。
核心价值: 实现安全、快速的调度器迭代,将调度策略实验范围从内核专家扩展到更广泛的用户群体。
官方资源
GitHub仓库
- 主仓库: https://github.com/sched-ext/scx
- 状态: 从Linux 6.12开始上游支持
- 支持者: Meta和Google全力投入,Meta正在大规模生产部署
社区渠道
- Slack: https://schedextworkspace.slack.com
- Reddit: https://reddit.com/r/sched_ext
- 每周例会: 每周二举行(Slack #office-hours频道)
调度器实现
官方调度器
| 调度器 | 描述 | 适用场景 |
|---|---|---|
| scx_lavd | 强调交互性,提升游戏帧率 | Steam Deck游戏系统 ⭐ |
| scx_bpfland | 最小化响应时间 | 个人计算机 |
| scx_rustland | 用户空间Rust调度 | 灵活的用户态决策 |
| scx_layered | 分层调度器 | 生产环境复杂工作负载 |
| scx_central | 中央调度器 | 集中式调度决策 |
| scx_flatcg | 扁平Cgroup调度 | Cgroup资源管理 |
| scx_qmap | 队列映射调度器 | 特定队列需求 |
| scx_flash | 闪存优化调度 | 存储相关工作负载 |
| scx_tickless | 无tick调度 | 节能场景 |
| scx_cosmos | 新调度器 (2025) | 实验性 |
| scx_p2dq | 两阶段双队列 | 多队列场景 |
| scx_wd40 | WD40调度器 | 特定优化 |
| scx_mitosis | 有丝分裂调度 | 任务分裂场景 |
| scx_chaos | 混沌测试调度 | 测试和验证 |
调度器选择建议
游戏/桌面用户:
# scx_lavd - 已用于Steam Deck
scx_lavd
# scx_bpfland - 个人计算机表现出色
scx_bpfland
服务器/生产环境:
# scx_layered - 复杂生产工作负载
scx_layered
# scx_rusty - Rust实现的高性能调度
scx_rusty
开发/测试:
# scx_rustland - 用户空间调度实验
scx_rustland
# scx_central - 理解中央调度概念
scx_central
LWN文章
| 日期 | 标题 | 链接 |
|---|---|---|
| 2023-02 | The extensible scheduler class | https://lwn.net/Articles/922405/ |
| 2024-05 | Another push for sched_ext | https://lwn.net/Articles/973796/ |
| 2024-05 | What’s scheduled for sched_ext | https://lwn.net/Articles/974709/ |
技术博客
arighi’s blog
- 2023-07: Implement your own kernel CPU scheduler in Ubuntu with sched-ext
- 2024-04: Getting started with sched-ext development
- YouTube: scx_bpfland Linux scheduler demo: topology awareness
Changwoo’s blog
- 2023-12: sched_ext: a BPF-extensible scheduler class (Part 1)
- 2024-06: sched_ext: scheduler architecture and interfaces (Part 2)
演讲视频
Kernel Recipes
- 2023-09: David Vernet - sched_ext: pluggable scheduling in the Linux kernel
- 2024-09: David Vernet - Scheduling with superpowers: Using sched_ext
- 2025-09: arighi - Schedule Recipes
Linux Plumbers Conference
- 2024: Kernel Plumbers Conference MC (关于sched_ext的讨论)
- 2025: 持续更新
YouTube播放列表: Sched_ext YT playlist
重要里程碑
2024年 - 上游化之年
2024年6月: Linus Torvalds宣布将在Linux 6.11合入sched_ext
2024年9月: Linux 6.11发布,sched_ext正式上游化
2024年12月: Tejun Heo从scx仓库同步更新到内核
2025年 - 成熟之年
2025年: sched_ext持续活跃开发
2025年: 新调度器scx_cosmos等加入
2025年: LPC东京会议讨论BPF arenas和可组合调度器
使用指南
安装
Ubuntu/Debian:
# 添加PPA或使用官方包
sudo apt install scx-scheds
从源码编译:
git clone https://github.com/sched-ext/scx.git
cd scx
meson setup build
cd build
ninja
运行调度器
# 运行scx_lavd
sudo scx_lavd
# 带监控运行
scx_lavd --monitor 5
# 运行scx_bpfland
sudo scx_bpfland
# 运行scx_rustland
sudo scx_rustland
监控输出示例
scx_bpfland:
[scx_bpfland] tasks -> run: 3/4 int: 2 wait: 3 | nvcsw: 3 | dispatch -> dir: 0 prio: 73 shr: 9
[scx_bpfland] tasks -> run: 4/4 int: 2 wait: 2 | nvcsw: 3 | dispatch -> dir: 1 prio: 3498 shr: 1385
scx_rusty:
###### Thu, 29 Aug 2024 14:42:37 +0200, load balance @ -265.1ms ######
cpu= 0.00 load= 0.17 mig=0 task_err=0 lb_data_err=0 time_used= 0.0ms
技术架构
BPF调度器工作流程
- 任务拦截: 任务被添加到BPF_MAP_TYPE_RINGBUF
- BPF唤醒: BPF程序唤醒用户空间调度器
- 用户空间决策: 用户空间调度器读取任务并分配CPU/时间片
- 任务分发: 处理后的任务放入BPF_MAP_TYPE_USER_RINGBUF
关键数据结构
// 任务状态枚举
enum scx_task_state {
SCX_TASK_NONE,
SCX_TASK_INIT,
SCX_TASK_READY,
SCX_TASK_ENABLED,
SCX_TASK_NR_STATES
};
// DSQ (Dispatch Queue) ID
#define SCX_DSQ_GLOBAL 0
#define SCX_DSQ_LOCAL 1
// 入队标志
#define SCX_ENQ_WAKEUP (1ULL << 0)
#define SCX_ENQ_HEAD (1ULL << 1)
#define SCX_ENQ_PREEMPT (1ULL << 2)
与其他项目的关联
Ghost (Google)
- 关系: sched_ext的前身和灵感来源
- 论文: SOSP’21 Ghost: Fast and flexible user-space delegation
- GitHub: https://github.com/google/ghost-userspace
Flux
- 关系: LPC 2023提出的Ghost BPF调度设计框架
- 演讲: LPC 2023
EEVDF
- 关系: Linux默认调度器,由Peter Zijlstra维护
- 状态: 与sched_ext并行发展
常见问题
Q: sched_ext会替代CFS吗?
A: 不会。sched_ext是一个可扩展的调度器类,与CFS共存。用户可以根据需要选择使用。
Q: 生产环境安全吗?
A: 从Linux 6.12开始上游化,Meta正在大规模生产部署,已被证明是安全的。
Q: 需要BPF知识吗?
A: 基础使用不需要。但自定义调度器需要了解BPF编程。
相关论文
- Ghost (SOSP’21): Ghost: Fast and flexible user-space delegation of Linux scheduling
- Enoki (EuroSys’24): A Rust Linux Kernel Scheduler Framework
- eBPF Runtime (SOSP’24): The eBPF Runtime in the Linux Kernel
延伸阅读
- Linux内核文档: Documentation/scheduler/sched-ext.rst
- BPF文档: https://docs.kernel.org/bpf/
- LWN调度器文章: https://lwn.net/Kernel/Index/
⚠️ 免责声明
本网站内容由 AI 工具辅助生成,仅供参考和学习使用。作者不对内容的准确性、完整性和适用性做任何保证。使用本站信息所造成的任何损失,作者不承担任何责任。请在生产环境使用前进行充分测试和验证。