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

Submitted by Vasily Averin on Oct. 12, 2020, 4:07 p.m.

Details

Message ID 202010121607.09CG7rA3015758@vz7build.vvs.sw.ru
State New
Series "mm/memcg: optimize mem_cgroup_enough_memory()"
Headers show

Commit Message

Vasily Averin Oct. 12, 2020, 4:07 p.m.
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@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@virtuozzo.com>
---
 mm/memcontrol.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Patch hide | download patch | download mbox

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;
 }