Skip to contentSkip to conversation

mm-memcg-fix-swapcached-stat-accounting.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Dec 12, 2022

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm: memcg: fix swapcached stat accounting
has been removed from the -mm tree. Its filename was
mm-memcg-fix-swapcached-stat-accounting.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Hugh Dickins <[email protected]>
Subject: mm: memcg: fix swapcached stat accounting
Date: Sun, 4 Dec 2022 17:01:03 -0800 (PST)

I'd been worried by high "swapcached" counts in memcg OOM reports, thought we had a problem freeing swapcache, but it was just the accounting that was wrong.

Two issues:

1. When __remove_mapping() removes swapcache, __delete_from_swap_cache() relies on memcg_data for the right counts to be updated; but that had already been reset by mem_cgroup_swapout(). Swap those calls around - mem_cgroup_swapout() does not require the swapcached flag to be set.

6.1 commit ac35a4902374 ("mm: multi-gen LRU: minimal implementation") already made a similar swap for workingset_eviction(), but not for this.

2. memcg's "swapcached" count was added for memcg v2 stats, but displayed on OOM even for memcg v1: so mem_cgroup_move_account() ought to move it.

Fixes b6038942480e ("mm: memcg: add swapcache stat for memcg v2")
Cc Michal Hocko <[email protected]>
Cc Roman Gushchin <[email protected]>
Cc Yu Zhao <[email protected]>

---

 mm/memcontrol.c |    6 ++++++
 mm/vmscan.c     |    3 +--
 2 files changed, 7 insertions(+), 2 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-fix-swapcached-stat-accounting +6 -0
@@ -5767,6 +5767,12 @@ static int mem_cgroup_move_account(struc
 		}
 	}
 
+#ifdef CONFIG_SWAP
+	if (folio_test_swapcache(folio)) {
+		__mod_lruvec_state(from_vec, NR_SWAPCACHE, -nr_pages);
+		__mod_lruvec_state(to_vec, NR_SWAPCACHE, nr_pages);
+	}
+#endif
 	if (folio_test_writeback(folio)) {
 		__mod_lruvec_state(from_vec, NR_WRITEBACK, -nr_pages);
 		__mod_lruvec_state(to_vec, NR_WRITEBACK, nr_pages);
mm/vmscan.c renamed from mm/vmscan.c~mm-memcg-fix-swapcached-stat-accounting +1 -2
@@ -1368,11 +1368,10 @@ static int __remove_mapping(struct addre
 	if (folio_test_swapcache(folio)) {
 		swp_entry_t swap = folio_swap_entry(folio);
 
-		/* get a shadow entry before mem_cgroup_swapout() clears folio_memcg() */
 		if (reclaimed && !mapping_exiting(mapping))
 			shadow = workingset_eviction(folio, target_memcg);
-		mem_cgroup_swapout(folio, swap);
 		__delete_from_swap_cache(folio, swap, shadow);
+		mem_cgroup_swapout(folio, swap);
 		xa_unlock_irq(&mapping->i_pages);
 		put_swap_folio(folio, swap);
 	} else {

_

Patches currently in -mm which might be from [email protected] are