page cache: Convert find_get_pages_range to XArray
The 'end' parameter of the xas_for_each iterator avoids a useless iteration at the end of the range. Signed-off-by: Matthew Wilcox <willy@infradead.org>
This commit is contained in:
parent
f280bf092d
commit
fd1b3cee2a
52
mm/filemap.c
52
mm/filemap.c
|
@ -1650,64 +1650,50 @@ unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start,
|
||||||
pgoff_t end, unsigned int nr_pages,
|
pgoff_t end, unsigned int nr_pages,
|
||||||
struct page **pages)
|
struct page **pages)
|
||||||
{
|
{
|
||||||
struct radix_tree_iter iter;
|
XA_STATE(xas, &mapping->i_pages, *start);
|
||||||
void **slot;
|
struct page *page;
|
||||||
unsigned ret = 0;
|
unsigned ret = 0;
|
||||||
|
|
||||||
if (unlikely(!nr_pages))
|
if (unlikely(!nr_pages))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
radix_tree_for_each_slot(slot, &mapping->i_pages, &iter, *start) {
|
xas_for_each(&xas, page, end) {
|
||||||
struct page *head, *page;
|
struct page *head;
|
||||||
|
if (xas_retry(&xas, page))
|
||||||
if (iter.index > end)
|
|
||||||
break;
|
|
||||||
repeat:
|
|
||||||
page = radix_tree_deref_slot(slot);
|
|
||||||
if (unlikely(!page))
|
|
||||||
continue;
|
continue;
|
||||||
|
/* Skip over shadow, swap and DAX entries */
|
||||||
if (radix_tree_exception(page)) {
|
if (xa_is_value(page))
|
||||||
if (radix_tree_deref_retry(page)) {
|
|
||||||
slot = radix_tree_iter_retry(&iter);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* A shadow entry of a recently evicted page,
|
|
||||||
* or a swap entry from shmem/tmpfs. Skip
|
|
||||||
* over it.
|
|
||||||
*/
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
head = compound_head(page);
|
head = compound_head(page);
|
||||||
if (!page_cache_get_speculative(head))
|
if (!page_cache_get_speculative(head))
|
||||||
goto repeat;
|
goto retry;
|
||||||
|
|
||||||
/* The page was split under us? */
|
/* The page was split under us? */
|
||||||
if (compound_head(page) != head) {
|
if (compound_head(page) != head)
|
||||||
put_page(head);
|
goto put_page;
|
||||||
goto repeat;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Has the page moved? */
|
/* Has the page moved? */
|
||||||
if (unlikely(page != *slot)) {
|
if (unlikely(page != xas_reload(&xas)))
|
||||||
put_page(head);
|
goto put_page;
|
||||||
goto repeat;
|
|
||||||
}
|
|
||||||
|
|
||||||
pages[ret] = page;
|
pages[ret] = page;
|
||||||
if (++ret == nr_pages) {
|
if (++ret == nr_pages) {
|
||||||
*start = pages[ret - 1]->index + 1;
|
*start = page->index + 1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
|
put_page:
|
||||||
|
put_page(head);
|
||||||
|
retry:
|
||||||
|
xas_reset(&xas);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We come here when there is no page beyond @end. We take care to not
|
* We come here when there is no page beyond @end. We take care to not
|
||||||
* overflow the index @start as it confuses some of the callers. This
|
* overflow the index @start as it confuses some of the callers. This
|
||||||
* breaks the iteration when there is page at index -1 but that is
|
* breaks the iteration when there is a page at index -1 but that is
|
||||||
* already broken anyway.
|
* already broken anyway.
|
||||||
*/
|
*/
|
||||||
if (end == (pgoff_t)-1)
|
if (end == (pgoff_t)-1)
|
||||||
|
|
Loading…
Reference in New Issue