Skip to content

Commit bdf4f4d

Browse files
hnaztorvalds
authored andcommitted
mm: memcg: only check anon swapin page charges for swap cache
shmem knows for sure that the page is in swap cache when attempting to charge a page, because the cache charge entry function has a check for it. Only anon pages may be removed from swap cache already when trying to charge their swapin. Adjust the comment, though: '4969c11 mm: fix swapin race condition' added a stable PageSwapCache check under the page lock in the do_swap_page() before calling the memory controller, so it's unuse_pte()'s pte_same() that may fail. Signed-off-by: Johannes Weiner <[email protected]> Acked-by: KAMEZAWA Hiroyuki <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: David Rientjes <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Wanpeng Li <[email protected]> Cc: Mel Gorman <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 90deb78 commit bdf4f4d

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

mm/memcontrol.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,14 +2818,6 @@ static int __mem_cgroup_try_charge_swapin(struct mm_struct *mm,
28182818
return 0;
28192819
if (!do_swap_account)
28202820
goto charge_cur_mm;
2821-
/*
2822-
* A racing thread's fault, or swapoff, may have already updated
2823-
* the pte, and even removed page from swap cache: in those cases
2824-
* do_swap_page()'s pte_same() test will fail; but there's also a
2825-
* KSM case which does need to charge the page.
2826-
*/
2827-
if (!PageSwapCache(page))
2828-
goto charge_cur_mm;
28292821
memcg = try_get_mem_cgroup_from_page(page);
28302822
if (!memcg)
28312823
goto charge_cur_mm;
@@ -2848,6 +2840,20 @@ int mem_cgroup_try_charge_swapin(struct mm_struct *mm, struct page *page,
28482840
*memcgp = NULL;
28492841
if (mem_cgroup_disabled())
28502842
return 0;
2843+
/*
2844+
* A racing thread's fault, or swapoff, may have already
2845+
* updated the pte, and even removed page from swap cache: in
2846+
* those cases unuse_pte()'s pte_same() test will fail; but
2847+
* there's also a KSM case which does need to charge the page.
2848+
*/
2849+
if (!PageSwapCache(page)) {
2850+
int ret;
2851+
2852+
ret = __mem_cgroup_try_charge(mm, gfp_mask, 1, memcgp, true);
2853+
if (ret == -EINTR)
2854+
ret = 0;
2855+
return ret;
2856+
}
28512857
return __mem_cgroup_try_charge_swapin(mm, page, gfp_mask, memcgp);
28522858
}
28532859

0 commit comments

Comments
 (0)