[Devel] [PATCH vz8] memcg: Fix missing memcg->cache charges during page migration

Andrey Ryabinin aryabinin at virtuozzo.com
Fri Oct 9 12:52:03 MSK 2020


Since 44b7a8d33d66 ("mm: memcontrol: do not uncharge old page in
 page cache replacement") the mem_cgroup_migrate() charges newpage,
but the ->cache charge is missing here. Add it to fix negative ->cache
values, which leads to WARNING like bellow and softlockups.

 WARNING: CPU: 14 PID: 1372 at mm/page_counter.c:62 page_counter_cancel+0x26/0x30

 Call Trace:
  page_counter_uncharge+0x1d/0x30
  uncharge_batch+0x25c/0x2e0
  mem_cgroup_uncharge_list+0x64/0x90
  release_pages+0x33e/0x3c0
  __pagevec_release+0x1b/0x40
  truncate_inode_pages_range+0x358/0x8b0
  ext4_evict_inode+0x167/0x580 [ext4]
  evict+0xd2/0x1a0
  do_unlinkat+0x250/0x2e0
  do_syscall_64+0x5b/0x1a0
  entry_SYSCALL_64_after_hwframe+0x65/0xca

https://jira.sw.ru/browse/PSBM-120653
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index df70c3bdd444..134cb27307f2 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6867,6 +6867,8 @@ void mem_cgroup_migrate(struct page *oldpage, struct page *newpage)
 	page_counter_charge(&memcg->memory, nr_pages);
 	if (do_memsw_account())
 		page_counter_charge(&memcg->memsw, nr_pages);
+	if (!PageAnon(newpage) && !PageSwapBacked(newpage))
+		page_counter_charge(&memcg->cache, nr_pages);
 	css_get_many(&memcg->css, nr_pages);
 
 	commit_charge(newpage, memcg, false);
-- 
2.26.2



More information about the Devel mailing list