cgroup: expose cpu.stat and io.stat to BPF - #1165
Open
blktests-ci[bot] wants to merge 4 commits into
Open
Conversation
Collecting cgroup statistics is expensive because the existing method opens and parses a cgroup file. memcg already provides an efficient BPF interface; extend that model to the CPU controller. Register css_rstat_flush() as a common kfunc and add bpf_cgroup_base_stat(). The latter returns cgroup_base_stat after the same cputime adjustment used by cpu.stat. The BPF program reads the plain CFS bandwidth counters directly. Add bpf_css_to_task_group() to check the controller and give the verifier a typed task_group pointer for bpf_per_cpu_ptr(). css_rstat_flush() may reschedule and requires a sleepable program. bpf_cgroup_base_stat() only takes locks and is not marked sleepable, but those locks are not NMI-safe. Suggested-by: Shakeel Butt <shakeel.butt@linux.dev> Suggested-by: Tejun Heo <tj@kernel.org> Assisted-by: Claude:claude-opus-5 Signed-off-by: Ziyang Men <ziyang.meme@gmail.com>
Add cgroup_iter_cpu, a selftest for the CPU controller BPF kfuncs.
The userspace side runs a CPU hog in a test cgroup with cpu.max settled
then:
- checks the CPU-time and throttling counters are nonzero,
- compares whether all values the program read are same as those
reading from cgroup file.
Enable CONFIG_CGROUP_SCHED, CONFIG_FAIR_GROUP_SCHED and
CONFIG_CFS_BANDWIDTH in the selftest config.
Tested on VM with v7.2-rc5.
Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
Assisted-by: Claude:claude-opus-5
Signed-off-by: Ziyang Men <ziyang.meme@gmail.com>
Collecting cgroup statistics is expensive because the existing method opens and parses a cgroup file for every cgroup. memcg already provides an efficient BPF interface; extend that model to the block controller. Add bpf_cgroup_css() and bpf_css_release() to acquire a controller's css from a cgroup. The reference keeps the css alive across the sleepable css_rstat_flush(). Add bpf_css_to_blkcg() as a checked RCU-protected css-to-blkcg conversion and an open-coded iterator for the per-device blkgs. Suggested-by: Shakeel Butt <shakeel.butt@linux.dev> Suggested-by: Tejun Heo <tj@kernel.org> Assisted-by: Claude:claude-opus-5 Signed-off-by: Ziyang Men <ziyang.meme@gmail.com>
Add cgroup_iter_io to test the blkcg io.stat BPF kfuncs. The BPF program acquires the I/O css, flushes its statistics, converts it to a typed blkcg under RCU, walks the blkgs, and releases the css reference. The test performs O_DIRECT I/O on a private loop device. It checks the device ID and counters against io.stat. Assisted-by: Claude:claude-opus-5 Signed-off-by: Ziyang Men <ziyang.meme@gmail.com>
Author
|
Upstream branch: bd5f485 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request for series with
subject: cgroup: expose cpu.stat and io.stat to BPF
version: 3
url: https://patchwork.kernel.org/project/linux-block/list/?series=1149340