Skip to content

Commit 5b280c0

Browse files
Hugh Dickinstorvalds
authored andcommitted
mm: don't return 0 too early from find_get_pages()
Callers of find_get_pages(), or its wrapper pagevec_lookup() - notably truncate_inode_pages_range() - stop looking further when it returns 0. But if an interrupt comes just after its radix_tree_gang_lookup_slot(), especially if we have preemptible RCU enabled, isn't it conceivable that all 14 pages returned could be removed from the page cache by shrink_page_list(), before find_get_pages() gets to process them? So causing it to return 0 although there may be plenty more pages beyond. Make find_get_pages() and find_get_pages_tag() check for this unlikely case, and restart should it occur; but callers of find_get_pages_contig() have no such expectation, it's okay for that to return 0 early. I have not seen this in practice, just worried by the possibility. Signed-off-by: Hugh Dickins <[email protected]> Cc: Nick Piggin <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Cc: Wu Fengguang <[email protected]> Cc: Salman Qazi <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9d8aa4e commit 5b280c0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

mm/filemap.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,13 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
885885
pages[ret] = page;
886886
ret++;
887887
}
888+
889+
/*
890+
* If all entries were removed before we could secure them,
891+
* try again, because callers stop trying once 0 is returned.
892+
*/
893+
if (unlikely(!ret && nr_found))
894+
goto restart;
888895
rcu_read_unlock();
889896
return ret;
890897
}
@@ -1004,6 +1011,13 @@ unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
10041011
pages[ret] = page;
10051012
ret++;
10061013
}
1014+
1015+
/*
1016+
* If all entries were removed before we could secure them,
1017+
* try again, because callers stop trying once 0 is returned.
1018+
*/
1019+
if (unlikely(!ret && nr_found))
1020+
goto restart;
10071021
rcu_read_unlock();
10081022

10091023
if (ret)

0 commit comments

Comments
 (0)