Skip to content

PATTERN Cited by 1 source

BPF scheduler for workload-specific optimization

Pattern

Deploy a custom BPF-based scheduling policy (via systems/sched-ext) that encodes application-level knowledge about thread priorities and workload structure directly into the kernel scheduler, replacing the general-purpose scheduler's fairness-optimised logic with domain-specific latency-optimised logic.

When to apply

  • The workload has a clear latency-critical path distinguishable from background work at the thread level.
  • General-purpose schedulers (CFS, EEVDF) leave measurable p99 latency on the table.
  • The fleet is large enough that per-host millisecond improvements compound to fleet-level business impact.
  • Kernel upgrades introduce scheduling regressions that cannot be addressed without forking.

Structure

  1. Classify threads: Identify which threads belong to the latency-critical request path and which are background (logging, GC, housekeeping).
  2. Encode classification into BPF policy: The policy's wake-up/enqueue/dispatch callbacks use this classification to make scheduling decisions.
  3. Apply workload-specific heuristics: e.g., soft-partition CPUs, prioritise critical-path threads, co-locate related threads for cache locality.
  4. Deploy as user-space binary: Policy iterations ship as binary restarts — no kernel patching.

Canonical instance

Meta's ads serving fleet: soft CPU partitioning + L3 cache locality optimization → 28% p99 reduction, 3.28 MW saved, +1.1% ads ranked. Two follow-on iterations in user space added 60% more p99 reduction + 18% fewer timeouts. (Source: sources/2026-07-13-meta-modernizing-ads-service-open-source-kernel-scheduler)

Trade-offs

  • Requires thread-level domain knowledge: the policy must know which threads matter. Workloads with undifferentiated thread pools benefit less.
  • Maintenance burden: policy correctness is the operator's responsibility (the kernel verifier guarantees safety, not optimality).
  • Interaction with other kernel subsystems: cgroup CPU controllers, NUMA balancing, power management may interact with custom policies in unexpected ways.

See also

Last updated · 585 distilled / 1,765 read