内核支持4种抢占模型
内核配置路径:General setup -> Preemption Model
Kconfig文件:kernel/Kconfig.preempt
选中:CONFIG_PREEMPT_NONE
禁止抢占,这是传统的linux抢占模型,为了吞吐量而生,但大多数情况下,仍然保持很好的低延迟。
服务器、科学计算系统选择这个选项。
选中:CONFIG_PREEMPT_VOLUNTARY
在内核中添加更多的显示抢占点(explicit preemption points)。
这些新的抢占可以减少重新调度的最大延时,这样可以提高更快的程序响应,代价是轻微的吞吐量下降。
This allows reaction to interactive events by allowing a low priority process to voluntarily
preempt itself even if it is in kernel mode executing a system call.
This allows applications to run more 'smoothly' even when the system is under load
桌面系统选择这种抢占模型。
选中:CONFIG_PREEMPT
自动选中:CONFIG_PREEMPTION 和 CONFIG_PREEMPT_COUNT
所有的内核代码都可以被抢占,即使代码还没有运行到自然的抢占点(natural preemption point)。
低延时桌面系统选择这种抢占模型。
选中:CONFIG_PREEMPT_RT
需要先选中CONFIG_EXPERT,还可以选择此选项。
通过替换各种locking primitives (如spinlocks rwlocks)为preemptible priority-inheritance aware变种。
将内核变成 real-time kernel
参考
Linux kernel preemption and the latency-throughput tradeoff
https://www.codeblueprint.co.uk/2019/12/23/linux-preemption-latency-throughput.html
linux5.5: consider switching from PREEMPT to PREEMPT_VOLUNTARY #18940
https://github.com/void-linux/void-packages/issues/18940