Skip to main content

Crate scx_mlfq

Crate scx_mlfq 

Source
Expand description

scx_mlfq, a Multilevel Feedback Queue scheduler for sched_ext.

Per-CPU, virtual-time-ordered user DSQs (Q1/Q2/Q3 per CPU) over an EEVDF virtual-time substrate. Tasks are classified into queues by a regression tree that predicts the next CPU burst from per-task features (see mlfq_tree.rs), with the EMA interactivity gauge as a tree feature and the fallback before the first model. The wakeup path is promotion-only, through the tree, the short-sleep and I/O boost and the band hysteresis. Demotion flows through the run-out gate. See README.md for the design overview.

Re-exportsยง

pub use bpf_intf::*;

Modulesยง

alloc ๐Ÿ”’
bpf_intf
bpf_skel ๐Ÿ”’
config ๐Ÿ”’
Userspace configuration, validated scheduling constants written into BPF rodata.
mlfq_tree ๐Ÿ”’
CART regression tree for next-CPU-burst prediction.
stats ๐Ÿ”’
Stats server, #[derive(Stats)] metrics and monitor loop.
topology ๐Ÿ”’
Hybrid-capacity and cache-domain topology discovery.
types
webui ๐Ÿ”’
Loopback web UI: live scheduler metrics as a small HTTP server.

Structsยง

BpfLinks
BpfMaps
BpfProgs
BpfSkel
BpfSkelBuilder
ModelMeta ๐Ÿ”’
Metadata of the committed MLFQ tree model, reported to the stats server and the exit log. Defaults describe the untrained state.
OpenBpfMaps
OpenBpfProgs
OpenBpfSkel
Opts ๐Ÿ”’
Scheduler ๐Ÿ”’
The Scheduler facade owns the loaded skeleton, the struct_ops link, the stats server and the MLFQ tree daemon state; drives the run loop until shutdown or UEI exit.
StructOps
TrainResult ๐Ÿ”’
Result of one training run, handed back from the worker thread. The metrics are computed on the held-out slice so the publish gate and the reported numbers describe out-of-sample error.

Constantsยง

MLFQ_IDLE_RESUME_LATENCY_US ๐Ÿ”’
MLFQ_MAX_CPUS ๐Ÿ”’
MLFQ_TREE_MAX_DEPTH ๐Ÿ”’
MLFQ_TREE_MAX_NODES ๐Ÿ”’
MLFQ_TREE_MIN_LEAF ๐Ÿ”’
MLFQ_TREE_MIN_PIDS ๐Ÿ”’
MLFQ_TREE_MIN_SAMPLES ๐Ÿ”’
MLFQ_TREE_PER_PID_CAP ๐Ÿ”’
MLFQ_TREE_RETRAIN_INTERVAL ๐Ÿ”’
MLFQ_TREE_WINDOW_MAX ๐Ÿ”’
NSEC_PER_USEC ๐Ÿ”’
SCHEDULER_NAME ๐Ÿ”’

Functionsยง

full_version ๐Ÿ”’
main ๐Ÿ”’
spawn_train_worker ๐Ÿ”’
Spawn the training worker and return its job and result channels.
split_holdout ๐Ÿ”’
Split the window into the fit slice (first 90%) and the held-out evaluation slice (last 10%). The daemon only trains once the window holds MLFQ_TREE_MIN_SAMPLES samples, so the holdout is never empty in production; a window too small for a meaningful 90/10 split (< 20 samples) is an error, which the caller treats as a skipped training round (log + keep the previous model) instead of silently training and evaluating on the same slice.
train_model ๐Ÿ”’
Fit a tree and compute the holdout metrics, on the training worker.
train_model_with_scratch ๐Ÿ”’
Fit a tree and compute holdout metrics reusing the scratch arena. The scratch buffers are cleared in place, so the second call with the same window size does not allocate.
tree_admit_pid ๐Ÿ”’
Admit one sample of pid into the window under the per-pid cap. Returns true when the sample is admitted and the pidโ€™s count is incremented, false when the pid already holds its MLFQ_TREE_PER_PID_CAP share and the caller must drop the sample. Entries are pruned on eviction, not here: a pid at the cap keeps its entry until the window ages its samples out.
tree_distinct_pids ๐Ÿ”’
Number of distinct pids in a slice, the concentration input for the per-pid cap.
tree_evict_pid ๐Ÿ”’
Remove one sample of pid from the per-pid accounting when the window evicts its oldest sample, pruning the entry when the count reaches zero so the map cannot grow with retired pids.