Skip to content

Commit 4597648

Browse files
Michal Hockoakpm00
authored andcommitted
mm, memcg: reconsider kmem.limit_in_bytes deprecation
This reverts commits 86327e8 ("memcg: drop kmem.limit_in_bytes") and partially reverts 58056f7 ("memcg, kmem: further deprecate kmem.limit_in_bytes") which have incrementally removed support for the kernel memory accounting hard limit. Unfortunately it has turned out that there is still userspace depending on the existence of memory.kmem.limit_in_bytes [1]. The underlying functionality is not really required but the non-existent file just confuses the userspace which fails in the result. The patch to fix this on the userspace side has been submitted but it is hard to predict how it will propagate through the maze of 3rd party consumers of the software. Now, reverting alone 86327e8 is not an option because there is another set of userspace which cannot cope with ENOTSUPP returned when writing to the file. Therefore we have to go and revisit 58056f7 as well. There are two ways to go ahead. Either we give up on the deprecation and fully revert 58056f7 as well or we can keep kmem.limit_in_bytes but make the write a noop and warn about the fact. This should work for both known breaking workloads which depend on the existence but do not depend on the hard limit enforcement. Note to backporters to stable trees. a8c49af ("memcg: add per-memcg total kernel memory stat") introduced in 4.18 has added memcg_account_kmem so the accounting is not done by obj_cgroup_charge_pages directly for v1 anymore. Prior kernels need to add it explicitly (thanks to Johannes for pointing this out). [[email protected]: fix build - remove unused local] Link: http://lkml.kernel.org/r/20230920081101.GA12096@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net [1] Link: https://lkml.kernel.org/r/[email protected] Fixes: 86327e8 ("memcg: drop kmem.limit_in_bytes") Fixes: 58056f7 ("memcg, kmem: further deprecate kmem.limit_in_bytes") Signed-off-by: Michal Hocko <[email protected]> Acked-by: Shakeel Butt <[email protected]> Acked-by: Johannes Weiner <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Jeremi Piotrowski <[email protected]> Cc: Muchun Song <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Tejun heo <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ca56489 commit 4597648

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ Brief summary of control files.
9292
memory.oom_control set/show oom controls.
9393
memory.numa_stat show the number of memory usage per numa
9494
node
95+
memory.kmem.limit_in_bytes Deprecated knob to set and read the kernel
96+
memory hard limit. Kernel hard limit is not
97+
supported since 5.16. Writing any value to
98+
do file will not have any effect same as if
99+
nokmem kernel parameter was specified.
100+
Kernel memory is still charged and reported
101+
by memory.kmem.usage_in_bytes.
95102
memory.kmem.usage_in_bytes show current kernel memory allocation
96103
memory.kmem.failcnt show the number of kernel memory usage
97104
hits limits

mm/memcontrol.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3867,6 +3867,13 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,
38673867
case _MEMSWAP:
38683868
ret = mem_cgroup_resize_max(memcg, nr_pages, true);
38693869
break;
3870+
case _KMEM:
3871+
pr_warn_once("kmem.limit_in_bytes is deprecated and will be removed. "
3872+
"Writing any value to this file has no effect. "
3873+
"Please report your usecase to [email protected] if you "
3874+
"depend on this functionality.\n");
3875+
ret = 0;
3876+
break;
38703877
case _TCP:
38713878
ret = memcg_update_tcp_max(memcg, nr_pages);
38723879
break;
@@ -5077,6 +5084,12 @@ static struct cftype mem_cgroup_legacy_files[] = {
50775084
.seq_show = memcg_numa_stat_show,
50785085
},
50795086
#endif
5087+
{
5088+
.name = "kmem.limit_in_bytes",
5089+
.private = MEMFILE_PRIVATE(_KMEM, RES_LIMIT),
5090+
.write = mem_cgroup_write,
5091+
.read_u64 = mem_cgroup_read_u64,
5092+
},
50805093
{
50815094
.name = "kmem.usage_in_bytes",
50825095
.private = MEMFILE_PRIVATE(_KMEM, RES_USAGE),

0 commit comments

Comments
 (0)