Meta optimized its ad serving fleet by implementing a custom kernel scheduling policy using sched_ext, an open-source BPF-based extensible scheduling framework. This initiative significantly reduced p99 latency by 28%, saved 3.28 MW of power, and increased the number of ads ranked, demonstrating the business value of workload-specific scheduling in high-scale distributed systems. The solution decoupled scheduler optimization from kernel releases, enabling rapid, iterative improvements.
Read original on Meta EngineeringAt Meta's scale, the ads serving fleet handles over 5 million requests per second, where even small latency degradations can severely impact ad relevance and advertiser ROI. A Linux kernel upgrade (v6.9 with EEVDF scheduler) introduced a latency regression, reducing the number of ads ranked and forcing a subset of hosts to remain on an older kernel, creating significant technical debt. This highlighted the need for a more controlled and workload-aware scheduling mechanism.
To address the latency regression and gain finer control over CPU scheduling, Meta leveraged sched_ext, an open-source, BPF-based scheduler framework that entered kernel v6.12. This framework allows developers to implement custom scheduling policies as BPF programs, which are then called by the kernel through event-driven callbacks (e.g., thread wake-up, enqueue, dispatch, idle transitions).
Why BPF is key
BPF (Berkeley Packet Filter) allows sandboxed programs to run within the operating system kernel. For sched_ext, this means custom scheduling logic can be safely executed in kernel space without requiring kernel recompilation or modification, offering both performance and flexibility.
Meta's custom scheduling policy for the ads workload soft-partitions CPUs into two pools: one for latency-critical request path threads and another for less latency-sensitive work. This domain-specific knowledge, encoded directly into the BPF program, prioritizes work that improves p99 request latency. The policy dynamically adjusts pool sizes using load-based heuristics, aiming to keep related work on the same CPUs to improve L3 cache locality and reduce costly DRAM access.
The policy is packaged as a user-space binary, enabling rapid experimentation and deployment. Changes can be rolled out by simply restarting the scheduler process to load a new BPF program, drastically reducing the iteration time from months (for kernel patches) to days.