[Devel] [PATCH rh7] mm/memcg: optimize mem_cgroup_enough_memory()
    Andrey Ryabinin 
    aryabinin at virtuozzo.com
       
    Mon Oct 12 14:58:05 MSK 2020
    
    
  
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 6587cc2ef019..e36ad592b3c7 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4721,11 +4721,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;
 }
-- 
2.26.2
    
    
More information about the Devel
mailing list