[PATCH 08/10] btrfs: keep the free space cache inode mapping at order 0

From: Tal Zussman

Date: Sun Sep 06 2026 - 18:37:28 EST


The free space cache inode is a data inode, so the read path enables
large folios on its mapping. The v1 cache code assumes one page per
folio. With a large folio, consecutive __filemap_get_folio() calls in
io_ctl_prepare_pages() would return the same folio and deadlock on the
second FGP_LOCK.

The v1 on-disk format is PAGE_SIZE granular, so keep the mapping at
order 0 rather than teaching the io_ctl code about large folios.

Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/btrfs/btrfs_inode.h | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index 89e5e9c0c904..5d85aa69db13 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -502,6 +502,13 @@ static inline void btrfs_set_inode_mapping_order(struct btrfs_inode *inode)
/* Metadata inode should not reach here. */
ASSERT(is_data_inode(inode));

+ /*
+ * The v1 free space cache operates on PAGE_SIZE chunks and assumes
+ * one page per folio. Leave it at order 0.
+ */
+ if (btrfs_is_free_space_inode(inode))
+ return;
+
mapping_set_folio_order_range(inode->vfs_inode.i_mapping,
inode->root->fs_info->block_min_order,
inode->root->fs_info->block_max_order);

--
2.39.5