Skip to content

Commit c449deb

Browse files
Hugh Dickinsakpm00
authored andcommitted
mm: memcg: fix swapcached stat accounting
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 ac35a49 ("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. Link: https://lkml.kernel.org/r/[email protected] Fixes: b603894 ("mm: memcg: add swapcache stat for memcg v2") Signed-off-by: Hugh Dickins <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: Shakeel Butt <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Yu Zhao <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 12a5d39 commit c449deb

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

mm/memcontrol.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5767,6 +5767,12 @@ static int mem_cgroup_move_account(struct page *page,
57675767
}
57685768
}
57695769

5770+
#ifdef CONFIG_SWAP
5771+
if (folio_test_swapcache(folio)) {
5772+
__mod_lruvec_state(from_vec, NR_SWAPCACHE, -nr_pages);
5773+
__mod_lruvec_state(to_vec, NR_SWAPCACHE, nr_pages);
5774+
}
5775+
#endif
57705776
if (folio_test_writeback(folio)) {
57715777
__mod_lruvec_state(from_vec, NR_WRITEBACK, -nr_pages);
57725778
__mod_lruvec_state(to_vec, NR_WRITEBACK, nr_pages);

mm/vmscan.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,11 +1368,10 @@ static int __remove_mapping(struct address_space *mapping, struct folio *folio,
13681368
if (folio_test_swapcache(folio)) {
13691369
swp_entry_t swap = folio_swap_entry(folio);
13701370

1371-
/* get a shadow entry before mem_cgroup_swapout() clears folio_memcg() */
13721371
if (reclaimed && !mapping_exiting(mapping))
13731372
shadow = workingset_eviction(folio, target_memcg);
1374-
mem_cgroup_swapout(folio, swap);
13751373
__delete_from_swap_cache(folio, swap, shadow);
1374+
mem_cgroup_swapout(folio, swap);
13761375
xa_unlock_irq(&mapping->i_pages);
13771376
put_swap_folio(folio, swap);
13781377
} else {

0 commit comments

Comments
 (0)