Skip to content

Commit c1901cd

Browse files
author
Matthew Wilcox
committed
page cache: Convert find_get_entries_tag to XArray
Slightly shorter and simpler code. Signed-off-by: Matthew Wilcox <[email protected]>
1 parent a690697 commit c1901cd

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

include/linux/pagemap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static inline unsigned find_get_pages_tag(struct address_space *mapping,
373373
nr_pages, pages);
374374
}
375375
unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,
376-
int tag, unsigned int nr_entries,
376+
xa_mark_t tag, unsigned int nr_entries,
377377
struct page **entries, pgoff_t *indices);
378378

379379
struct page *grab_cache_page_write_begin(struct address_space *mapping,

mm/filemap.c

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,57 +1866,51 @@ EXPORT_SYMBOL(find_get_pages_range_tag);
18661866
* @tag.
18671867
*/
18681868
unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,
1869-
int tag, unsigned int nr_entries,
1869+
xa_mark_t tag, unsigned int nr_entries,
18701870
struct page **entries, pgoff_t *indices)
18711871
{
1872-
void **slot;
1872+
XA_STATE(xas, &mapping->i_pages, start);
1873+
struct page *page;
18731874
unsigned int ret = 0;
1874-
struct radix_tree_iter iter;
18751875

18761876
if (!nr_entries)
18771877
return 0;
18781878

18791879
rcu_read_lock();
1880-
radix_tree_for_each_tagged(slot, &mapping->i_pages, &iter, start, tag) {
1881-
struct page *head, *page;
1882-
repeat:
1883-
page = radix_tree_deref_slot(slot);
1884-
if (unlikely(!page))
1880+
xas_for_each_marked(&xas, page, ULONG_MAX, tag) {
1881+
struct page *head;
1882+
if (xas_retry(&xas, page))
18851883
continue;
1886-
if (radix_tree_exception(page)) {
1887-
if (radix_tree_deref_retry(page)) {
1888-
slot = radix_tree_iter_retry(&iter);
1889-
continue;
1890-
}
1891-
1892-
/*
1893-
* A shadow entry of a recently evicted page, a swap
1894-
* entry from shmem/tmpfs or a DAX entry. Return it
1895-
* without attempting to raise page count.
1896-
*/
1884+
/*
1885+
* A shadow entry of a recently evicted page, a swap
1886+
* entry from shmem/tmpfs or a DAX entry. Return it
1887+
* without attempting to raise page count.
1888+
*/
1889+
if (xa_is_value(page))
18971890
goto export;
1898-
}
18991891

19001892
head = compound_head(page);
19011893
if (!page_cache_get_speculative(head))
1902-
goto repeat;
1894+
goto retry;
19031895

19041896
/* The page was split under us? */
1905-
if (compound_head(page) != head) {
1906-
put_page(head);
1907-
goto repeat;
1908-
}
1897+
if (compound_head(page) != head)
1898+
goto put_page;
19091899

19101900
/* Has the page moved? */
1911-
if (unlikely(page != *slot)) {
1912-
put_page(head);
1913-
goto repeat;
1914-
}
1901+
if (unlikely(page != xas_reload(&xas)))
1902+
goto put_page;
1903+
19151904
export:
1916-
indices[ret] = iter.index;
1905+
indices[ret] = xas.xa_index;
19171906
entries[ret] = page;
19181907
if (++ret == nr_entries)
19191908
break;
1909+
continue;
1910+
put_page:
1911+
put_page(head);
1912+
retry:
1913+
xas_reset(&xas);
19201914
}
19211915
rcu_read_unlock();
19221916
return ret;

0 commit comments

Comments
 (0)