[PATCH v2 4/4] btrfs: use GFP_NOWAIT for tree block readahead

Boris Burkov <[email protected]> Tue, 21 Jul 2026 15:42:15 -0700
Newsgroups org.kernel.vger.linux-btrfs
Message-ID <ee8a445ea0791b92cb4902ef8cc5da531f5a12bd.1784673567.git.boris@bur.io>
extent_buffer readahead should not be able to painfully stall a
search_slot and hog tree locks by getting stuck in direct reclaim.

If the allocation fails, that is fine, we simply fail to do the
readahead in that case.

Signed-off-by: Boris Burkov <[email protected]>
---
 fs/btrfs/extent_io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 1a40250e1e83..3c014bd653ae 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4814,7 +4814,8 @@ void btrfs_readahead_tree_block(struct btrfs_fs_info *fs_info,
 		.level = level,
 		.transid = gen
 	};
-	struct btrfs_eb_prealloc pa = { 0 };
+	/* Readahead is best effort so prefer to fail rather than block in reclaim. */
+	struct btrfs_eb_prealloc pa = { .supports_nowait = true };
 	struct extent_buffer *eb;
 	int ret;
 
-- 
2.55.0