[PATCH 2/2] fuse: convert fuse_readdir_cached() to use folios

From: Tal Zussman

Date: Thu Sep 24 2026 - 19:42:51 EST


Replace find_get_page_flags() with __filemap_get_folio(), and switch the
remaining page helpers to their folio equivalents.

This removes seven hidden calls to compound_head() and the last caller of
find_get_page_flags().

Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/fuse/readdir.c | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c
index e6b828eb41a5..5e6b3f574e90 100644
--- a/fs/fuse/readdir.c
+++ b/fs/fuse/readdir.c
@@ -502,7 +502,7 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)
enum fuse_parse_result res;
pgoff_t index;
unsigned int size;
- struct page *page;
+ struct folio *folio;
void *addr;

/* Seeked? If so, reset the cache stream */
@@ -580,42 +580,44 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)
if (offset_in_page(ff->readdir.cache_off) == size)
return 0;

- page = find_get_page_flags(file->f_mapping, index,
- FGP_ACCESSED | FGP_LOCK);
- /* Page gone missing, then re-added to cache, but not initialized? */
- if (page && !PageUptodate(page)) {
- unlock_page(page);
- put_page(page);
- page = NULL;
+ folio = __filemap_get_folio(file->f_mapping, index,
+ FGP_ACCESSED | FGP_LOCK, 0);
+ if (IS_ERR(folio))
+ folio = NULL;
+ /* Folio gone missing, then re-added to cache, but not initialized? */
+ if (folio && !folio_test_uptodate(folio)) {
+ folio_unlock(folio);
+ folio_put(folio);
+ folio = NULL;
}
spin_lock(&fi->rdc.lock);
- if (!page) {
+ if (!folio) {
/*
- * Uh-oh: page gone missing, cache is useless
+ * Uh-oh: folio gone missing, cache is useless
*/
if (fi->rdc.version == ff->readdir.version)
fuse_rdc_reset(inode);
goto retry_locked;
}

- /* Make sure it's still the same version after getting the page. */
+ /* Make sure it's still the same version after getting the folio. */
if (ff->readdir.version != fi->rdc.version) {
spin_unlock(&fi->rdc.lock);
- unlock_page(page);
- put_page(page);
+ folio_unlock(folio);
+ folio_put(folio);
goto retry;
}
spin_unlock(&fi->rdc.lock);

/*
- * Contents of the page are now protected against changing by holding
- * the page lock.
+ * Contents of the folio are now protected against changing by holding
+ * the folio lock.
*/
- addr = kmap_local_page(page);
+ addr = kmap_local_folio(folio, 0);
res = fuse_parse_cache(ff, addr, size, ctx);
kunmap_local(addr);
- unlock_page(page);
- put_page(page);
+ folio_unlock(folio);
+ folio_put(folio);

if (res == FOUND_ERR)
return -EIO;

--
2.39.5