Skip to content

block: expose blkcg io.stat to BPF

Ziyang Men bpf cgroups linux-block linux-kselftest lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 8 repliesIn review
  2. v12 patches 6 repliesSuperseded

Changes in v2 from the cover letter

- Drop the blkcg acquire/release helpers. The program reads the io controller's css from cgroup->subsys[] under RCU instead.
- Remove the kfuncs that read the blkg device ID and counters; BPF programs can read those fields with BPF_CORE_READ().
- Keep the flush sleepable. It now takes a struct cgroup * and pins its CSS internally.
- Make the blkg iterator take an RCU-protected CSS.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2block: add BPF kfuncs to read blkcg io.statMAINTAINERS block/Makefile block/blk-cgroup.c +2 more+160 -18 replies
2/2selftests/bpf: add test for blkcg io.stat BPF kfuncstools/testing/selftests/bpf/cgroup_iter_io.h tools/testing/selftests/bpf/config tools/testing/selftests/bpf/prog_tests/cgroup_iter_io.c +1 more+394 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] block: expose blkcg io.stat to BPF

Collecting cgroup statistics is expensive: the existing method is to open and parse a cgroup file for every cgroup of interest. The memory controller already has an efficient alternative through BPF; this series extends that model to the block I/O controller's per-device io.stat.

Patch 1 adds the blkcg flush and per-device iterator.

Patch 2 adds a selftest that performs direct I/O on a private loop device and compares every counter read by BPF with io.stat.

===
Changes since v1.

- Drop the blkcg acquire/release helpers. The program reads the io controller's css from cgroup->subsys[] under RCU instead.
- Remove the kfuncs that read the blkg device ID and counters; BPF programs can read those fields with BPF_CORE_READ().
- Keep the flush sleepable. It now takes a struct cgroup * and pins its CSS internally.
- Make the blkg iterator take an RCU-protected CSS.

Tested on VM with v7.2-rc5.

Ziyang Men (2):
block: add BPF kfuncs to read blkcg io.stat selftests/bpf: add test for blkcg io.stat BPF kfuncs

 MAINTAINERS                                   |   1 +
 block/Makefile                                |   3 +
 block/blk-cgroup.c                            |   2 +-
 block/blk-cgroup.h                            |   1 +
 block/bpf_blkcg.c                             | 154 ++++++++++
 tools/testing/selftests/bpf/cgroup_iter_io.h  |  17 ++
 tools/testing/selftests/bpf/config            |   1 +
 .../selftests/bpf/prog_tests/cgroup_iter_io.c | 277 ++++++++++++++++++
 .../selftests/bpf/progs/cgroup_iter_io.c      |  99 +++++++
 9 files changed, 554 insertions(+), 1 deletion(-)
 create mode 100644 block/bpf_blkcg.c
 create mode 100644 tools/testing/selftests/bpf/cgroup_iter_io.h
 create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_iter_io.c
 create mode 100644 tools/testing/selftests/bpf/progs/cgroup_iter_io.c
Signature · 1 line
2.53.0-Meta