iT邦幫忙

2025 iThome 鐵人賽

DAY 15
0

如果覺得文章對你有所啟發,可以考慮用 🌟 支持 Gthulhu 專案,短期目標是集齊 300 個 🌟 藉此被 CNCF Landscape 採納 [ref]

scx_rustland 是由任職於 NVIDIA 的大神 Andrea Righi 實作的排程器,它的設計理念是:

  1. 將排程器的決策 offload 到 user space,也就是在 user space 實作排程器。
  2. 排程器實作了一個基於 vruntime 的策略(類似於 CFS),並採用一些小技巧來檢測 interactive task 並稍微提高其優先級(透過查看 voluntary context switches 的數量來確定任務是否是 interactive task,未使用其分配的完整時間片就釋放 CPU 的任務很可能是 interactive task)。
  3. 排程器會根據目前排隊的任務數量來決定給定任務的 time slice。

補充:
起初 scx_rustland 是參考 voluntary context switches,但隨著 scx_rustland 的演化,現在是根據任務通過將停止執行與開始執行的時間戳相減取得實際的執行時間來取代原有的機制。

大致了解設計理念以後,稍微看一下技術細節(考慮的文章篇幅,這邊先不貼程式碼):

圖片來源:https://www.youtube.com/watch?v=L-39aeUQdS8

  1. 利用 eBPF Map(RingBuffer & UserRingBuffer)使 eBPF program 與 user space 排程器能夠傳遞任務
  2. 將排程器實作在 user space 可以利用 rust 豐富的套件,在 user space 也比起在 kernel space 更容易探測到外部環境的改變。
  3. scx_rustland 會考慮 CPU topology 為任務選擇一個最合適的 CPU。
  4. 實作客製化的 memory allocator 改善 user-space scheduler 的效能(這部分後面的篇章會探討)

scx_rustland 可以大幅改善 interactive task 的響應時間,目前 scx 最大的作用是改善 Linux 上的遊戲體驗,這點從 scx 最初的 DEMO 影片就能得知。

References

  1. https://arighi.blogspot.com/2024/02/
  2. https://arighi.blogspot.com/2025/05/revamping-my-linux-kernel-scheduler-in.html
  3. https://github.com/sched-ext/scx
  4. https://www.youtube.com/watch?v=L-39aeUQdS8

上一篇
scx_simple 實作解說
下一篇
scx_goland_core 移植與挑戰(一):page fault
系列文
30 篇文帶你用 eBPF 與 Golang 打造 Linux Scheduler17
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言