Skip to content

Commit 33fd2f7

Browse files
asjkdave
authored andcommitted
btrfs: create read policy framework
As of now, we use the pid method to read striped mirrored data, which means process id determines the stripe id to read. This type of routing typically helps in a system with many small independent processes tying to read random data. On the other hand, the pid based read IO policy is inefficient because if there is a single process trying to read a large file, the overall disk bandwidth remains underutilized. So this patch introduces a read policy framework so that we could add more read policies, such as IO routing based on the device's wait-queue or manual when we have a read-preferred device or a policy based on the target storage caching. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Anand Jain <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent aaefed2 commit 33fd2f7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

fs/btrfs/volumes.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
12171217
fs_devices->latest_bdev = latest_dev->bdev;
12181218
fs_devices->total_rw_bytes = 0;
12191219
fs_devices->chunk_alloc_policy = BTRFS_CHUNK_ALLOC_REGULAR;
1220+
fs_devices->read_policy = BTRFS_READ_POLICY_PID;
12201221

12211222
return 0;
12221223
}
@@ -5479,7 +5480,18 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
54795480
else
54805481
num_stripes = map->num_stripes;
54815482

5482-
preferred_mirror = first + current->pid % num_stripes;
5483+
switch (fs_info->fs_devices->read_policy) {
5484+
default:
5485+
/* Shouldn't happen, just warn and use pid instead of failing */
5486+
btrfs_warn_rl(fs_info,
5487+
"unknown read_policy type %u, reset to pid",
5488+
fs_info->fs_devices->read_policy);
5489+
fs_info->fs_devices->read_policy = BTRFS_READ_POLICY_PID;
5490+
fallthrough;
5491+
case BTRFS_READ_POLICY_PID:
5492+
preferred_mirror = first + (current->pid % num_stripes);
5493+
break;
5494+
}
54835495

54845496
if (dev_replace_is_ongoing &&
54855497
fs_info->dev_replace.cont_reading_from_srcdev_mode ==

fs/btrfs/volumes.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ enum btrfs_chunk_allocation_policy {
211211
BTRFS_CHUNK_ALLOC_REGULAR,
212212
};
213213

214+
/*
215+
* Read policies for mirrored block group profiles, read picks the stripe based
216+
* on these policies.
217+
*/
218+
enum btrfs_read_policy {
219+
/* Use process PID to choose the stripe */
220+
BTRFS_READ_POLICY_PID,
221+
BTRFS_NR_READ_POLICY,
222+
};
223+
214224
struct btrfs_fs_devices {
215225
u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
216226
u8 metadata_uuid[BTRFS_FSID_SIZE];
@@ -264,6 +274,9 @@ struct btrfs_fs_devices {
264274
struct completion kobj_unregister;
265275

266276
enum btrfs_chunk_allocation_policy chunk_alloc_policy;
277+
278+
/* Policy used to read the mirrored stripes */
279+
enum btrfs_read_policy read_policy;
267280
};
268281

269282
#define BTRFS_BIO_INLINE_CSUM_SIZE 64

0 commit comments

Comments
 (0)