Skip to content

Commit 7ef70b4

Browse files
committed
btrfs: preallocate radix tree node for global readahead tree
We can preallocate the node so insertion does not have to do that under the lock. The GFP flags for the global radix tree are initialized to GFP_NOFS & ~__GFP_DIRECT_RECLAIM but we can use GFP_KERNEL, because readahead is optional and not on any critical writeout path. Reviewed-by: Liu Bo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent cc8385b commit 7ef70b4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

fs/btrfs/disk-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2693,7 +2693,7 @@ int open_ctree(struct super_block *sb,
26932693
fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
26942694
fs_info->avg_delayed_ref_runtime = NSEC_PER_SEC >> 6; /* div by 64 */
26952695
/* readahead state */
2696-
INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
2696+
INIT_RADIX_TREE(&fs_info->reada_tree, GFP_KERNEL);
26972697
spin_lock_init(&fs_info->reada_lock);
26982698

26992699
fs_info->thread_pool_size = min_t(unsigned long,

fs/btrfs/reada.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info,
393393
goto error;
394394
}
395395

396+
ret = radix_tree_preload(GFP_KERNEL);
397+
if (ret)
398+
goto error;
399+
396400
/* insert extent in reada_tree + all per-device trees, all or nothing */
397401
btrfs_dev_replace_lock(&fs_info->dev_replace, 0);
398402
spin_lock(&fs_info->reada_lock);
@@ -402,13 +406,16 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info,
402406
re_exist->refcnt++;
403407
spin_unlock(&fs_info->reada_lock);
404408
btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);
409+
radix_tree_preload_end();
405410
goto error;
406411
}
407412
if (ret) {
408413
spin_unlock(&fs_info->reada_lock);
409414
btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);
415+
radix_tree_preload_end();
410416
goto error;
411417
}
418+
radix_tree_preload_end();
412419
prev_dev = NULL;
413420
dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(
414421
&fs_info->dev_replace);

0 commit comments

Comments
 (0)