[Devel] [PATCH vz10 09/32] proc: build the per-Container oom_score limit lookup only with CONFIG_MEMCG

Konstantin Khorenko khorenko at virtuozzo.com
Fri Aug 21 19:36:55 MSK 2026


From: Eva Kurchatova <eva.kurchatova at virtuozzo.com>

proc_oom_score() scales the badness against the memory cgroup limit of
the Container the task belongs to, using memory_cgrp_id,
mem_cgroup_from_css() and mem_cgroup_get_max().  None of those exist with
CONFIG_MEMCG disabled:

  fs/proc/base.c: error: 'memory_cgrp_id' undeclared (first use in this
                  function)

Wrap the whole lookup in CONFIG_MEMCG.  totalpages is already initialized
to totalram_pages() + total_swap_pages, so without a memory controller
oom_score simply falls back to being scaled against all of the machine's
memory, which is what a kernel without memory cgroups can report.

Fixes: 708b02c17c36 ("proc,memcg: use memcg limits for showing oom_score inside CT")
Feature: mm/oom: per-CT oom_score virtualization
https://virtuozzo.atlassian.net/browse/VSTOR-134732
Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 fs/proc/base.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 8174b2a8a5dc..f7cae1c59ec4 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -692,6 +692,7 @@ static int proc_oom_score(struct seq_file *m, struct pid_namespace *ns,
 	unsigned long points = 0;
 	long badness;
 
+#ifdef CONFIG_MEMCG
 	scoped_guard (rcu) {
 		struct cgroup_subsys_state *css = task_css(task, memory_cgrp_id);
 
@@ -703,6 +704,7 @@ static int proc_oom_score(struct seq_file *m, struct pid_namespace *ns,
 			totalpages = mem_cgroup_get_max(memcg);
 		}
 	}
+#endif
 
 	badness = oom_badness(task, totalpages, NULL);
 	/*
-- 
2.47.1



More information about the Devel mailing list