page cache: Convert find_get_entries_tag to XArray
authorMatthew Wilcox <willy@infradead.org>
Thu, 17 May 2018 03:56:04 +0000 (23:56 -0400)
committerMatthew Wilcox <willy@infradead.org>
Sun, 21 Oct 2018 14:46:35 +0000 (10:46 -0400)
Slightly shorter and simpler code.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
include/linux/pagemap.h
mm/filemap.c

index c9bbb9a05764dbe70bb6a09f75e5f8329bde063a..226f96f0dee0611e44622aaf6e401c588423e2de 100644 (file)
@@ -373,7 +373,7 @@ static inline unsigned find_get_pages_tag(struct address_space *mapping,
                                        nr_pages, pages);
 }
 unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,
-                       int tag, unsigned int nr_entries,
+                       xa_mark_t tag, unsigned int nr_entries,
                        struct page **entries, pgoff_t *indices);
 
 struct page *grab_cache_page_write_begin(struct address_space *mapping,
index 0df28aa6411c34b8ddc3192773c14d9d2b5a7080..35ae011971e153748609917594b985e21a5a1158 100644 (file)
@@ -1866,57 +1866,51 @@ EXPORT_SYMBOL(find_get_pages_range_tag);
  * @tag.
  */
 unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,
-                       int tag, unsigned int nr_entries,
+                       xa_mark_t tag, unsigned int nr_entries,
                        struct page **entries, pgoff_t *indices)
 {
-       void **slot;
+       XA_STATE(xas, &mapping->i_pages, start);
+       struct page *page;
        unsigned int ret = 0;
-       struct radix_tree_iter iter;
 
        if (!nr_entries)
                return 0;
 
        rcu_read_lock();
-       radix_tree_for_each_tagged(slot, &mapping->i_pages, &iter, start, tag) {
-               struct page *head, *page;
-repeat:
-               page = radix_tree_deref_slot(slot);
-               if (unlikely(!page))
+       xas_for_each_marked(&xas, page, ULONG_MAX, tag) {
+               struct page *head;
+               if (xas_retry(&xas, page))
                        continue;
-               if (radix_tree_exception(page)) {
-                       if (radix_tree_deref_retry(page)) {
-                               slot = radix_tree_iter_retry(&iter);
-                               continue;
-                       }
-
-                       /*
-                        * A shadow entry of a recently evicted page, a swap
-                        * entry from shmem/tmpfs or a DAX entry.  Return it
-                        * without attempting to raise page count.
-                        */
+               /*
+                * A shadow entry of a recently evicted page, a swap
+                * entry from shmem/tmpfs or a DAX entry.  Return it
+                * without attempting to raise page count.
+                */
+               if (xa_is_value(page))
                        goto export;
-               }
 
                head = compound_head(page);
                if (!page_cache_get_speculative(head))
-                       goto repeat;
+                       goto retry;
 
                /* The page was split under us? */
-               if (compound_head(page) != head) {
-                       put_page(head);
-                       goto repeat;
-               }
+               if (compound_head(page) != head)
+                       goto put_page;
 
                /* Has the page moved? */
-               if (unlikely(page != *slot)) {
-                       put_page(head);
-                       goto repeat;
-               }
+               if (unlikely(page != xas_reload(&xas)))
+                       goto put_page;
+
 export:
-               indices[ret] = iter.index;
+               indices[ret] = xas.xa_index;
                entries[ret] = page;
                if (++ret == nr_entries)
                        break;
+               continue;
+put_page:
+               put_page(head);
+retry:
+               xas_reset(&xas);
        }
        rcu_read_unlock();
        return ret;