[rh7] mm/memcg: optimize mem_cgroup_enough_memory()

Submitted by Andrey Ryabinin on Oct. 12, 2020, 11:58 a.m.

Details

Message ID 20201012115805.24557-1-aryabinin@virtuozzo.com
State New
Series "mm/memcg: optimize mem_cgroup_enough_memory()"
Headers show

Commit Message

Andrey Ryabinin Oct. 12, 2020, 11:58 a.m.
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 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;
 }