[Devel] [PATCH RHEL7 COMMIT] mm/memcg: optimize mem_cgroup_enough_memory()

Vasily Averin vvs at virtuozzo.com
Mon Oct 12 19:07:53 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1127.18.2.vz7.163.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.18.2.vz7.163.36
------>
commit 42198a2e87454cd34c2a61a86e4ffb90d0b19e0c
Author: Andrey Ryabinin <aryabinin at virtuozzo.com>
Date:   Mon Oct 12 19:07:53 2020 +0300

    mm/memcg: optimize mem_cgroup_enough_memory()
    
    mem_cgroup_enough_memory() iterates memcg's subtree to account
    'MEM_CGROUP_STAT_CACHE - MEM_CGROUP_STAT_SHMEM'.
    
    Fortunately we can just read memcg->cache counter instead
    as it's hierarchical (includes subgroups) and doesn't account
    shmem.
    
    https://jira.sw.ru/browse/PSBM-120968
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/memcontrol.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index fe06c7d..e0e113b 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4723,11 +4723,7 @@ int mem_cgroup_enough_memory(struct mem_cgroup *memcg, long pages)
 	free += page_counter_read(&memcg->dcache);
 
 	/* assume file cache is reclaimable */
-	free += mem_cgroup_recursive_stat2(memcg, MEM_CGROUP_STAT_CACHE);
-
-	/* but do not count shmem pages as they can't be purged,
-	 * only swapped out */
-	free -= mem_cgroup_recursive_stat(memcg, MEM_CGROUP_STAT_SHMEM);
+	free += page_counter_read(&memcg->cache);
 
 	return free < pages ? -ENOMEM : 0;
 }


More information about the Devel mailing list