mm: bpf kfuncs to access memcg data
Subsystems (6)
Roman Gushchin
maintainerv4 cover mm: bpf kfuncs to access memcg data
Introduce kfuncs to simplify the access to the memcg data. These kfuncs can be used to accelerate monitoring use cases and for implementing custom OOM policies once BPF OOM is landed.
This patchset was separated out from the BPF OOM patchset to simplify the logistics and accelerate the landing of the part which is useful by itself. No functional changes since BPF OOM v2.
v4:
- refactored memcg vm event and stat item idx checks (by Alexei)
v3:
- dropped redundant kfuncs flags (by Alexei)
- fixed kdocs warnings (by Alexei)
- merged memcg stats access patches into one (by Alexei)
- restored root memcg usage reporting, added a comment
- added checks for enum boundaries
- added Shakeel and JP as co-maintainers (by Shakeel)
v2:
- added mem_cgroup_disabled() checks (by Shakeel B.)
- added special handling of the root memcg in bpf_mem_cgroup_usage() (by Shakeel B.)
- minor fixes in the kselftest (by Shakeel B.)
- added a MAINTAINERS entry (by Shakeel B.)
v1:
https://lore.kernel.org/bpf/[email protected]/T/#t
JP Kobryn (1):
bpf: selftests: selftests for memcg stat kfuncs
Roman Gushchin (5):
mm: declare memcg_page_state_output() in memcontrol.h
mm: introduce BPF kfuncs to deal with memcg pointers
mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
mm: introduce BPF kfuncs to access memcg statistics and events
MAINTAINERS: add an entry for MM BPF extensions
MAINTAINERS | 9 + include/linux/memcontrol.h | 20 ++ mm/Makefile | 3 + mm/bpf_memcontrol.c | 193 +++++++++++++++ mm/memcontrol-v1.h | 1 - mm/memcontrol.c | 16 ++ .../testing/selftests/bpf/cgroup_iter_memcg.h | 18 ++ .../bpf/prog_tests/cgroup_iter_memcg.c | 223 ++++++++++++++++++ .../selftests/bpf/progs/cgroup_iter_memcg.c | 39 +++ 9 files changed, 521 insertions(+), 1 deletion(-) create mode 100644 mm/bpf_memcontrol.c create mode 100644 tools/testing/selftests/bpf/cgroup_iter_memcg.h create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c create mode 100644 tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c
Signature · 1 line
2.52.0
Roman Gushchin
maintainerPATCH v4 1/6 mm: declare memcg_page_state_output() in memcontrol.h
To use memcg_page_state_output() in bpf_memcontrol.c move the declaration from v1-specific memcontrol-v1.h to memcontrol.h.
--- include/linux/memcontrol.h | 6 ++++++ mm/memcontrol-v1.h | 1 - 2 files changed, 6 insertions(+), 1 deletion(-)
include/linux/memcontrol.h +6 -0
@@ -950,6 +950,7 @@ static inline void mod_memcg_page_state(struct page *page, }unsigned long memcg_page_state (struct mem_cgroup *memcg,int idx); +unsigned long memcg_page_state_output (struct mem_cgroup *memcg,int item);unsigned long lruvec_page_state (struct lruvec *lruvec,enum node_stat_item idx);unsigned long lruvec_page_state_local (struct lruvec *lruvec,enum node_stat_item idx);
@@ -1373,6 +1374,11 @@ static inline unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx)return 0 ; } +static inline unsigned long memcg_page_state_output (struct mem_cgroup *memcg,int item) +{ +return 0 ; +} +static inline unsigned long lruvec_page_state (struct lruvec *lruvec,enum node_stat_item idx) {
mm/memcontrol-v1.h +0 -1
@@ -27,7 +27,6 @@ unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap);void drain_all_stock (struct mem_cgroup *root_memcg);unsigned long memcg_events (struct mem_cgroup *memcg,int event); -unsigned long memcg_page_state_output (struct mem_cgroup *memcg,int item);int memory_stat_show (struct seq_file *m,void *v);void mem_cgroup_id_get_many (struct mem_cgroup *memcg,unsigned int n);
Signature · 1 line
2.52.0
Roman Gushchin
maintainerPATCH v4 2/6 mm: introduce BPF kfuncs to deal with memcg pointers
In reply to Roman GushchinTo effectively operate with memory cgroups in BPF there is a need to convert css pointers to memcg pointers. A simple container_of cast which is used in the kernel code can't be used in BPF because from the verifier's point of view that's a out-of-bounds memory access.
Introduce helper get/put kfuncs which can be used to get a refcounted memcg pointer from the css pointer:
- bpf_get_mem_cgroup,
- bpf_put_mem_cgroup.
bpf_get_mem_cgroup() can take both memcg's css and the corresponding cgroup's "self" css. It allows it to be used with the existing cgroup iterator which iterates over cgroup tree, not memcg tree.
--- mm/Makefile | 3 ++ mm/bpf_memcontrol.c | 88 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 mm/bpf_memcontrol.c
mm/Makefile +3 -0
@@ -106,6 +106,9 @@ obj-$(CONFIG_MEMCG) += memcontrol.o vmpressure.o ifdef CONFIG_SWAP obj-$(CONFIG_MEMCG) += swap_cgroup.o endif +ifdef CONFIG_BPF_SYSCALL +obj-$(CONFIG_MEMCG) += bpf_memcontrol.o +endif obj-$(CONFIG_CGROUP_HUGETLB) += hugetlb_cgroup.o obj-$(CONFIG_GUP_TEST) += gup_test.o obj-$(CONFIG_DMAPOOL_TEST) += dmapool_test.o
mm/bpf_memcontrol.c new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.52.0
Roman Gushchin
maintainerPATCH v4 3/6 mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
In reply to Roman GushchinIntroduce a BPF kfunc to get a trusted pointer to the root memory cgroup. It's very handy to traverse the full memcg tree, e.g. for handling a system-wide OOM.
It's possible to obtain this pointer by traversing the memcg tree up from any known memcg, but it's sub-optimal and makes BPF programs more complex and less efficient.
bpf_get_root_mem_cgroup() has a KF_ACQUIRE | KF_RET_NULL semantics, however in reality it's not necessary to bump the corresponding reference counter - root memory cgroup is immortal, reference counting is skipped, see css_get(). Once set, root_mem_cgroup is always a valid memcg pointer. It's safe to call bpf_put_mem_cgroup() for the pointer obtained with bpf_get_root_mem_cgroup(), it's effectively a no-op.
--- mm/bpf_memcontrol.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
mm/bpf_memcontrol.c +20 -0
@@ -10,6 +10,25 @@__bpf_kfunc_start_defs (); +/** +* bpf_get_root_mem_cgroup - Returns a pointer to the root memory cgroup +* +* The function has KF_ACQUIRE semantics, even though the root memory +* cgroup is never destroyed after being created and doesn't require +* reference counting. And it's perfectly safe to pass it to +* bpf_put_mem_cgroup() +* +* Return: A pointer to the root memory cgroup. +*/ +__bpf_kfunc struct mem_cgroup *bpf_get_root_mem_cgroup(void) +{ +if (mem_cgroup_disabled ()) +return NULL ; + +/* css_get() is not needed */ +return root_mem_cgroup; +} +/** * bpf_get_mem_cgroup - Get a reference to a memory cgroup * @css: pointer to the css structure
@@ -64,6 +83,7 @@ __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg)__bpf_kfunc_end_defs (); BTF_KFUNCS_START(bpf_memcontrol_kfuncs) +BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_ACQUIRE | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_get_mem_cgroup, KF_ACQUIRE | KF_RET_NULL | KF_RCU) BTF_ID_FLAGS(func, bpf_put_mem_cgroup, KF_RELEASE)
Signature · 1 line
2.52.0
Re: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
Quoted 51 lines · Roman Gushchin
Introduce a BPF kfunc to get a trusted pointer to the root memory cgroup. It's very handy to traverse the full memcg tree, e.g. for handling a system-wide OOM.
It's possible to obtain this pointer by traversing the memcg tree up from any known memcg, but it's sub-optimal and makes BPF programs more complex and less efficient.
bpf_get_root_mem_cgroup()has aKF_ACQUIRE|KF_RET_NULLsemantics, however in reality it's not necessary to bump the corresponding reference counter - root memory cgroup is immortal, reference counting is skipped, seecss_get(). Once set,root_mem_cgroupis always a valid memcg pointer. It's safe to callbpf_put_mem_cgroup()for the pointer obtained withbpf_get_root_mem_cgroup(), it's effectively a no-op.Signed-off-by Roman Gushchin <[email protected]>--- mm/bpf_memcontrol.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)mm/bpf_memcontrol.c +19
-0@@ -10,6 +10,25 @@__bpf_kfunc_start_defs (); +/** +* bpf_get_root_mem_cgroup - Returns a pointer to the root memory cgroup +* +* The function has KF_ACQUIRE semantics, even though the root memory +* cgroup is never destroyed after being created and doesn't require +* reference counting. And it's perfectly safe to pass it to +* bpf_put_mem_cgroup() +* +* Return: A pointer to the root memory cgroup. +*/ +__bpf_kfunc struct mem_cgroup *bpf_get_root_mem_cgroup(void) +{ +if (mem_cgroup_disabled ()) +return NULL ; + +/* css_get() is not needed */ +return root_mem_cgroup; +} +/** * bpf_get_mem_cgroup - Get a reference to a memory cgroup * @css: pointer to the css structure
mm/bpf_memcontrol.c __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg) · line 86
Quoted 4 lines
mm/bpf_memcontrol.c +1
-0@@ -64,6 +83,7 @@ __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg)__bpf_kfunc_end_defs ();BTF_KFUNCS_START (bpf_memcontrol_kfuncs) +BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_ACQUIRE | KF_RET_NULL)
I feel as though relying on KF_ACQUIRE semantics here is somewhat odd. Users of this BPF kfunc will now be forced to call bpf_put_mem_cgroup() on the returned root_mem_cgroup, despite it being completely unnecessary.
Perhaps we should consider introducing a new KF bit/value which essentially allows such BPF kfuncs to also have their returned pointers implicitly marked as "trusted", similar to that of the legacy RET_PTR_TO_BTF_ID_TRUSTED. What do you think? That way it obviates the requirement to call into any backing KF_RELEASE BPF kfunc after the fact.
Roman Gushchin
maintainerRe: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
Quoted 54 lines · Matt Bobrowski
Quoted 53 lines · Roman Gushchin
Introduce a BPF kfunc to get a trusted pointer to the root memory cgroup. It's very handy to traverse the full memcg tree, e.g. for handling a system-wide OOM.
It's possible to obtain this pointer by traversing the memcg tree up from any known memcg, but it's sub-optimal and makes BPF programs more complex and less efficient.
bpf_get_root_mem_cgroup()has aKF_ACQUIRE|KF_RET_NULLsemantics, however in reality it's not necessary to bump the corresponding reference counter - root memory cgroup is immortal, reference counting is skipped, seecss_get(). Once set,root_mem_cgroupis always a valid memcg pointer. It's safe to callbpf_put_mem_cgroup()for the pointer obtained withbpf_get_root_mem_cgroup(), it's effectively a no-op.Signed-off-by Roman Gushchin <[email protected]>--- mm/bpf_memcontrol.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)mm/bpf_memcontrol.c +19
-0@@ -10,6 +10,25 @@__bpf_kfunc_start_defs (); +/** +* bpf_get_root_mem_cgroup - Returns a pointer to the root memory cgroup +* +* The function has KF_ACQUIRE semantics, even though the root memory +* cgroup is never destroyed after being created and doesn't require +* reference counting. And it's perfectly safe to pass it to +* bpf_put_mem_cgroup() +* +* Return: A pointer to the root memory cgroup. +*/ +__bpf_kfunc struct mem_cgroup *bpf_get_root_mem_cgroup(void) +{ +if (mem_cgroup_disabled ()) +return NULL ; + +/* css_get() is not needed */ +return root_mem_cgroup; +} +/** * bpf_get_mem_cgroup - Get a reference to a memory cgroup * @css: pointer to the css structure @@ -64,6 +83,7 @@ __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg)__bpf_kfunc_end_defs ();
Quoted 7 lines
mm/bpf_memcontrol.c __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg) · line 86
Quoted 2 lines
mm/bpf_memcontrol.c +1
-0BTF_KFUNCS_START (bpf_memcontrol_kfuncs) +BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_ACQUIRE | KF_RET_NULL)I feel as though relying on
KF_ACQUIREsemantics here is somewhat odd. Users of this BPF kfunc will now be forced to callbpf_put_mem_cgroup()on the returnedroot_mem_cgroup, despite it being completely unnecessary.
A agree that it's annoying, but I doubt this extra call makes any difference in the real world.
Also, the corresponding kernel code designed to hide the special handling of the root cgroup. css_get()/css_put() are simple no-ops for the root cgroup, but are totally valid. So in most places the root cgroup is handled as any other, which simplifies the code. I guess the same will be true for many bpf programs.
Thanks!
Re: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
Quoted 64 lines · Roman Gushchin
Quoted 54 lines · Matt Bobrowski
Quoted 53 lines · Roman Gushchin
Introduce a BPF kfunc to get a trusted pointer to the root memory cgroup. It's very handy to traverse the full memcg tree, e.g. for handling a system-wide OOM.
It's possible to obtain this pointer by traversing the memcg tree up from any known memcg, but it's sub-optimal and makes BPF programs more complex and less efficient.
bpf_get_root_mem_cgroup()has aKF_ACQUIRE|KF_RET_NULLsemantics, however in reality it's not necessary to bump the corresponding reference counter - root memory cgroup is immortal, reference counting is skipped, seecss_get(). Once set,root_mem_cgroupis always a valid memcg pointer. It's safe to callbpf_put_mem_cgroup()for the pointer obtained withbpf_get_root_mem_cgroup(), it's effectively a no-op.Signed-off-by Roman Gushchin <[email protected]>--- mm/bpf_memcontrol.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)mm/bpf_memcontrol.c +19
-0@@ -10,6 +10,25 @@__bpf_kfunc_start_defs (); +/** +* bpf_get_root_mem_cgroup - Returns a pointer to the root memory cgroup +* +* The function has KF_ACQUIRE semantics, even though the root memory +* cgroup is never destroyed after being created and doesn't require +* reference counting. And it's perfectly safe to pass it to +* bpf_put_mem_cgroup() +* +* Return: A pointer to the root memory cgroup. +*/ +__bpf_kfunc struct mem_cgroup *bpf_get_root_mem_cgroup(void) +{ +if (mem_cgroup_disabled ()) +return NULL ; + +/* css_get() is not needed */ +return root_mem_cgroup; +} +/** * bpf_get_mem_cgroup - Get a reference to a memory cgroup * @css: pointer to the css structure @@ -64,6 +83,7 @@ __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg)__bpf_kfunc_end_defs ();Quoted 7 lines
mm/bpf_memcontrol.c __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg) · line 86
Quoted 2 lines
mm/bpf_memcontrol.c +1
-0BTF_KFUNCS_START (bpf_memcontrol_kfuncs) +BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_ACQUIRE | KF_RET_NULL)I feel as though relying on
KF_ACQUIREsemantics here is somewhat odd. Users of this BPF kfunc will now be forced to callbpf_put_mem_cgroup()on the returnedroot_mem_cgroup, despite it being completely unnecessary.
Quoted 2 lines
A agree that it's annoying, but I doubt this extra call makes any difference in the real world.
Sure, that certainly holds true.
Quoted 3 lines
Also, the corresponding kernel code designed to hide the special handling of the root cgroup. css_get()/css_put() are simple no-ops for the root cgroup, but are totally valid.
Yes, I do see that.
Quoted 3 lines
So in most places the root cgroup is handled as any other, which simplifies the code. I guess the same will be true for many bpf programs.
I see, however the same might not necessarily hold for all other global pointers which end up being handed out by a BPF kfunc (not necessarily bpf_get_root_mem_cgroup()). This is why I was wondering whether there's some sense to introducing another KF flag (or something similar) which allows returned values from BPF kfuncs to be implicitly treated as trusted.
Roman Gushchin
maintainerRe: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
Quoted 80 lines · Matt Bobrowski
Quoted 64 lines · Roman Gushchin
Quoted 54 lines · Matt Bobrowski
Quoted 53 lines · Roman Gushchin
Introduce a BPF kfunc to get a trusted pointer to the root memory cgroup. It's very handy to traverse the full memcg tree, e.g. for handling a system-wide OOM.
It's possible to obtain this pointer by traversing the memcg tree up from any known memcg, but it's sub-optimal and makes BPF programs more complex and less efficient.
bpf_get_root_mem_cgroup()has aKF_ACQUIRE|KF_RET_NULLsemantics, however in reality it's not necessary to bump the corresponding reference counter - root memory cgroup is immortal, reference counting is skipped, seecss_get(). Once set,root_mem_cgroupis always a valid memcg pointer. It's safe to callbpf_put_mem_cgroup()for the pointer obtained withbpf_get_root_mem_cgroup(), it's effectively a no-op.Signed-off-by Roman Gushchin <[email protected]>--- mm/bpf_memcontrol.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)mm/bpf_memcontrol.c +19
-0@@ -10,6 +10,25 @@__bpf_kfunc_start_defs (); +/** +* bpf_get_root_mem_cgroup - Returns a pointer to the root memory cgroup +* +* The function has KF_ACQUIRE semantics, even though the root memory +* cgroup is never destroyed after being created and doesn't require +* reference counting. And it's perfectly safe to pass it to +* bpf_put_mem_cgroup() +* +* Return: A pointer to the root memory cgroup. +*/ +__bpf_kfunc struct mem_cgroup *bpf_get_root_mem_cgroup(void) +{ +if (mem_cgroup_disabled ()) +return NULL ; + +/* css_get() is not needed */ +return root_mem_cgroup; +} +/** * bpf_get_mem_cgroup - Get a reference to a memory cgroup * @css: pointer to the css structure @@ -64,6 +83,7 @@ __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg)__bpf_kfunc_end_defs ();Quoted 7 lines
mm/bpf_memcontrol.c __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg) · line 86
Quoted 2 lines
mm/bpf_memcontrol.c +1
-0BTF_KFUNCS_START (bpf_memcontrol_kfuncs) +BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_ACQUIRE | KF_RET_NULL)I feel as though relying on
KF_ACQUIREsemantics here is somewhat odd. Users of this BPF kfunc will now be forced to callbpf_put_mem_cgroup()on the returnedroot_mem_cgroup, despite it being completely unnecessary.Quoted 2 lines
A agree that it's annoying, but I doubt this extra call makes any difference in the real world.
Sure, that certainly holds true.
Quoted 3 lines
Also, the corresponding kernel code designed to hide the special handling of the root cgroup. css_get()/css_put() are simple no-ops for the root cgroup, but are totally valid.
Yes, I do see that.
Quoted 3 lines
So in most places the root cgroup is handled as any other, which simplifies the code. I guess the same will be true for many bpf programs.
Quoted 6 lines
I see, however the same might not necessarily hold for all other global pointers which end up being handed out by a BPF kfunc (not necessarily
bpf_get_root_mem_cgroup()). This is why I was wondering whether there's some sense to introducing another KF flag (or something similar) which allows returned values from BPF kfuncs to be implicitly treated as trusted.
Agree. It sounds like a good idea to me.
Re: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
In reply to Matt BobrowskiQuoted 81 lines · Matt Bobrowski
Quoted 64 lines · Roman Gushchin
Quoted 54 lines · Matt Bobrowski
Quoted 53 lines · Roman Gushchin
Introduce a BPF kfunc to get a trusted pointer to the root memory cgroup. It's very handy to traverse the full memcg tree, e.g. for handling a system-wide OOM.
It's possible to obtain this pointer by traversing the memcg tree up from any known memcg, but it's sub-optimal and makes BPF programs more complex and less efficient.
bpf_get_root_mem_cgroup()has aKF_ACQUIRE|KF_RET_NULLsemantics, however in reality it's not necessary to bump the corresponding reference counter - root memory cgroup is immortal, reference counting is skipped, seecss_get(). Once set,root_mem_cgroupis always a valid memcg pointer. It's safe to callbpf_put_mem_cgroup()for the pointer obtained withbpf_get_root_mem_cgroup(), it's effectively a no-op.Signed-off-by Roman Gushchin <[email protected]>--- mm/bpf_memcontrol.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)mm/bpf_memcontrol.c +19
-0@@ -10,6 +10,25 @@__bpf_kfunc_start_defs (); +/** +* bpf_get_root_mem_cgroup - Returns a pointer to the root memory cgroup +* +* The function has KF_ACQUIRE semantics, even though the root memory +* cgroup is never destroyed after being created and doesn't require +* reference counting. And it's perfectly safe to pass it to +* bpf_put_mem_cgroup() +* +* Return: A pointer to the root memory cgroup. +*/ +__bpf_kfunc struct mem_cgroup *bpf_get_root_mem_cgroup(void) +{ +if (mem_cgroup_disabled ()) +return NULL ; + +/* css_get() is not needed */ +return root_mem_cgroup; +} +/** * bpf_get_mem_cgroup - Get a reference to a memory cgroup * @css: pointer to the css structure @@ -64,6 +83,7 @@ __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg)__bpf_kfunc_end_defs ();Quoted 7 lines
mm/bpf_memcontrol.c __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg) · line 86
Quoted 2 lines
mm/bpf_memcontrol.c +1
-0BTF_KFUNCS_START (bpf_memcontrol_kfuncs) +BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_ACQUIRE | KF_RET_NULL)I feel as though relying on
KF_ACQUIREsemantics here is somewhat odd. Users of this BPF kfunc will now be forced to callbpf_put_mem_cgroup()on the returnedroot_mem_cgroup, despite it being completely unnecessary.Quoted 2 lines
A agree that it's annoying, but I doubt this extra call makes any difference in the real world.
Sure, that certainly holds true.
Quoted 3 lines
Also, the corresponding kernel code designed to hide the special handling of the root cgroup. css_get()/css_put() are simple no-ops for the root cgroup, but are totally valid.
Yes, I do see that.
Quoted 3 lines
So in most places the root cgroup is handled as any other, which simplifies the code. I guess the same will be true for many bpf programs.
Quoted 6 lines
I see, however the same might not necessarily hold for all other global pointers which end up being handed out by a BPF kfunc (not necessarily
bpf_get_root_mem_cgroup()). This is why I was wondering whether there's some sense to introducing another KF flag (or something similar) which allows returned values from BPF kfuncs to be implicitly treated as trusted.
No need for a new KF flag. Any struct returned by kfunc should be trusted or trusted_or_null if KF_RET_NULL was specified. I don't remember off the top of my head, but this behavior is already implemented or we discussed making it this way.
Re: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
Quoted 90 lines · Alexei Starovoitov
Quoted 81 lines · Matt Bobrowski
Quoted 64 lines · Roman Gushchin
Quoted 54 lines · Matt Bobrowski
Quoted 53 lines · Roman Gushchin
Introduce a BPF kfunc to get a trusted pointer to the root memory cgroup. It's very handy to traverse the full memcg tree, e.g. for handling a system-wide OOM.
It's possible to obtain this pointer by traversing the memcg tree up from any known memcg, but it's sub-optimal and makes BPF programs more complex and less efficient.
bpf_get_root_mem_cgroup()has aKF_ACQUIRE|KF_RET_NULLsemantics, however in reality it's not necessary to bump the corresponding reference counter - root memory cgroup is immortal, reference counting is skipped, seecss_get(). Once set,root_mem_cgroupis always a valid memcg pointer. It's safe to callbpf_put_mem_cgroup()for the pointer obtained withbpf_get_root_mem_cgroup(), it's effectively a no-op.Signed-off-by Roman Gushchin <[email protected]>--- mm/bpf_memcontrol.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)mm/bpf_memcontrol.c +19
-0@@ -10,6 +10,25 @@__bpf_kfunc_start_defs (); +/** +* bpf_get_root_mem_cgroup - Returns a pointer to the root memory cgroup +* +* The function has KF_ACQUIRE semantics, even though the root memory +* cgroup is never destroyed after being created and doesn't require +* reference counting. And it's perfectly safe to pass it to +* bpf_put_mem_cgroup() +* +* Return: A pointer to the root memory cgroup. +*/ +__bpf_kfunc struct mem_cgroup *bpf_get_root_mem_cgroup(void) +{ +if (mem_cgroup_disabled ()) +return NULL ; + +/* css_get() is not needed */ +return root_mem_cgroup; +} +/** * bpf_get_mem_cgroup - Get a reference to a memory cgroup * @css: pointer to the css structure @@ -64,6 +83,7 @@ __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg)__bpf_kfunc_end_defs ();Quoted 7 lines
mm/bpf_memcontrol.c __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg) · line 86
Quoted 2 lines
mm/bpf_memcontrol.c +1
-0BTF_KFUNCS_START (bpf_memcontrol_kfuncs) +BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_ACQUIRE | KF_RET_NULL)I feel as though relying on
KF_ACQUIREsemantics here is somewhat odd. Users of this BPF kfunc will now be forced to callbpf_put_mem_cgroup()on the returnedroot_mem_cgroup, despite it being completely unnecessary.Quoted 2 lines
A agree that it's annoying, but I doubt this extra call makes any difference in the real world.
Sure, that certainly holds true.
Quoted 3 lines
Also, the corresponding kernel code designed to hide the special handling of the root cgroup. css_get()/css_put() are simple no-ops for the root cgroup, but are totally valid.
Yes, I do see that.
Quoted 3 lines
So in most places the root cgroup is handled as any other, which simplifies the code. I guess the same will be true for many bpf programs.
Quoted 6 lines
I see, however the same might not necessarily hold for all other global pointers which end up being handed out by a BPF kfunc (not necessarily
bpf_get_root_mem_cgroup()). This is why I was wondering whether there's some sense to introducing another KF flag (or something similar) which allows returned values from BPF kfuncs to be implicitly treated as trusted.
Quoted 4 lines
No need for a new KF flag. Any struct returned by kfunc should be trusted or
trusted_or_nullifKF_RET_NULLwas specified. I don't remember off the top of my head, but this behavior is already implemented or we discussed making it this way.
Hm, I do not see any evidence of this kind of semantic currently implemented, so perhaps it was only discussed at some point. Would you like me to put forward a patch that introduces this kind of implicit trust semantic for BPF kfuncs returning pointer to struct types?
Re: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
Quoted 11 lines · Matt Bobrowski
Quoted 6 lines
No need for a new KF flag. Any struct returned by kfunc should be trusted or
trusted_or_nullifKF_RET_NULLwas specified. I don't remember off the top of my head, but this behavior is already implemented or we discussed making it this way.Hm, I do not see any evidence of this kind of semantic currently implemented, so perhaps it was only discussed at some point. Would you like me to put forward a patch that introduces this kind of implicit trust semantic for BPF kfuncs returning pointer to struct types?
Hmm. What about these:BTF_ID_FLAGS(func, scx_bpf_cpu_rq)BTF_ID_FLAGS(func, scx_bpf_locked_rq, KF_RET_NULL) BTF_ID_FLAGS(func, scx_bpf_cpu_curr, KF_RET_NULL | KF_RCU_PROTECTED)
I thought they're returning a trusted pointer without acquiring it. iirc the last one returns trusted in RCU CS,
but the first two return just a legacy ptr_to_btf_id ? This is something to fix asap then.
Re: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
Quoted 18 lines · Alexei Starovoitov
Quoted 11 lines · Matt Bobrowski
Quoted 6 lines
No need for a new KF flag. Any struct returned by kfunc should be trusted or
trusted_or_nullifKF_RET_NULLwas specified. I don't remember off the top of my head, but this behavior is already implemented or we discussed making it this way.Hm, I do not see any evidence of this kind of semantic currently implemented, so perhaps it was only discussed at some point. Would you like me to put forward a patch that introduces this kind of implicit trust semantic for BPF kfuncs returning pointer to struct types?
Hmm. What about these:
BTF_ID_FLAGS(func, scx_bpf_cpu_rq)BTF_ID_FLAGS(func, scx_bpf_locked_rq, KF_RET_NULL)BTF_ID_FLAGS(func, scx_bpf_cpu_curr, KF_RET_NULL | KF_RCU_PROTECTED)
Quoted 4 lines
I thought they're returning a trusted pointer without acquiring it. iirc the last one returns trusted in RCU CS,
but the first two return just a legacyptr_to_btf_id? This is something to fix asap then.
No, AFAIU they do not. These simply return a regular pointer to BTF ID (PTR_TO_BTF_ID), rather than a formally "trusted" pointer (which would carry the PTR_TRUSTED flag or a ref_obj_id). scx_bpf_cpu_curr returns a MEM_RCU pointer (via KF_RCU_PROTECTED), which is somewhat considered to be trusted within a RCU read-side critical section *ONLY*.
Kumar/Tejun,
Please keep me honest here.
Kumar Kartikeya Dwivedi
maintainerRe: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
Quoted 25 lines · Matt Bobrowski
Quoted 18 lines · Alexei Starovoitov
Quoted 11 lines · Matt Bobrowski
Quoted 6 lines
No need for a new KF flag. Any struct returned by kfunc should be trusted or
trusted_or_nullifKF_RET_NULLwas specified. I don't remember off the top of my head, but this behavior is already implemented or we discussed making it this way.Hm, I do not see any evidence of this kind of semantic currently implemented, so perhaps it was only discussed at some point. Would you like me to put forward a patch that introduces this kind of implicit trust semantic for BPF kfuncs returning pointer to struct types?
Hmm. What about these:
BTF_ID_FLAGS(func, scx_bpf_cpu_rq)BTF_ID_FLAGS(func, scx_bpf_locked_rq, KF_RET_NULL)BTF_ID_FLAGS(func, scx_bpf_cpu_curr, KF_RET_NULL | KF_RCU_PROTECTED)Quoted 4 lines
I thought they're returning a trusted pointer without acquiring it. iirc the last one returns trusted in RCU CS,
but the first two return just a legacyptr_to_btf_id? This is something to fix asap then.
Quoted 7 lines
No, AFAIU they do not. These simply return a regular pointer to BTF ID (
PTR_TO_BTF_ID), rather than a formally "trusted" pointer (which would carry thePTR_TRUSTEDflag or aref_obj_id).scx_bpf_cpu_currreturns aMEM_RCUpointer (viaKF_RCU_PROTECTED), which is somewhat considered to be trusted within a RCU read-side critical section *ONLY*.Kumar/Tejun,
Yeah, they don't return a trusted pointer. I think it would make sense to change the behavior here by default.
A non-trusted pointer cannot be passed to kfuncs taking trusted arguments, so hopefully it will only make things more permissive and doesn't break anything.
Quoted 2 lines
Please keep me honest here.
Re: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
Quoted 32 lines · Kumar Kartikeya Dwivedi
Quoted 31 lines · Matt Bobrowski
Quoted 18 lines · Alexei Starovoitov
Quoted 11 lines · Matt Bobrowski
Quoted 6 lines
No need for a new KF flag. Any struct returned by kfunc should be trusted or
trusted_or_nullifKF_RET_NULLwas specified. I don't remember off the top of my head, but this behavior is already implemented or we discussed making it this way.Hm, I do not see any evidence of this kind of semantic currently implemented, so perhaps it was only discussed at some point. Would you like me to put forward a patch that introduces this kind of implicit trust semantic for BPF kfuncs returning pointer to struct types?
Hmm. What about these:
BTF_ID_FLAGS(func, scx_bpf_cpu_rq)BTF_ID_FLAGS(func, scx_bpf_locked_rq, KF_RET_NULL)BTF_ID_FLAGS(func, scx_bpf_cpu_curr, KF_RET_NULL | KF_RCU_PROTECTED)Quoted 4 lines
I thought they're returning a trusted pointer without acquiring it. iirc the last one returns trusted in RCU CS,
but the first two return just a legacyptr_to_btf_id? This is something to fix asap then.No, AFAIU they do not. These simply return a regular pointer to BTF ID (
PTR_TO_BTF_ID), rather than a formally "trusted" pointer (which would carry thePTR_TRUSTEDflag or aref_obj_id).scx_bpf_cpu_currreturns aMEM_RCUpointer (viaKF_RCU_PROTECTED), which is somewhat considered to be trusted within a RCU read-side critical section *ONLY*.
Quoted 4 lines
Quoted 1 line
Kumar/Tejun,
Yeah, they don't return a trusted pointer. I think it would make sense to change the behavior here by default.
Thanks for chiming in and confirming this Kumar! I also agree that any BPF kfunc returning a pointer should be treated as being implicitly trusted by default. I can't think of any scenario whereby a BPF kfunc would want to return a pointer that'd fundamentally be untrusted, but there always could be some exceptions. Anyway, I will work on this and send something through for review soon.
Quoted 3 lines
A non-trusted pointer cannot be passed to kfuncs taking trusted arguments, so hopefully it will only make things more permissive and doesn't break anything.
We can only hope! ;)
Roman Gushchin
maintainerPATCH v4 4/6 mm: introduce BPF kfuncs to access memcg statistics and events
In reply to Roman GushchinIntroduce BPF kfuncs to conveniently access memcg data:
- bpf_mem_cgroup_vm_events(),
- bpf_mem_cgroup_memory_events(),
- bpf_mem_cgroup_usage(),
- bpf_mem_cgroup_page_state(),
- bpf_mem_cgroup_flush_stats().
These functions are useful for implementing BPF OOM policies, but also can be used to accelerate access to the memcg data. Reading it through cgroupfs is much more expensive, roughly 5x, mostly because of the need to convert the data into the text and back.
JP Kobryn:
An experiment was setup to compare the performance of a program that uses the traditional method of reading memory.stat vs a program using the new kfuncs. The control program opens up the root memory.stat file and for 1M iterations reads, converts the string values to numeric data, then seeks back to the beginning. The experimental program sets up the requisite libbpf objects and for 1M iterations invokes a bpf program which uses the kfuncs to fetch all available stats for node_stat_item, memcg_stat_item, and vm_event_item types.
The results showed a significant perf benefit on the experimental side, outperforming the control side by a margin of 93%. In kernel mode, elapsed time was reduced by 80%, while in user mode, over 99% of time was saved.
control: elapsed time
real 0m38.318s user 0m25.131s sys 0m13.070s
experiment: elapsed time
real 0m2.789s user 0m0.187s sys 0m2.512s
control: perf data
33.43% a.out libc.so.6 [.] __vfscanf_internal
6.88% a.out [kernel.kallsyms] [k] vsnprintf
6.33% a.out libc.so.6 [.] _IO_fgets
5.51% a.out [kernel.kallsyms] [k] format_decode
4.31% a.out libc.so.6 [.] __GI_____strtoull_l_internal
3.78% a.out [kernel.kallsyms] [k] string
3.53% a.out [kernel.kallsyms] [k] number
2.71% a.out libc.so.6 [.] _IO_sputbackc
2.41% a.out [kernel.kallsyms] [k] strlen
1.98% a.out a.out [.] main 1.70% a.out libc.so.6 [.] _IO_getline_info 1.51% a.out libc.so.6 [.] __isoc99_sscanf
1.47% a.out [kernel.kallsyms] [k] memory_stat_format 1.47% a.out [kernel.kallsyms] [k] memcpy_orig 1.41% a.out [kernel.kallsyms] [k] seq_buf_printf
experiment: perf data
10.55% memcgstat bpf_prog_..._query [k] bpf_prog_16aab2f19fa982a7_query
6.90% memcgstat [kernel.kallsyms] [k] memcg_page_state_output 3.55% memcgstat [kernel.kallsyms] [k] _raw_spin_lock 3.12% memcgstat [kernel.kallsyms] [k] memcg_events 2.87% memcgstat [kernel.kallsyms] [k] __memcg_slab_post_alloc_hook 2.73% memcgstat [kernel.kallsyms] [k] kmem_cache_free 2.70% memcgstat [kernel.kallsyms] [k] entry_SYSRETQ_unsafe_stack 2.25% memcgstat [kernel.kallsyms] [k] __memcg_slab_free_hook 2.06% memcgstat [kernel.kallsyms] [k] get_page_from_freelist
--- include/linux/memcontrol.h | 14 +++++++ mm/bpf_memcontrol.c | 85 ++++++++++++++++++++++++++++++++++++++ mm/memcontrol.c | 16 +++++++ 3 files changed, 115 insertions(+)
include/linux/memcontrol.h +14 -0
@@ -949,8 +949,12 @@ static inline void mod_memcg_page_state(struct page *page,rcu_read_unlock (); } +unsigned long memcg_events (struct mem_cgroup *memcg,int event); +unsigned long mem_cgroup_usage (struct mem_cgroup *memcg,bool swap);unsigned long memcg_page_state (struct mem_cgroup *memcg,int idx);unsigned long memcg_page_state_output (struct mem_cgroup *memcg,int item); +bool memcg_stat_item_valid (int idx); +bool memcg_vm_event_item_valid (enum vm_event_item idx);unsigned long lruvec_page_state (struct lruvec *lruvec,enum node_stat_item idx);unsigned long lruvec_page_state_local (struct lruvec *lruvec,enum node_stat_item idx);
@@ -1379,6 +1383,16 @@ static inline unsigned long memcg_page_state_output(struct mem_cgroup *memcg, inreturn 0 ; } +static inline bool memcg_stat_item_valid (int idx) +{ +return false; +} + +static inline bool memcg_vm_event_item_valid (enum vm_event_item idx) +{ +return false; +} +static inline unsigned long lruvec_page_state (struct lruvec *lruvec,enum node_stat_item idx) {
mm/bpf_memcontrol.c +85 -0
97 lines not on this page · raw message
mm/memcontrol.c +16 -0
@@ -663,6 +663,14 @@ unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx)return x; } +bool memcg_stat_item_valid (int idx) +{ +if ((u32 )idx >=MEMCG_NR_STAT ) +return false; + +return !BAD_STAT_IDX (memcg_stats_index (idx)); +} +static int memcg_page_state_unit (int item);/*
@@ -860,6 +868,14 @@ unsigned long memcg_events(struct mem_cgroup *memcg, int event)return READ_ONCE (memcg->vmstats->events[i]); } +bool memcg_vm_event_item_valid (enum vm_event_item idx) +{ +if (idx >=NR_VM_EVENT_ITEMS ) +return false; + +return !BAD_STAT_IDX (memcg_events_index (idx)); +} +#ifdef CONFIG_MEMCG_V1 unsigned long memcg_events_local (struct mem_cgroup *memcg,int event) {
Signature · 1 line
2.52.0
Roman Gushchin
maintainerPATCH v4 5/6 bpf: selftests: selftests for memcg stat kfuncs
In reply to Roman GushchinFrom: JP Kobryn <[email protected]>
Add test coverage for the kfuncs that fetch memcg stats. Using some common stats, test scenarios ensuring that the given stat increases by some arbitrary amount. The stats selected cover the three categories represented by the enums: node_stat_item, memcg_stat_item, vm_event_item.
Since only a subset of all stats are queried, use a static struct made up of fields for each stat. Write to the struct with the fetched values when the bpf program is invoked and read the fields in the user mode program for verification.
--- .../testing/selftests/bpf/cgroup_iter_memcg.h | 18 ++ .../bpf/prog_tests/cgroup_iter_memcg.c | 223 ++++++++++++++++++ .../selftests/bpf/progs/cgroup_iter_memcg.c | 39 +++ 3 files changed, 280 insertions(+) create mode 100644 tools/testing/selftests/bpf/cgroup_iter_memcg.h create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c create mode 100644 tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c
tools/testing/selftests/bpf/cgroup_iter_memcg.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ +#ifndef __CGROUP_ITER_MEMCG_H +#define __CGROUP_ITER_MEMCG_H + +struct memcg_query { +/* some node_stat_item's */ +unsigned long nr_anon_mapped; +unsigned long nr_shmem; +unsigned long nr_file_pages; +unsigned long nr_file_mapped; +/* some memcg_stat_item */ +unsigned long memcg_kmem; +/* some vm_event_item */ +unsigned long pgfault; +}; + +#endif /* __CGROUP_ITER_MEMCG_H */
tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c new file +223 -0
223 lines not on this page · raw message
tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ +#include <vmlinux.h> +#include <bpf/bpf_core_read.h> +#include "cgroup_iter_memcg.h" + +char _license[] SEC("license") = "GPL"; + +/* The latest values read are stored here. */ +struct memcg_query memcg_query SEC(".data.query"); + +SEC("iter.s/cgroup") +int cgroup_memcg_query (struct bpf_iter__cgroup *ctx) +{ +struct cgroup *cgrp = ctx->cgroup; +struct cgroup_subsys_state *css; +struct mem_cgroup *memcg; + +if (!cgrp) +return 1 ; + + css = &cgrp->self; + memcg =bpf_get_mem_cgroup (css); +if (!memcg) +return 1 ; + +bpf_mem_cgroup_flush_stats (memcg); + + memcg_query.nr_anon_mapped =bpf_mem_cgroup_page_state (memcg,NR_ANON_MAPPED ); + memcg_query.nr_shmem =bpf_mem_cgroup_page_state (memcg,NR_SHMEM ); + memcg_query.nr_file_pages =bpf_mem_cgroup_page_state (memcg,NR_FILE_PAGES ); + memcg_query.nr_file_mapped =bpf_mem_cgroup_page_state (memcg,NR_FILE_MAPPED ); + memcg_query.memcg_kmem =bpf_mem_cgroup_page_state (memcg,MEMCG_KMEM ); + memcg_query.pgfault =bpf_mem_cgroup_vm_events (memcg,PGFAULT ); + +bpf_put_mem_cgroup (memcg); + +return 0 ; +}
Signature · 1 line
2.52.0
Roman Gushchin
maintainerPATCH v4 6/6 MAINTAINERS: add an entry for MM BPF extensions
In reply to Roman GushchinLet's create a separate entry for MM BPF extensions: these patches often require an attention from both bpf and mm communities.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -4799,6 +4799,15 @@ L: [email protected] S: Maintained F: tools/lib/bpf/ +BPF [MEMORY MANAGEMENT EXTENSIONS] +M: Roman Gushchin <[email protected]> +M: JP Kobryn <[email protected]> +M: Shakeel Butt <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: mm/bpf_memcontrol.c + BPF [MISC] L: [email protected] S: Odd Fixes
Signature · 1 line
2.52.0
Quoted 11 lines · Roman Gushchin
Introduce kfuncs to simplify the access to the memcg data. These kfuncs can be used to accelerate monitoring use cases and for implementing custom OOM policies once BPF OOM is landed.
This patchset was separated out from the BPF OOM patchset to simplify the logistics and accelerate the landing of the part which is useful by itself. No functional changes since BPF OOM v2.
v4:
- refactored memcg vm event and stat item idx checks (by Alexei)
Applied yesterday.
pw-bot seems to be completely broken. No notifications for the last few days.
Roman Gushchin
maintainerQuoted 6 lines · Alexei Starovoitov
Quoted 5 lines · Roman Gushchin
Introduce kfuncs to simplify the access to the memcg data. These kfuncs can be used to accelerate monitoring use cases and for implementing custom OOM policies once BPF OOM is landed.
Quoted 8 lines
Quoted 6 lines
This patchset was separated out from the BPF OOM patchset to simplify the logistics and accelerate the landing of the part which is useful by itself. No functional changes since BPF OOM v2.
v4:
- refactored memcg vm event and stat item idx checks (by Alexei)Applied yesterday.
Thank you!
Quoted 1 line
pw-bot seems to be completely broken. No notifications for the last few days.
Yep, also there were some infra issues in the ci output... Something about git being unavailable.
Quoted 6 lines · Alexei Starovoitov
Quoted 2 lines
v4:
- refactored memcg vm event and stat item idx checks (by Alexei)Applied yesterday.
pw-bot seems to be completely broken. No notifications for the last few days.
It was postfix, actually, but it managed to fail in a way that didn't show up on monitoring. It should be in a happier place now. Thanks for the heads-up.
-K
Quoted 7 lines · Roman Gushchin
Introduce kfuncs to simplify the access to the memcg data. These kfuncs can be used to accelerate monitoring use cases and for implementing custom OOM policies once BPF OOM is landed.
This patchset was separated out from the BPF OOM patchset to simplify the logistics and accelerate the landing of the part which is useful by itself. No functional changes since BPF OOM v2.
For the series:
Quoted 8 lines · Roman Gushchin
Introduce kfuncs to simplify the access to the memcg data. These kfuncs can be used to accelerate monitoring use cases and for implementing custom OOM policies once BPF OOM is landed.
This patchset was separated out from the BPF OOM patchset to simplify the logistics and accelerate the landing of the part which is useful by itself. No functional changes since BPF OOM v2.
Hello Roman,
Thanks for driving the BPF-MM upstreaming work—this is great progress.
Would it be possible to upstream the bpf_st_ops and cgroups patch as a standalone series as well? [0]
While the upstreaming of BPF-THP is currently stalled, we are actively experimenting with more BPF-MM related features—like BPF-based NUMA balancing—on our production servers. This work is a great fit for per-cgroup tuning via BPF, and having your bpf_st_ops and cgroups changes upstream would be very helpful for these efforts.
[0] https://lore.kernel.org/bpf/CAADnVQJGiH_yF=AoFSRy4zh20uneJgBfqGshubLM6aVq069Fhg@mail.gmail.com/
Signature · 2 lines
Regards Yafang
Roman Gushchin
maintainerQuoted 11 lines · Yafang Shao
Quoted 8 lines · Roman Gushchin
Introduce kfuncs to simplify the access to the memcg data. These kfuncs can be used to accelerate monitoring use cases and for implementing custom OOM policies once BPF OOM is landed.
This patchset was separated out from the BPF OOM patchset to simplify the logistics and accelerate the landing of the part which is useful by itself. No functional changes since BPF OOM v2.
Quoted 6 lines
Hello Roman,
Thanks for driving the BPF-MM upstreaming work—this is great progress.
Would it be possible to upstream the
bpf_st_opsand cgroups patch as a standalone series as well? [0]
Hello Yafang,
this is in my plan for next few weeks: I'll probably try to upstream it altogether with bpfoom, but if there will be any delays with bpfoom, we can split the patchset further.
Thanks!