RFC bpf, mm: Add a new item bpf into memory.stat for the observability of bpf memory
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest10 patches 2 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/10 | bpf: Introduce new helper bpf_map_put_memcg()kernel/ | +8 | 0 replies | |
| 2/10 | bpf: Define bpf_map_{get,put}_memcg for !CONFIG_MEMCG_KMEMinclude/ include/ kernel/ | +36 | 0 replies | |
| 3/10 | bpf: Call bpf_map_init_from_attr() immediately after map creationkernel/ kernel/ kernel/ | +5 | 0 replies | |
| 4/10 | bpf: Save memcg in bpf_map_init_from_attr()include/ kernel/ kernel/ +15 more | +76 | 0 replies | |
| 5/10 | bpf: Use scoped-based charge in bpf_map_area_allocinclude/ kernel/ kernel/ +15 more | +61 | 0 replies | |
| 6/10 | bpf: Introduce new helpers bpf_ringbuf_pages_{alloc,free}kernel/ | +56 | 0 replies | |
| 7/10 | bpf: Use bpf_map_kzalloc in arraymapkernel/ | +8 | 0 replies | |
| 8/10 | bpf: Use bpf_map_kvcalloc in bpf_local_storageinclude/ kernel/ kernel/ | +25 | 0 replies | |
| 9/10 | bpf: Add bpf map free helpersinclude/ kernel/ kernel/ +9 more | +72 | 0 replies | |
| 10/10 | bpf, memcg: Add new item bpf into memory.statinclude/ include/ include/ +6 more | +107 | 2 replies |
Reviews trailers per patch
1 of 10 patches has a Reviewed-by or Acked-by.
| Patch | Andrii Nakryiko |
|---|---|
| 1/10 | |
| 2/10 | |
| 3/10 | |
| 4/10 | |
| 5/10 | |
| 6/10 | A-b |
| 7/10 | |
| 8/10 | |
| 9/10 | |
| 10/10 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [RFC PATCH bpf-next 00/10] bpf, mm: Add a new item bpf into memory.stat for the observability of bpf memory
This patchset adds a new item 'bpf' into memory.stat to show the bpf memory usage in each memcg (except the root memcg because kmem is not charged into root memcg now). The bpf memory usage is not trivial, so it deserves a new item.
Patches #1 ~ #8 are from another series[1] which try to fix the pinned bpf issues, but it seems to be a long way to go. So let's do the observability first, which has been in my local repo for a long time.
We use the scope-based accouting/unaccouthing to track the bpf memory usage, which is similar with the way how we charge bpf memory.
We have to annotate both allocations and releases of bpf memory because we don't want to add something into struct page currently. The allocations and releases of bpf memory are very clear, so it won't be a trouble.
This patchset only tracks the memory of bpf-map currently.
Future works:
- track the memory of bpf-prog
- observe system-wide bpf memory usage by adding this item into root memcg
- per-map and per-prog bpf memory usage in bpftool or something else
- give user an option to disable memcg-based bpf accouting [2]
Any feedback is welcomed.
[1]. https://lore.kernel.org/bpf/20220902023003.47124-1-laoar.shao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org/
[2]. https://lore.kernel.org/bpf/CALOAHbAOkUpDWaL2kP8ntBe6sj8S0thLmAwZXhG5kFKBunHt_w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org/T/#m3597928c7161b206cb9218c80d9e58a42128d31a
Yafang Shao (10):
bpf: Introduce new helper bpf_map_put_memcg()
bpf: Define bpf_map_{get,put}_memcg for !CONFIG_MEMCG_KMEM
bpf: Call bpf_map_init_from_attr() immediately after map creation
bpf: Save memcg in bpf_map_init_from_attr()
bpf: Use scoped-based charge in bpf_map_area_alloc
bpf: Introduce new helpers bpf_ringbuf_pages_{alloc,free}
bpf: Use bpf_map_kzalloc in arraymap
bpf: Use bpf_map_kvcalloc in bpf_local_storage
bpf: Add bpf map free helpers
bpf, memcg: Add new item bpf into memory.stat
include/linux/bpf.h | 70 ++++++++++++++++++- include/linux/memcontrol.h | 11 +++ include/linux/sched.h | 1 + include/linux/sched/mm.h | 24 +++++++ kernel/bpf/arraymap.c | 30 ++++----- kernel/bpf/bloom_filter.c | 4 +- kernel/bpf/bpf_local_storage.c | 20 +++--- kernel/bpf/bpf_struct_ops.c | 14 ++-- kernel/bpf/cpumap.c | 24 +++---- kernel/bpf/devmap.c | 36 +++++----- kernel/bpf/hashtab.c | 24 ++++--- kernel/bpf/helpers.c | 2 +- kernel/bpf/local_storage.c | 14 ++-- kernel/bpf/lpm_trie.c | 6 +- kernel/bpf/memalloc.c | 10 +++ kernel/bpf/offload.c | 6 +- kernel/bpf/queue_stack_maps.c | 4 +- kernel/bpf/reuseport_array.c | 4 +- kernel/bpf/ringbuf.c | 106 ++++++++++++++++++++--------- kernel/bpf/stackmap.c | 13 ++-- kernel/bpf/syscall.c | 149 ++++++++++++++++++++++++++++++----------- kernel/fork.c | 1 + mm/memcontrol.c | 20 ++++++ net/core/sock_map.c | 22 +++--- net/xdp/xskmap.c | 6 +- 25 files changed, 439 insertions(+), 182 deletions(-)
Signature · 1 line
1.8.3.1