Commit cc39c6a9 authored by Shaohua Li's avatar Shaohua Li Committed by Linus Torvalds

mm: account skipped entries to avoid looping in find_get_pages

The found entries by find_get_pages() could be all swap entries.  In
this case we skip the entries, but make sure the skipped entries are
accounted, so we don't keep looping.

Using nr_found > nr_skip to simplify code as suggested by Eric.
Reported-and-tested-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarShaohua Li <shaohua.li@intel.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4f5b0480
...@@ -827,13 +827,14 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start, ...@@ -827,13 +827,14 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
{ {
unsigned int i; unsigned int i;
unsigned int ret; unsigned int ret;
unsigned int nr_found; unsigned int nr_found, nr_skip;
rcu_read_lock(); rcu_read_lock();
restart: restart:
nr_found = radix_tree_gang_lookup_slot(&mapping->page_tree, nr_found = radix_tree_gang_lookup_slot(&mapping->page_tree,
(void ***)pages, NULL, start, nr_pages); (void ***)pages, NULL, start, nr_pages);
ret = 0; ret = 0;
nr_skip = 0;
for (i = 0; i < nr_found; i++) { for (i = 0; i < nr_found; i++) {
struct page *page; struct page *page;
repeat: repeat:
...@@ -856,6 +857,7 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start, ...@@ -856,6 +857,7 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
* here as an exceptional entry: so skip over it - * here as an exceptional entry: so skip over it -
* we only reach this from invalidate_mapping_pages(). * we only reach this from invalidate_mapping_pages().
*/ */
nr_skip++;
continue; continue;
} }
...@@ -876,7 +878,7 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start, ...@@ -876,7 +878,7 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
* If all entries were removed before we could secure them, * If all entries were removed before we could secure them,
* try again, because callers stop trying once 0 is returned. * try again, because callers stop trying once 0 is returned.
*/ */
if (unlikely(!ret && nr_found)) if (unlikely(!ret && nr_found > nr_skip))
goto restart; goto restart;
rcu_read_unlock(); rcu_read_unlock();
return ret; return ret;
......
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