diff mbox series

[v1,5/9] mm: memcg: guard memcg1-specific fields accesses in mm/memcontrol.c

Message ID 20240628210317.272856-6-roman.gushchin@linux.dev (mailing list archive)
State New
Headers show
Series mm: memcg: put cgroup v1-specific memcg data under CONFIG_MEMCG_V1 | expand

Commit Message

Roman Gushchin June 28, 2024, 9:03 p.m. UTC
There are only few memcg1-specific struct mem_cgroup's members
accesses left in mm/memcontrol.c. Let's guard them with the
CONFIG_MEMCG_V1 config option.

Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev>
---
 mm/memcontrol.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Shakeel Butt June 29, 2024, 12:49 a.m. UTC | #1
On Fri, Jun 28, 2024 at 09:03:13PM GMT, Roman Gushchin wrote:
> There are only few memcg1-specific struct mem_cgroup's members
> accesses left in mm/memcontrol.c. Let's guard them with the
> CONFIG_MEMCG_V1 config option.
> 
> Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev>

Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
diff mbox series

Patch

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e78ed54d46d2..661e3a70e685 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3672,20 +3672,23 @@  mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
 	page_counter_set_high(&memcg->swap, PAGE_COUNTER_MAX);
 	if (parent) {
 		WRITE_ONCE(memcg->swappiness, mem_cgroup_swappiness(parent));
-		WRITE_ONCE(memcg->oom_kill_disable, READ_ONCE(parent->oom_kill_disable));
 
 		page_counter_init(&memcg->memory, &parent->memory);
 		page_counter_init(&memcg->swap, &parent->swap);
+#ifdef CONFIG_MEMCG_V1
+		WRITE_ONCE(memcg->oom_kill_disable, READ_ONCE(parent->oom_kill_disable));
 		page_counter_init(&memcg->kmem, &parent->kmem);
 		page_counter_init(&memcg->tcpmem, &parent->tcpmem);
+#endif
 	} else {
 		init_memcg_stats();
 		init_memcg_events();
 		page_counter_init(&memcg->memory, NULL);
 		page_counter_init(&memcg->swap, NULL);
+#ifdef CONFIG_MEMCG_V1
 		page_counter_init(&memcg->kmem, NULL);
 		page_counter_init(&memcg->tcpmem, NULL);
-
+#endif
 		root_mem_cgroup = memcg;
 		return &memcg->css;
 	}
@@ -3820,8 +3823,10 @@  static void mem_cgroup_css_reset(struct cgroup_subsys_state *css)
 
 	page_counter_set_max(&memcg->memory, PAGE_COUNTER_MAX);
 	page_counter_set_max(&memcg->swap, PAGE_COUNTER_MAX);
+#ifdef CONFIG_MEMCG_V1
 	page_counter_set_max(&memcg->kmem, PAGE_COUNTER_MAX);
 	page_counter_set_max(&memcg->tcpmem, PAGE_COUNTER_MAX);
+#endif
 	page_counter_set_min(&memcg->memory, 0);
 	page_counter_set_low(&memcg->memory, 0);
 	page_counter_set_high(&memcg->memory, PAGE_COUNTER_MAX);