[rh7,v3] mm/memcg: fix cache growth above cache.limit_in_bytes

Submitted by Andrey Ryabinin on July 30, 2020, 2:34 p.m.

Details

Message ID 20200730143439.22051-1-aryabinin@virtuozzo.com
State New
Series "mm/memcg: fix cache growth above cache.limit_in_bytes"
Headers show

Commit Message

Andrey Ryabinin July 30, 2020, 2:34 p.m.
Exceeding cache above cache.limit_in_bytes schedules high_work_func()
which tries to reclaim 32 pages. If cache generated fast enough or it allows
cgroup to steadily grow above cache.limit_in_bytes because we don't reclaim
enough. Try to reclaim exceeded amount of cache instead.

https://jira.sw.ru/browse/PSBM-106384
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---

 Changes since v1: add bug link to changelog
 Changes since v2: Fix cache_overused check (We should check if it's positive).
    Made this stupid bug during cleanup, patch was tested without bogus cleanup,
    so it shoud work.

 mm/memcontrol.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 3cf200f506c3..e23e546fd00f 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3080,12 +3080,16 @@  static void reclaim_high(struct mem_cgroup *memcg,
 {
 
 	do {
+		long cache_overused;
+
 		if (page_counter_read(&memcg->memory) > memcg->high)
 			try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, 0);
 
-		if (page_counter_read(&memcg->cache) > memcg->cache.limit)
-			try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask,
-						MEM_CGROUP_RECLAIM_NOSWAP);
+		cache_overused = page_counter_read(&memcg->cache) -
+			memcg->cache.limit;
+		if (cache_overused > 0)
+			try_to_free_mem_cgroup_pages(memcg, max(CHARGE_BATCH, cache_overused,
+					gfp_mask, MEM_CGROUP_RECLAIM_NOSWAP);
 
 	} while ((memcg = parent_mem_cgroup(memcg)));
 }