Thread (24 messages) 24 messages, 3 authors, 2022-08-03
STALE1414d
Revisions (4)
  1. rfc current
  2. v1 [diff vs current]
  3. v2 [diff vs current]
  4. v3 [diff vs current]

[RFC PATCH bpf-next 07/15] bpf: Define bpf_map_get_memcg for !CONFIG_MEMCG_KMEM

From: Yafang Shao <hidden>
Date: 2022-07-29 15:23:38
Also in: bpf, linux-mm
Subsystem: bpf [core], bpf [general] (safe dynamic programs and tools), control group - memory resource controller (memcg), the rest · Maintainers: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Linus Torvalds

Then we can use this helper when CONFIG_MEMCG_KMEM is not set.

Signed-off-by: Yafang Shao <redacted>
---
 include/linux/memcontrol.h | 10 ++++++++++
 kernel/bpf/syscall.c       |  7 ++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 9ecead1042b9..2f0a611f12e5 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -361,6 +361,11 @@ struct mem_cgroup {
 
 extern struct mem_cgroup *root_mem_cgroup;
 
+static inline struct mem_cgroup *root_memcg(void)
+{
+	return root_mem_cgroup;
+}
+
 enum page_memcg_data_flags {
 	/* page->memcg_data is a pointer to an objcgs vector */
 	MEMCG_DATA_OBJCGS = (1UL << 0),
@@ -1138,6 +1143,11 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
 #define MEM_CGROUP_ID_SHIFT	0
 #define MEM_CGROUP_ID_MAX	0
 
+static inline struct mem_cgroup *root_memcg(void)
+{
+	return NULL;
+}
+
 static inline struct mem_cgroup *folio_memcg(struct folio *folio)
 {
 	return NULL;
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index a6f68ade200f..7289ee1a300a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -433,7 +433,7 @@ static struct mem_cgroup *bpf_map_get_memcg(const struct bpf_map *map)
 	if (map->objcg)
 		return get_mem_cgroup_from_objcg(map->objcg);
 
-	return root_mem_cgroup;
+	return root_memcg();
 }
 
 void *bpf_map_kmalloc_node(const struct bpf_map *map, size_t size, gfp_t flags,
@@ -488,6 +488,11 @@ static void bpf_map_save_memcg(struct bpf_map *map)
 static void bpf_map_release_memcg(struct bpf_map *map)
 {
 }
+
+static struct mem_cgroup *bpf_map_get_memcg(const struct bpf_map *map)
+{
+	return root_memcg();
+}
 #endif
 
 /*
-- 
2.17.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help