[RHEL8,COMMIT] mm/memcg: fix cache growth above cache.limit_in_bytes

Submitted by Konstantin Khorenko on Oct. 5, 2020, 9 a.m.

Details

Message ID 202010050900.09590wQ7142406@finist-co8.sw.ru
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko Oct. 5, 2020, 9 a.m.
The commit is pushed to "branch-rh8-4.18.0-193.6.3.vz8.4.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.11
------>
commit e9a22ab1de9d9904945a5ed4abbbc9dff1bef6b1
Author: Andrey Ryabinin <aryabinin@virtuozzo.com>
Date:   Mon Oct 5 12:00:58 2020 +0300

    mm/memcg: fix cache growth above cache.limit_in_bytes
    
    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>
---
 mm/memcontrol.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 14727037bcd0..a2d9f74ef77c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2213,14 +2213,18 @@  static void reclaim_high(struct mem_cgroup *memcg,
 {
 
 	do {
+		long cache_overused;
 
 		if (page_counter_read(&memcg->memory) > memcg->high) {
 			memcg_memory_event(memcg, MEMCG_HIGH);
 			try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, true);
 		}
 
-		if (page_counter_read(&memcg->cache) > memcg->cache.max)
-			try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, false);
+		cache_overused = page_counter_read(&memcg->cache) -
+			memcg->cache.max;
+
+		if (cache_overused > 0)
+			try_to_free_mem_cgroup_pages(memcg, cache_overused, gfp_mask, false);
 	} while ((memcg = parent_mem_cgroup(memcg)));
 }