Skip to content

Commit cc8385b

Browse files
committed
btrfs: preallocate radix tree node for readahead
We can preallocate the node so insertion does not have to do that under the lock. The GFP flags for the per-device radix tree are initialized to GFP_NOFS & ~__GFP_DIRECT_RECLAIM but we can use GFP_KERNEL, same as an allocation above anyway, but also 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 261cc2c commit cc8385b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

fs/btrfs/reada.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ static struct reada_zone *reada_find_zone(struct btrfs_fs_info *fs_info,
270270
if (!zone)
271271
return NULL;
272272

273+
ret = radix_tree_preload(GFP_KERNEL);
274+
if (ret) {
275+
kfree(zone);
276+
return NULL;
277+
}
278+
273279
zone->start = start;
274280
zone->end = end;
275281
INIT_LIST_HEAD(&zone->list);
@@ -299,6 +305,7 @@ static struct reada_zone *reada_find_zone(struct btrfs_fs_info *fs_info,
299305
zone = NULL;
300306
}
301307
spin_unlock(&fs_info->reada_lock);
308+
radix_tree_preload_end();
302309

303310
return zone;
304311
}

fs/btrfs/volumes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static struct btrfs_device *__alloc_device(void)
252252
atomic_set(&dev->reada_in_flight, 0);
253253
atomic_set(&dev->dev_stats_ccnt, 0);
254254
btrfs_device_data_ordered_init(dev);
255-
INIT_RADIX_TREE(&dev->reada_zones, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
255+
INIT_RADIX_TREE(&dev->reada_zones, GFP_KERNEL);
256256
INIT_RADIX_TREE(&dev->reada_extents, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
257257

258258
return dev;

0 commit comments

Comments
 (0)