Live cgroup interface files (voltron_cgroup_lp)

Live-inject voltron.policy into the cgroup filesystem.

A loadable module that live-injects Voltron's per-cgroup policy into the running kernel's cgroup-v2 hierarchy — no reboot, no kernel rebuild — so policy appears in its natural place:

/sys/fs/cgroup/<some.slice>/voltron.policy

1One unified policy store

This module provides only the cgroup-fs view. The data lives in the main module (voltron.ko), which exports voltron_policy_show() and voltron_policy_set_kv(); this module calls them, so both surfaces are the same store:

SurfaceBacked by
/sys/fs/cgroup/<cg>/voltron.policy (this module)voltron.ko policy store
/sys/kernel/voltron/policy/cgroups/<id>/… (voltron.ko)voltron.ko policy store

Writing a field through either surface updates the one record; the resolver voltron_policy_resolve() and the (future) migration engine see it immediately. Consequently voltron_cgroup_lp **depends on voltron** (load order enforced by module deps).

2Why a live patch (and not a normal module or a klp patch)

3How it works

  1. Resolve kallsyms_lookup_name via a short-lived kprobe (it is no longer exported since 5.7).
  2. Resolve the non-exported cgroup_add_dfl_cftypes / cgroup_rm_cftypes and the target controller subsystem symbol (default memory_cgrp_subsys).
  3. Attach a cftype (voltron.policy) to that subsystem with cgroup_add_dfl_cftypes(). The files appear in every cgroup where that controller is enabled, and automatically in future cgroups.
  4. Read/write handlers forward to voltron.ko's voltron_policy_show() / voltron_policy_set_kv() — the shared store.
  5. On unload, cgroup_rm_cftypes() removes them.

Link-time symbols are the exported ones (of_css, register_kprobe, seq_printf, and voltron.ko's voltron_policy_*); the sensitive cgroup internals are resolved at runtime via kallsyms.

4Build order

Build voltron.ko first (it provides src/Module.symvers with the exported policy symbols), then this module with KBUILD_EXTRA_SYMBOLS pointing at it — the Makefile/make remote targets do this automatically.

(cd ../src && make) && make KBUILD_EXTRA_SYMBOLS=$(abspath ../src/Module.symvers)

5The file

voltron.policy is one line-oriented file per cgroup:

cat /sys/fs/cgroup/batch.slice/voltron.policy
# cgroup_id 1234
# mode deny
# target 0
# psi_metric cpu
# psi_threshold 0
# min_residency_ms 0
# inherit 1

# write "<key> <value>":
echo "mode auto"        > /sys/fs/cgroup/batch.slice/voltron.policy
echo "psi_metric cpu"   > /sys/fs/cgroup/batch.slice/voltron.policy
echo "psi_threshold 400">/sys/fs/cgroup/batch.slice/voltron.policy
echo "target 2"         > /sys/fs/cgroup/batch.slice/voltron.policy   # manual mode
echo "inherit 1"        > /sys/fs/cgroup/batch.slice/voltron.policy

Keys: mode (deny|auto|manual), target, psi_metric (cpu|memory|io|full), psi_threshold (0..1000 permille), min_residency_ms, inherit (0|1).

6Build & load

cd livepatch
make                      # against ../kernel-src
make KDIR=/lib/modules/$(uname -r)/build   # against the running kernel
make remote               # build on the kernel-build box

sudo insmod voltron_cgroup_lp.ko           # default: attach to memory controller
sudo insmod voltron_cgroup_lp.ko subsys=cpu_cgrp_subsys   # or another controller
dmesg | tail
ls /sys/fs/cgroup/*/voltron.policy
sudo rmmod voltron_cgroup_lp

7Requirements & caveats