Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

page cache: Convert find_get_entries to XArray

Slightly shorter and simpler code.

Signed-off-by: Matthew Wilcox <willy@infradead.org>

+23 -28
+23 -28
mm/filemap.c
··· 1578 1578 pgoff_t start, unsigned int nr_entries, 1579 1579 struct page **entries, pgoff_t *indices) 1580 1580 { 1581 - void **slot; 1581 + XA_STATE(xas, &mapping->i_pages, start); 1582 + struct page *page; 1582 1583 unsigned int ret = 0; 1583 - struct radix_tree_iter iter; 1584 1584 1585 1585 if (!nr_entries) 1586 1586 return 0; 1587 1587 1588 1588 rcu_read_lock(); 1589 - radix_tree_for_each_slot(slot, &mapping->i_pages, &iter, start) { 1590 - struct page *head, *page; 1591 - repeat: 1592 - page = radix_tree_deref_slot(slot); 1593 - if (unlikely(!page)) 1589 + xas_for_each(&xas, page, ULONG_MAX) { 1590 + struct page *head; 1591 + if (xas_retry(&xas, page)) 1594 1592 continue; 1595 - if (radix_tree_exception(page)) { 1596 - if (radix_tree_deref_retry(page)) { 1597 - slot = radix_tree_iter_retry(&iter); 1598 - continue; 1599 - } 1600 - /* 1601 - * A shadow entry of a recently evicted page, a swap 1602 - * entry from shmem/tmpfs or a DAX entry. Return it 1603 - * without attempting to raise page count. 1604 - */ 1593 + /* 1594 + * A shadow entry of a recently evicted page, a swap 1595 + * entry from shmem/tmpfs or a DAX entry. Return it 1596 + * without attempting to raise page count. 1597 + */ 1598 + if (xa_is_value(page)) 1605 1599 goto export; 1606 - } 1607 1600 1608 1601 head = compound_head(page); 1609 1602 if (!page_cache_get_speculative(head)) 1610 - goto repeat; 1603 + goto retry; 1611 1604 1612 1605 /* The page was split under us? */ 1613 - if (compound_head(page) != head) { 1614 - put_page(head); 1615 - goto repeat; 1616 - } 1606 + if (compound_head(page) != head) 1607 + goto put_page; 1617 1608 1618 1609 /* Has the page moved? */ 1619 - if (unlikely(page != *slot)) { 1620 - put_page(head); 1621 - goto repeat; 1622 - } 1610 + if (unlikely(page != xas_reload(&xas))) 1611 + goto put_page; 1612 + 1623 1613 export: 1624 - indices[ret] = iter.index; 1614 + indices[ret] = xas.xa_index; 1625 1615 entries[ret] = page; 1626 1616 if (++ret == nr_entries) 1627 1617 break; 1618 + continue; 1619 + put_page: 1620 + put_page(head); 1621 + retry: 1622 + xas_reset(&xas); 1628 1623 } 1629 1624 rcu_read_unlock(); 1630 1625 return ret;