Skip to content

Commit 90519d6

Browse files
author
Arne Jansen
committed
btrfs: state information for readahead
Add state information for readahead to btrfs_fs_info and btrfs_device Changes v2: - don't wait in radix_trees - add own set of workers for readahead Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Arne Jansen <[email protected]>
1 parent ab0fff0 commit 90519d6

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

fs/btrfs/ctree.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ struct btrfs_fs_info {
10361036
struct btrfs_workers endio_freespace_worker;
10371037
struct btrfs_workers submit_workers;
10381038
struct btrfs_workers caching_workers;
1039+
struct btrfs_workers readahead_workers;
10391040

10401041
/*
10411042
* fixup workers take dirty pages that didn't properly go through
@@ -1119,6 +1120,10 @@ struct btrfs_fs_info {
11191120
u64 fs_state;
11201121

11211122
struct btrfs_delayed_root *delayed_root;
1123+
1124+
/* readahead tree */
1125+
spinlock_t reada_lock;
1126+
struct radix_tree_root reada_tree;
11221127
};
11231128

11241129
/*

fs/btrfs/disk-io.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,10 @@ struct btrfs_root *open_ctree(struct super_block *sb,
17111711
fs_info->defrag_inodes = RB_ROOT;
17121712
fs_info->trans_no_join = 0;
17131713

1714+
/* readahead state */
1715+
INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT);
1716+
spin_lock_init(&fs_info->reada_lock);
1717+
17141718
fs_info->thread_pool_size = min_t(unsigned long,
17151719
num_online_cpus() + 2, 8);
17161720

@@ -1903,6 +1907,9 @@ struct btrfs_root *open_ctree(struct super_block *sb,
19031907
btrfs_init_workers(&fs_info->delayed_workers, "delayed-meta",
19041908
fs_info->thread_pool_size,
19051909
&fs_info->generic_worker);
1910+
btrfs_init_workers(&fs_info->readahead_workers, "readahead",
1911+
fs_info->thread_pool_size,
1912+
&fs_info->generic_worker);
19061913

19071914
/*
19081915
* endios are largely parallel and should have a very
@@ -1913,6 +1920,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
19131920

19141921
fs_info->endio_write_workers.idle_thresh = 2;
19151922
fs_info->endio_meta_write_workers.idle_thresh = 2;
1923+
fs_info->readahead_workers.idle_thresh = 2;
19161924

19171925
btrfs_start_workers(&fs_info->workers, 1);
19181926
btrfs_start_workers(&fs_info->generic_worker, 1);
@@ -1926,6 +1934,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
19261934
btrfs_start_workers(&fs_info->endio_freespace_worker, 1);
19271935
btrfs_start_workers(&fs_info->delayed_workers, 1);
19281936
btrfs_start_workers(&fs_info->caching_workers, 1);
1937+
btrfs_start_workers(&fs_info->readahead_workers, 1);
19291938

19301939
fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super);
19311940
fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages,
@@ -2650,6 +2659,7 @@ int close_ctree(struct btrfs_root *root)
26502659
btrfs_stop_workers(&fs_info->submit_workers);
26512660
btrfs_stop_workers(&fs_info->delayed_workers);
26522661
btrfs_stop_workers(&fs_info->caching_workers);
2662+
btrfs_stop_workers(&fs_info->readahead_workers);
26532663

26542664
btrfs_close_devices(fs_info->fs_devices);
26552665
btrfs_mapping_tree_free(&fs_info->mapping_tree);

fs/btrfs/volumes.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,14 @@ static noinline int device_list_add(const char *path,
366366
}
367367
INIT_LIST_HEAD(&device->dev_alloc_list);
368368

369+
/* init readahead state */
370+
spin_lock_init(&device->reada_lock);
371+
device->reada_curr_zone = NULL;
372+
atomic_set(&device->reada_in_flight, 0);
373+
device->reada_next = 0;
374+
INIT_RADIX_TREE(&device->reada_zones, GFP_NOFS & ~__GFP_WAIT);
375+
INIT_RADIX_TREE(&device->reada_extents, GFP_NOFS & ~__GFP_WAIT);
376+
369377
mutex_lock(&fs_devices->device_list_mutex);
370378
list_add_rcu(&device->dev_list, &fs_devices->devices);
371379
mutex_unlock(&fs_devices->device_list_mutex);

fs/btrfs/volumes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ struct btrfs_device {
9292
struct btrfs_work work;
9393
struct rcu_head rcu;
9494
struct work_struct rcu_work;
95+
96+
/* readahead state */
97+
spinlock_t reada_lock;
98+
atomic_t reada_in_flight;
99+
u64 reada_next;
100+
struct reada_zone *reada_curr_zone;
101+
struct radix_tree_root reada_zones;
102+
struct radix_tree_root reada_extents;
95103
};
96104

97105
struct btrfs_fs_devices {

0 commit comments

Comments
 (0)