aboutsummaryrefslogtreecommitdiffstats
path: root/mm/filemap.c
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2018-01-16 06:26:49 -0500
committerMatthew Wilcox <willy@infradead.org>2018-10-21 10:46:36 -0400
commit8fa8e538e4be359e9042573737632dda35a8700d (patch)
treee885f07c50f9b3721d9d929bdc14de5e243333fe /mm/filemap.c
parentpage cache: Remove stray radix comment (diff)
downloadlinux-dev-8fa8e538e4be359e9042573737632dda35a8700d.tar.xz
linux-dev-8fa8e538e4be359e9042573737632dda35a8700d.zip
page cache: Convert filemap_range_has_page to XArray
Instead of calling find_get_pages_range() and putting any reference, use xas_find() to iterate over any entries in the range, skipping the shadow/swap entries. Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'mm/filemap.c')
-rw-r--r--mm/filemap.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/mm/filemap.c b/mm/filemap.c
index bedd8680f789..6b36516bc31d 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -455,20 +455,31 @@ EXPORT_SYMBOL(filemap_flush);
bool filemap_range_has_page(struct address_space *mapping,
loff_t start_byte, loff_t end_byte)
{
- pgoff_t index = start_byte >> PAGE_SHIFT;
- pgoff_t end = end_byte >> PAGE_SHIFT;
struct page *page;
+ XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT);
+ pgoff_t max = end_byte >> PAGE_SHIFT;
if (end_byte < start_byte)
return false;
- if (mapping->nrpages == 0)
- return false;
+ rcu_read_lock();
+ for (;;) {
+ page = xas_find(&xas, max);
+ if (xas_retry(&xas, page))
+ continue;
+ /* Shadow entries don't count */
+ if (xa_is_value(page))
+ continue;
+ /*
+ * We don't need to try to pin this page; we're about to
+ * release the RCU lock anyway. It is enough to know that
+ * there was a page here recently.
+ */
+ break;
+ }
+ rcu_read_unlock();
- if (!find_get_pages_range(mapping, &index, end, 1, &page))
- return false;
- put_page(page);
- return true;
+ return page != NULL;
}
EXPORT_SYMBOL(filemap_range_has_page);