bpf: Include verifier memory allocations in memcg statistics
authorEduard Zingerman <eddyz87@gmail.com>
Fri, 13 Jun 2025 07:21:46 +0000 (00:21 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 13 Jun 2025 17:29:45 +0000 (10:29 -0700)
commit43736ec3e02789795d4e7b9cb49a005fa56c0171
tree82aab2860f31fe6f42ff0cbd93d89af3854cd8a5
parentccefa19335a0b81f11b0856e951ca909445b3783
bpf: Include verifier memory allocations in memcg statistics

This commit adds __GFP_ACCOUNT flag to verifier induced memory
allocations. The intent is to account for all allocations reachable
from BPF_PROG_LOAD command, which is needed to track verifier memory
consumption in veristat. This includes allocations done in verifier.c,
and some allocations in btf.c, functions in log.c do not allocate.

There is also a utility function bpf_memcg_flags() which selectively
adds GFP_ACCOUNT flag depending on the `cgroup.memory=nobpf` option.
As far as I understand [1], the idea is to remove bpf_prog instances
and maps from memcg accounting as these objects do not strictly belong
to cgroup, hence it should not apply here.

(btf_parse_fields() is reachable from both program load and map
 creation, but allocated record is not persistent as is freed as soon
 as map_check_btf() exits).

[1] https://lore.kernel.org/all/20230210154734.4416-1-laoar.shao@gmail.com/

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250613072147.3938139-2-eddyz87@gmail.com
kernel/bpf/btf.c
kernel/bpf/verifier.c