From: Nick Piggin free_it obviously should be below the unlock_page. Cc: Jeff Garzik Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Hugh Dickins Cc: "Paul E. McKenney" Cc: Peter Zijlstra Signed-off-by: Andrew Morton --- mm/vmscan.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff -puN mm/vmscan.c~mm-speculative-page-references-fix-fix mm/vmscan.c --- a/mm/vmscan.c~mm-speculative-page-references-fix-fix +++ a/mm/vmscan.c @@ -391,7 +391,7 @@ static pageout_t pageout(struct page *pa } /* - * Save as remove_mapping, but if the page is removed from the mapping, it + * Same as remove_mapping, but if the page is removed from the mapping, it * gets returned with a refcount of 0. */ static int __remove_mapping(struct address_space *mapping, struct page *page) @@ -619,6 +619,13 @@ static unsigned long shrink_page_list(st if (put_page_testzero(page)) goto free_it; else { + /* + * rare race with speculative reference. + * the speculative reference will free + * this page shortly, so we may + * increment nr_reclaimed here (and + * leave it off the LRU). + */ nr_reclaimed++; continue; } @@ -628,8 +635,8 @@ static unsigned long shrink_page_list(st if (!mapping || !__remove_mapping(mapping, page)) goto keep_locked; -free_it: unlock_page(page); +free_it: nr_reclaimed++; if (!pagevec_add(&freed_pvec, page)) { __pagevec_free(&freed_pvec); _