Commit 24c92eb7 authored by Shaohua Li's avatar Shaohua Li Committed by Linus Torvalds

mm: avoid marking swap cached page as lazyfree

MADV_FREE clears pte dirty bit and then marks the page lazyfree (clear
SwapBacked).  There is no lock to prevent the page is added to swap
cache between these two steps by page reclaim.  Page reclaim could add
the page to swap cache and unmap the page.  After page reclaim, the page
is added back to lru.  At that time, we probably start draining per-cpu
pagevec and mark the page lazyfree.  So the page could be in a state
with SwapBacked cleared and PG_swapcache set.  Next time there is a
refault in the virtual address, do_swap_page can find the page from swap
cache but the page has PageSwapCache false because SwapBacked isn't set,
so do_swap_page will bail out and do nothing.  The task will keep
running into fault handler.

Fixes: 802a3a92 ("mm: reclaim MADV_FREE pages")
Link: default avatarShaohua Li <>
Reported-by: default avatarArtem Savkov <>
Tested-by: default avatarArtem Savkov <>
Reviewed-by: default avatarRik van Riel <>
Acked-by: default avatarJohannes Weiner <>
Acked-by: default avatarMichal Hocko <>
Acked-by: default avatarMinchan Kim <>
Cc: Hillf Danton <>
Cc: Hugh Dickins <>
Cc: Mel Gorman <>
Cc: <>	[4.12+]
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent f4e222c5
......@@ -575,7 +575,7 @@ static void lru_lazyfree_fn(struct page *page, struct lruvec *lruvec,
void *arg)
if (PageLRU(page) && PageAnon(page) && PageSwapBacked(page) &&
!PageUnevictable(page)) {
!PageSwapCache(page) && !PageUnevictable(page)) {
bool active = PageActive(page);
del_page_from_lru_list(page, lruvec,
......@@ -665,7 +665,7 @@ void deactivate_file_page(struct page *page)
void mark_page_lazyfree(struct page *page)
if (PageLRU(page) && PageAnon(page) && PageSwapBacked(page) &&
!PageUnevictable(page)) {
!PageSwapCache(page) && !PageUnevictable(page)) {
struct pagevec *pvec = &get_cpu_var(lru_lazyfree_pvecs);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment