Skip to content

Commit e0a146b

Browse files
Yang Yingliangopsiff
authored andcommitted
cgroup: disable kernel memory accounting for all memory cgroups by default
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8QLND CVE: NA ---------------------------------------- The kernel memory accounting for all memory cgroups is not stable, and it will cause a 100% regression in hackbench compared with kernel-4.19, so disable it by default. We can use the following command line to enable or disable it: cgroup.memory=kmem or cgroup.memory=nokmem. Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Signed-off-by: Zheng Zengkai <zhengzengkai@huawei.com> Signed-off-by: chenridong <chenridong@huawei.com> Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 1fe9a1f commit e0a146b

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

Documentation/admin-guide/cgroup-v1/memory.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ the amount of kernel memory used by the system. Kernel memory is fundamentally
320320
different than user memory, since it can't be swapped out, which makes it
321321
possible to DoS the system by consuming too much of this precious resource.
322322

323-
Kernel memory accounting is enabled for all memory cgroups by default. But
324-
it can be disabled system-wide by passing cgroup.memory=nokmem to the kernel
325-
at boot time. In this case, kernel memory will not be accounted at all.
323+
Kernel memory accounting is disabled for all memory cgroups by default. But
324+
it can be enabled system-wide by passing cgroup.memory=kmem to the kernel
325+
at boot time. In this case, kernel memory will all be accounted.
326326

327327
Kernel memory limits are not imposed for the root cgroup. Usage for the root
328328
cgroup may or may not be accounted. The memory used is accumulated into

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@
589589
Format: <string>
590590
nosocket -- Disable socket memory accounting.
591591
nokmem -- Disable kernel memory accounting.
592+
kmem -- Enable kernel memory accounting.
592593
nobpf -- Disable BPF memory accounting.
593594

594595
checkreqprot= [SELINUX] Set initial checkreqprot flag value.

mm/memcontrol.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ EXPORT_PER_CPU_SYMBOL_GPL(int_active_memcg);
8787
static bool cgroup_memory_nosocket __ro_after_init;
8888

8989
/* Kernel memory accounting disabled? */
90-
static bool cgroup_memory_nokmem __ro_after_init;
90+
static bool cgroup_memory_nokmem __ro_after_init = true;
9191

9292
/* BPF memory accounting disabled? */
9393
static bool cgroup_memory_nobpf __ro_after_init;
@@ -7618,6 +7618,8 @@ static int __init cgroup_memory(char *s)
76187618
cgroup_memory_nosocket = true;
76197619
if (!strcmp(token, "nokmem"))
76207620
cgroup_memory_nokmem = true;
7621+
else if (!strcmp(token, "kmem"))
7622+
cgroup_memory_nokmem = false;
76217623
if (!strcmp(token, "nobpf"))
76227624
cgroup_memory_nobpf = true;
76237625
}

0 commit comments

Comments
 (0)