block: expose blkcg io.stat to BPF - #8659
Open
kernel-patches-daemon-bpf-rc[bot] wants to merge 2 commits into
Open
block: expose blkcg io.stat to BPF#8659kernel-patches-daemon-bpf-rc[bot] wants to merge 2 commits into
kernel-patches-daemon-bpf-rc[bot] wants to merge 2 commits into
Conversation
Author
|
Upstream branch: 2b1f9f6 |
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
bpf-next_base
branch
from
August 7, 2026 21:09
dd2acb0 to
75f1c0e
Compare
Author
|
Upstream branch: e1d9b82 |
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
series/1142393=>bpf-next
branch
from
August 7, 2026 21:17
eac7499 to
2268b3c
Compare
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
bpf-next_base
branch
from
August 7, 2026 22:48
75f1c0e to
f776207
Compare
Author
|
Upstream branch: 51476f6 |
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
series/1142393=>bpf-next
branch
from
August 7, 2026 22:53
2268b3c to
1b5c205
Compare
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
bpf-next_base
branch
from
August 8, 2026 10:01
f776207 to
b882df0
Compare
Author
|
Upstream branch: 8b365b3 |
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
series/1142393=>bpf-next
branch
from
August 8, 2026 10:06
1b5c205 to
4baaf13
Compare
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
bpf-next_base
branch
from
August 8, 2026 10:13
b882df0 to
818432c
Compare
Author
|
Upstream branch: d114bb9 |
added 2 commits
August 8, 2026 03:18
Expose the block I/O controller's per-device statistics to BPF, mirroring the memory controller kfuncs in mm/bpf_memcontrol.c. A BPF program gets a blkcg from a cgroup's css with bpf_get_blkcg() (or bpf_get_root_blkcg() for the root), flushes the stats with bpf_blkcg_flush_stats(), then walks the cgroup's per-device blkgs with the bpf_iter_blkg open-coded iterator and reads each device's counters with bpf_blkg_iostat_bytes() and bpf_blkg_iostat_ios(). bpf_blkg_dev() returns the device id for labelling. The reference is released with bpf_put_blkcg(). Unlike the memory controller, blkcg keeps one blkg (and one io.stat line) per block device, so the reader kfuncs take a blkg and the iterator yields them under RCU. The counters are read under the same u64_stats seqlock the io.stat file uses, so the kfuncs add no fast-path cost: accounting stays in the per-cpu blkg iostat and is only folded on flush. bpf_blkcg_flush_stats() branches the way blkcg_print_stat() does. A non-root cgroup is flushed through rstat. The root cgroup is not accounted through rstat at all - blkcg_rstat_flush() returns early for it and __blkcg_rstat_flush() stops propagating one level short - so its per-device aggregates are refilled from the disks' own statistics instead, by blkcg_fill_root_iostats(), which is no longer static for that reason. Without this a program reading the root cgroup would see zeroes. Those numbers cover every cgroup's I/O, exactly as the root io.stat file reports them. Two details are worth calling out: bpf_iter_blkg_next() forgets the list head once the walk ends, not just the position. process_iter_next_call() in the verifier requires an iterator to keep returning NULL once it has returned it, and stops checking the loop for termination at that point; restarting the walk would let such a loop spin forever. The counter readers give up instead of retrying when called from NMI on 32-bit. There the u64_stats read is a real seqcount loop, every writer of blkg->iostat keeps interrupts off, and a perf event program can call these kfuncs from NMI, where the loop would never end. On 64-bit the loop compiles away. Signed-off-by: Ziyang Men <ziyang.meme@gmail.com>
Add cgroup_iter_io, a test_progs test for the block I/O controller BPF
kfuncs. A SEC("iter.s/cgroup") program acquires the cgroup's blkcg,
flushes stats, iterates its blkgs and reads the io.stat counters for a
target device.
The userspace side attaches a loop device, generates O_DIRECT read and
write I/O charged to a test cgroup, and then:
- checks the write and read byte/io counters are nonzero,
- checks the reported device id,
- compares every kfunc-read value against the cgroup's io.stat file
for the same device and requires an exact match,
- reads the same device through bpf_get_root_blkcg() and checks the
root counters are at or above the test cgroup's.
The measured device is pinned to the loop device, which has no
asynchronous writeback, so the kfunc snapshot and the io.stat file
snapshot are identical rather than merely close. The root cgroup's
numbers for a device come from the disk itself and so cover every
cgroup's I/O to it, which is why the root check is "at or above" rather
than an exact match.
CONFIG_BLK_CGROUP is added to the test config; CONFIG_BLK_DEV_LOOP is
already present.
Signed-off-by: Ziyang Men <ziyang.meme@gmail.com>
kernel-patches-daemon-bpf-rc
Bot
force-pushed
the
series/1142393=>bpf-next
branch
from
August 8, 2026 10:18
4baaf13 to
50e42c7
Compare
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: block: expose blkcg io.stat to BPF
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1142393