[Devel] [PATCH RHEL9 COMMIT] ms/memcg, kmem: further deprecate kmem.limit_in_bytes

Konstantin Khorenko khorenko at virtuozzo.com
Fri Nov 12 20:30:30 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.26
------>
commit 0eddb17df4a42152e5710126b3fa17fc7af3f792
Author: Vasily Averin <vvs at virtuozzo.com>
Date:   Fri Nov 12 20:30:30 2021 +0300

    ms/memcg, kmem: further deprecate kmem.limit_in_bytes
    
    The deprecation process of kmem.limit_in_bytes started with the commit
    0158115f702 ("memcg, kmem: deprecate kmem.limit_in_bytes") which also
    explains in detail the motivation behind the deprecation.  To summarize,
    it is the unexpected behavior on hitting the kmem limit.  This patch
    moves the deprecation process to the next stage by disallowing to set
    the kmem limit.  In future we might just remove the kmem.limit_in_bytes
    file completely.
    
    [akpm at linux-foundation.org: s/ENOTSUPP/EOPNOTSUPP/]
    [arnd at arndb.de: mark cancel_charge() inline]
      Link: https://lkml.kernel.org/r/20211022070542.679839-1-arnd@kernel.org
    
    Link: https://lkml.kernel.org/r/20211019153408.2916808-1-shakeelb@google.com
    Signed-off-by: Shakeel Butt <shakeelb at google.com>
    Signed-off-by: Arnd Bergmann <arnd at arndb.de>
    Acked-by: Roman Gushchin <guro at fb.com>
    Acked-by: Michal Hocko <mhocko at suse.com>
    Reviewed-by: Muchun Song <songmuchun at bytedance.com>
    Cc: Vasily Averin <vvs at virtuozzo.com>
    Cc: Johannes Weiner <hannes at cmpxchg.org>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
    
    https://jira.sw.ru/browse/PSBM-134774
    https://jira.sw.ru/browse/PSBM-134369
    https://jira.sw.ru/browse/PSBM-135291
    (cherry picked from commit 58056f77502f3567b760c9a8fc8d2e9081515b2d)
    Signed-off-by: Vasily Averin <vvs at virtuozzo.com>
---
 Documentation/admin-guide/cgroup-v1/memory.rst | 11 ++------
 mm/memcontrol.c                                | 39 ++++----------------------
 2 files changed, 7 insertions(+), 43 deletions(-)

diff --git a/Documentation/admin-guide/cgroup-v1/memory.rst b/Documentation/admin-guide/cgroup-v1/memory.rst
index 41191b5fb69d..faac50149a22 100644
--- a/Documentation/admin-guide/cgroup-v1/memory.rst
+++ b/Documentation/admin-guide/cgroup-v1/memory.rst
@@ -87,10 +87,8 @@ Brief summary of control files.
  memory.oom_control		     set/show oom controls.
  memory.numa_stat		     show the number of memory usage per numa
 				     node
- memory.kmem.limit_in_bytes          set/show hard limit for kernel memory
-                                     This knob is deprecated and shouldn't be
-                                     used. It is planned that this be removed in
-                                     the foreseeable future.
+ memory.kmem.limit_in_bytes          This knob is deprecated and writing to
+                                     it will return -ENOTSUPP.
  memory.kmem.usage_in_bytes          show current kernel memory allocation
  memory.kmem.failcnt                 show the number of kernel memory usage
 				     hits limits
@@ -518,11 +516,6 @@ will be charged as a new owner of it.
   charged file caches. Some out-of-use page caches may keep charged until
   memory pressure happens. If you want to avoid that, force_empty will be useful.
 
-  Also, note that when memory.kmem.limit_in_bytes is set the charges due to
-  kernel pages will still be seen. This is not considered a failure and the
-  write will still return success. In this case, it is expected that
-  memory.kmem.usage_in_bytes == memory.usage_in_bytes.
-
 5.2 stat file
 -------------
 
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index fb047d0da227..f5d59acd91b9 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2894,8 +2894,7 @@ static inline int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
 	return try_charge_memcg(memcg, gfp_mask, nr_pages, cache_charge);
 }
 
-#if defined(CONFIG_MEMCG_KMEM) || defined(CONFIG_MMU)
-static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages)
+static inline void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages)
 {
 	if (mem_cgroup_is_root(memcg))
 		return;
@@ -2904,7 +2903,6 @@ static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages)
 	if (do_memsw_account())
 		page_counter_uncharge(&memcg->memsw, nr_pages);
 }
-#endif
 
 static void commit_charge(struct page *page, struct mem_cgroup *memcg)
 {
@@ -3123,7 +3121,6 @@ static void obj_cgroup_uncharge_pages(struct obj_cgroup *objcg,
 static int obj_cgroup_charge_pages(struct obj_cgroup *objcg, gfp_t gfp,
 				   unsigned int nr_pages)
 {
-	struct page_counter *counter;
 	struct mem_cgroup *memcg;
 	int ret;
 
@@ -3133,21 +3130,8 @@ static int obj_cgroup_charge_pages(struct obj_cgroup *objcg, gfp_t gfp,
 	if (ret)
 		goto out;
 
-	if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) &&
-	    !page_counter_try_charge(&memcg->kmem, nr_pages, &counter)) {
-
-		/*
-		 * Enforce __GFP_NOFAIL allocation because callers are not
-		 * prepared to see failures and likely do not have any failure
-		 * handling code.
-		 */
-		if (gfp & __GFP_NOFAIL) {
-			page_counter_charge(&memcg->kmem, nr_pages);
-			goto out;
-		}
-		cancel_charge(memcg, nr_pages);
-		ret = -ENOMEM;
-	}
+	if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
+		page_counter_charge(&memcg->kmem, nr_pages);
 out:
 	css_put(&memcg->css);
 
@@ -3905,17 +3889,6 @@ static void memcg_free_kmem(struct mem_cgroup *memcg)
 }
 #endif /* CONFIG_MEMCG_KMEM */
 
-static int memcg_update_kmem_max(struct mem_cgroup *memcg,
-				 unsigned long max)
-{
-	int ret;
-
-	mutex_lock(&memcg_max_mutex);
-	ret = page_counter_set_max(&memcg->kmem, max);
-	mutex_unlock(&memcg_max_mutex);
-	return ret;
-}
-
 static int memcg_update_tcp_max(struct mem_cgroup *memcg, unsigned long max)
 {
 	int ret;
@@ -4018,10 +3991,8 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,
 			ret = mem_cgroup_resize_max(memcg, nr_pages, true);
 			break;
 		case _KMEM:
-			pr_warn_once("kmem.limit_in_bytes is deprecated and will be removed. "
-				     "Please report your usecase to linux-mm at kvack.org if you "
-				     "depend on this functionality.\n");
-			ret = memcg_update_kmem_max(memcg, nr_pages);
+			/* kmem.limit_in_bytes is deprecated. */
+			ret = -EOPNOTSUPP;
 			break;
 		case _TCP:
 			ret = memcg_update_tcp_max(memcg, nr_pages);


More information about the Devel mailing list