Linus Torvalds expressed readiness adopt Linux 6.11 kernel, which is expected to be released at the end of September, patches with the implementation of the mechanism “sched_ext“(SCX), which allows you to use eBPF to create CPU schedulers that cover almost all aspects of task scheduling and CPU resource allocation. Such schedulers can be loaded dynamically and executed inside the Linux kernel in the eBPF virtual machine, in which, thanks to the use of JIT compilation, the bytecode is translated into machine instructions and executes with the performance of compiled code.
The proposed patches implement a new scheduling class SCHED_EXT, for which the kernel call priority is set between the SCHED_IDLE and SCHED_NORMAL classes, which does not allow BPF handlers bound to SCHED_EXT to affect tasks already attached to the regular task scheduler (SCHED_NORMAL), but makes it possible to attach to SCHED_EXT of individual tasks or move them to handle all processes with a priority lower than real-time execution. If there are no BPF handlers attached to SCHED_EXT, then all processes moved to the SCHED_EXT class will be processed using the SCHED_NORMAL scheduler. The work of BPF handlers consists of parsing queues of tasks waiting to be executed on the CPU (one global queue and one queue per CPU core), and selecting a task to which CPU resources should be allocated when the next CPU core is released.
The sched_ext mechanism makes it easy to create task-specific schedulers, allows you to experiment with different scheduling techniques and strategies, and allows you to quickly create working prototypes and replace schedulers on the fly in production infrastructures. For example, using sched_ext you can create a scheduler that takes into account the specifics of a particular application and dynamically changes the scheduling strategy for its execution depending on the state of the system and some additional factors.
Currently, about a dozen schedulers based on sched_ext are already being developed, the task scheduling logic in which is defined in user space and loaded into the kernel in the form of BPF programs:
- scx_layered – a hybrid task scheduler that divides tasks into layers, each of which has its own scheduling strategy. For example, scx_layered allows you to allocate certain tasks into a separate layer, for which certain guaranteed CPU resources will be provided, or to increase the priority of individual applications. The scheduler is developed by Meta. The user-space BPF generation logic is written in Rust.
- scx_rustland – the scheduler is optimized to increase the priority of interactive tasks over CPU-intensive tasks. For example, in a test of launching the Terraria game application simultaneously with the kernel build, the scx_rustland scheduler allowed us to achieve higher FPS in the game than when using the standard EEVDF scheduler. The project is being developed by a Canonical employee. The user-space BPF generation logic is written in Rust.
- scx_lavd – implementation of the LAVD (Latency-criticality Aware Virtual Deadline) task scheduling algorithm, which takes into account the relevance of reducing delays for specific tasks and uses information about the progress of processes when making decisions on the allocation of CPU resources. The scheduler is being developed by Igalia and Valve to reduce latency in computer games and interactive tasks. The user-space BPF generation logic is written in Rust.
- scx_rusty, scx_rlfifo, scx_mitosis – examples of schedulers with user-space components in the Rust language, implementing balancing between task groups depending on the load, a simple FIFO scheduler and a scheduler for linking task groups to CPU cores.
- scx_central, scx_flatcg, scx_nest, scx_pair, scx_qmap, scx_simple, scx_userland – examples of schedulers with user-space components in C, illustrating the various capabilities of sched-ext.
Initially, the sched_ext mechanism was proposed for review by kernel developers in 2022, after which six revisions of the patch were published. Despite the lack of support in the main kernel, for Ubuntu, Arch Linux, Fedora and NixOS distributions provided ability to install sched_ext through additional packages. Canonical is considering the possibility inclusion of sched-ext components in Ubuntu 24.10, and Valve works working on integrating sched_ext into Steam Deck. At Meta, the sched_ext-based scheduler is already used in production infrastructure.
Google is experimenting with its own framework ghOSt, which allows you to influence the decisions of the task scheduler using BPF programs. Currently, work has begun on porting ghOSt to sched_ext. Google is also developing a port of sched_ext for ChromeOS with the intention of using it to enable a hybrid scheduler scx_layered to reduce latency without using real-time extensions. Oculus is developing a port of sched_ext for Android.
Thanks for reading: