Re: [PATCH v2 1/2] memcg: introduce kfuncs for fetching memcg stats
From: Yonghong Song
Date: Thu Oct 16 2025 - 00:18:57 EST
On 10/15/25 4:12 PM, Song Liu wrote:
On Wed, Oct 15, 2025 at 12:08 PM JP Kobryn <inwardvessel@xxxxxxxxx> wrote:
[...]
---We should add __bpf_kfunc_start_defs() here, and __bpf_kfunc_end_defs()
mm/memcontrol.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4deda33625f4..6547c27d4430 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -871,6 +871,73 @@ unsigned long memcg_events_local(struct mem_cgroup *memcg, int event)
}
#endif
+static inline struct mem_cgroup *memcg_from_cgroup(struct cgroup *cgrp)
+{
+ return cgrp ? mem_cgroup_from_css(cgrp->subsys[memory_cgrp_id]) : NULL;
+}
+
after all the kfuncs.
+__bpf_kfunc static void memcg_flush_stats(struct cgroup *cgrp)We mostly do not make kfunc static, but it seems to also work.
Let us remove 'static' in __bpf_kfunc functions in order to be consistent
with other existing kfuncs.
The __bpf_kfunc macro is
linux/btf.h:#define __bpf_kfunc __used __retain __noclone noinline
__used and __retain attributes ensure the function won't be removed
by compiler/linker.
+{Maybe we can let memcg_flush_stats return int, and return -EINVAL
+ struct mem_cgroup *memcg = memcg_from_cgroup(cgrp);
+
+ if (!memcg)
+ return;
on memcg == NULL cases?
+[...]
+ mem_cgroup_flush_stats(memcg);
+}
+