@@ -1121,6 +1121,8 @@ struct btrfs_fs_info {
spinlock_t ref_verify_lock;
struct rb_root block_tree;
#endif
+ /* Policy to balance read across mirrored devices */
+ int read_mirror_policy;
};
static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb)
@@ -345,6 +345,7 @@ enum {
#ifdef CONFIG_BTRFS_FS_REF_VERIFY
Opt_ref_verify,
#endif
+ Opt_read_mirror_policy,
Opt_err,
};
@@ -414,6 +415,7 @@ static const match_table_t tokens = {
#ifdef CONFIG_BTRFS_FS_REF_VERIFY
{Opt_ref_verify, "ref_verify"},
#endif
+ {Opt_read_mirror_policy, "read_mirror_policy=%s"},
{Opt_err, NULL},
};
@@ -844,6 +846,14 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
btrfs_set_opt(info->mount_opt, REF_VERIFY);
break;
#endif
+ case Opt_read_mirror_policy:
+ if (strcmp(args[0].from, "pid") == 0) {
+ info->read_mirror_policy =
+ BTRFS_READ_MIRROR_BY_PID;
+ break;
+ }
+ ret = -EINVAL;
+ goto out;
case Opt_err:
btrfs_info(info, "unrecognized mount option '%s'", p);
ret = -EINVAL;
@@ -5219,7 +5219,13 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
else
num_stripes = map->num_stripes;
- preferred_mirror = first + current->pid % num_stripes;
+ switch(fs_info->read_mirror_policy) {
+ case BTRFS_READ_MIRROR_DEFAULT:
+ case BTRFS_READ_MIRROR_BY_PID:
+ default:
+ preferred_mirror = first + current->pid % num_stripes;
+ break;
+ }
if (dev_replace_is_ongoing &&
fs_info->dev_replace.cont_reading_from_srcdev_mode ==
@@ -34,6 +34,11 @@ struct btrfs_pending_bios {
#define btrfs_device_data_ordered_init(device) do { } while (0)
#endif
+enum btrfs_read_mirror_type {
+ BTRFS_READ_MIRROR_DEFAULT,
+ BTRFS_READ_MIRROR_BY_PID,
+};
+
#define BTRFS_DEV_STATE_WRITEABLE (0)
#define BTRFS_DEV_STATE_IN_FS_METADATA (1)
#define BTRFS_DEV_STATE_MISSING (2)
In case of RAID1 and RAID10 devices are mirror-ed, a read IO can pick any device for reading. This choice of picking a device for reading should be configurable. In short not one policy would satisfy all types of workload and configs. So before we add more policies, this patch-set makes existing $pid policy configurable from the mount option. For example.. mount -o read_mirror_policy=pid (which is also default) Signed-off-by: Anand Jain <anand.jain@oracle.com> --- fs/btrfs/ctree.h | 2 ++ fs/btrfs/super.c | 10 ++++++++++ fs/btrfs/volumes.c | 8 +++++++- fs/btrfs/volumes.h | 5 +++++ 4 files changed, 24 insertions(+), 1 deletion(-)