spinlock_t treelog_bg_lock;
u64 treelog_bg;
- /* Data for scheduling made by the "load" read policy */
- u64 __percpu *last_sched_time;
- int __percpu *last_mirror;
-
#ifdef CONFIG_BTRFS_FS_REF_VERIFY
spinlock_t ref_verify_lock;
struct rb_root block_tree;
btrfs_extent_buffer_leak_debug_check(fs_info);
kfree(fs_info->super_copy);
kfree(fs_info->super_for_commit);
- free_percpu(fs_info->last_sched_time);
- free_percpu(fs_info->last_mirror);
kvfree(fs_info);
}
fs_info->bg_reclaim_threshold = BTRFS_DEFAULT_RECLAIM_THRESH;
INIT_WORK(&fs_info->reclaim_bgs_work, btrfs_reclaim_bgs_work);
-
- fs_info->last_sched_time = __alloc_percpu(sizeof(u64), __alignof__(u64));
- fs_info->last_mirror = __alloc_percpu(sizeof(int), __alignof__(int));
}
static int init_mount_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb)
}
BTRFS_ATTR(, generation, btrfs_generation_show);
-static ssize_t btrfs_read_policy_load_duration_show(struct kobject *kobj,
- struct kobj_attribute *a,
- char *buf)
-{
- struct btrfs_fs_devices *fs_devs = to_fs_devs(kobj->parent->parent);
-
- return scnprintf(buf, PAGE_SIZE, "%d\n", fs_devs->read_policy_load_duration);
-}
-
-static ssize_t btrfs_read_policy_load_duration_store(struct kobject *kobj,
- struct kobj_attribute *a,
- const char *buf, size_t len)
-{
- struct btrfs_fs_devices *fs_devs = to_fs_devs(kobj->parent->parent);
- u32 duration;
- int ret;
-
- ret = kstrtou32(buf, 10, &duration);
- if (ret)
- return -EINVAL;
-
- WRITE_ONCE(fs_devs->read_policy_load_duration, duration);
- return len;
-}
-BTRFS_ATTR_RW(read_policy_load, duration, btrfs_read_policy_load_duration_show,
- btrfs_read_policy_load_duration_store);
-
-static ssize_t btrfs_read_policy_load_rotating_inc_show(struct kobject *kobj,
- struct kobj_attribute *a,
- char *buf)
-{
- struct btrfs_fs_devices *fs_devs = to_fs_devs(kobj->parent->parent);
-
- return scnprintf(buf, PAGE_SIZE, "%d\n",
- fs_devs->read_policy_load_rotating_inc);
-}
-
-static ssize_t btrfs_read_policy_load_rotating_inc_store(struct kobject *kobj,
- struct kobj_attribute *a,
- const char *buf,
- size_t len)
-{
- struct btrfs_fs_devices *fs_devs = to_fs_devs(kobj->parent->parent);
- u32 rotating_inc;
- int ret;
-
- ret = kstrtou32(buf, 10, &rotating_inc);
- if (ret)
- return -EINVAL;
-
- WRITE_ONCE(fs_devs->read_policy_load_rotating_inc, rotating_inc);
- return len;
-}
-BTRFS_ATTR_RW(read_policy_load, rotating_inc,
- btrfs_read_policy_load_rotating_inc_show,
- btrfs_read_policy_load_rotating_inc_store);
-
-static struct attribute *read_policy_load_attrs[] = {
- BTRFS_ATTR_PTR(read_policy_load, duration),
- BTRFS_ATTR_PTR(read_policy_load, rotating_inc),
- NULL
-};
-ATTRIBUTE_GROUPS(read_policy_load);
-
-static void btrfs_release_read_policy_load_kobj(struct kobject *kobj)
-{
- struct btrfs_fs_devices *fs_devs = to_fs_devs(kobj->parent);
-
- memset(&fs_devs->read_policy_load_kobj, 0, sizeof(struct kobject));
-}
-
-static struct kobj_type read_policy_load_ktype = {
- .sysfs_ops = &kobj_sysfs_ops,
- .default_groups = read_policy_load_groups,
- .release = btrfs_release_read_policy_load_kobj,
-};
-
-static int btrfs_sysfs_add_read_policy_load(struct btrfs_fs_devices *devices)
-{
- int ret;
-
- ret = kobject_init_and_add(&devices->read_policy_load_kobj,
- &read_policy_load_ktype,
- devices->read_policies_kobj,
- "%s", "load");
- if (ret < 0)
- kobject_put(&devices->read_policy_load_kobj);
-
- return ret;
-}
-
/*
* Look for an exact string @string in @buffer with possible leading or
* trailing whitespace
/* Must follow the order as in enum btrfs_read_policy */
static const char * const btrfs_read_policy_name[] = { "pid", "latency",
- "device", "load" };
+ "device" };
static ssize_t btrfs_read_policy_show(struct kobject *kobj,
struct kobj_attribute *a, char *buf)
static void __btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
{
- if (fs_devs->read_policies_kobj) {
- kobject_del(fs_devs->read_policies_kobj);
- kobject_put(fs_devs->read_policies_kobj);
- fs_devs->read_policies_kobj = NULL;
- }
-
if (fs_devs->devinfo_kobj) {
kobject_del(fs_devs->devinfo_kobj);
kobject_put(fs_devs->devinfo_kobj);
return -ENOMEM;
}
- fs_devs->read_policies_kobj = kobject_create_and_add(
- "read_policies", &fs_devs->fsid_kobj);
- if (!fs_devs->read_policies_kobj) {
- btrfs_err(fs_devs->fs_info,
- "failed to init sysfs read_polivies kobject");
- btrfs_sysfs_remove_fsid(fs_devs);
- return -ENOMEM;
- }
-
- error = btrfs_sysfs_add_read_policy_load(fs_devs);
- if (error)
- return error;
-
return 0;
}
else if (fsid)
memcpy(fs_devs->metadata_uuid, fsid, BTRFS_FSID_SIZE);
- fs_devs->read_policy_load_duration =
- BTRFS_DEFAULT_READ_POLICY_LOAD_DURATION;
- fs_devs->read_policy_load_rotating_inc =
- BTRFS_DEFAULT_READ_POLICY_LOAD_ROTATING_INC;
-
return fs_devs;
}
return first;
}
-static int mirror_load(struct btrfs_fs_info *fs_info,
- struct btrfs_bio_stripe *stripe)
-{
- struct btrfs_device *dev;
- int load;
-
- dev = stripe->dev;
- load = percpu_counter_sum(&dev->inflight);
-
- if (blk_queue_nonrot(dev->bdev->bd_disk->queue))
- return load;
-
- return load + fs_info->fs_devices->read_policy_load_rotating_inc;
-}
-
-static int find_live_mirror_load(struct btrfs_fs_info *fs_info,
- struct map_lookup *map, int first,
- int num_stripes)
-{
- int preferred_mirror;
- u64 last_sched_time;
- int min_load;
- int cur_load;
- u64 duration;
- u64 now;
- int i;
-
- last_sched_time = this_cpu_read(*fs_info->last_sched_time);
- if (last_sched_time != 0) {
- now = ktime_get_ns();
- duration = now - last_sched_time;
-
- if (duration < (NSEC_PER_MSEC *
- fs_info->fs_devices->read_policy_load_duration))
- return this_cpu_read(*fs_info->last_mirror);
- }
-
- preferred_mirror = first;
- min_load = INT_MAX;
-
- for (i = first; i < first + num_stripes; i++) {
- cur_load = mirror_load(fs_info, &map->stripes[i]);
- if (cur_load < min_load) {
- preferred_mirror = i;
- min_load = cur_load;
- }
- }
-
- this_cpu_write(*fs_info->last_sched_time, now);
- this_cpu_write(*fs_info->last_mirror, preferred_mirror);
- return preferred_mirror;
-}
-
static int find_live_mirror(struct btrfs_fs_info *fs_info,
struct map_lookup *map, int first,
int dev_replace_is_ongoing)
case BTRFS_READ_POLICY_PID:
preferred_mirror = first + (unsigned)atomic_inc_return(&rr_counter) % num_stripes;
break;
- case BTRFS_READ_POLICY_LOAD:
- preferred_mirror = find_live_mirror_load(fs_info, map, first,
- num_stripes);
- break;
case BTRFS_READ_POLICY_LATENCY:
preferred_mirror = btrfs_find_best_stripe(fs_info, map, first,
num_stripes);
BTRFS_READ_POLICY_LATENCY,
/* Use the device marked with READ_PREFERRED state */
BTRFS_READ_POLICY_DEVICE,
- /* Use the least loaded mirrors */
- BTRFS_READ_POLICY_LOAD,
BTRFS_NR_READ_POLICY,
};
-/* Default duration in the load read policy (100 ms) */
-#define BTRFS_DEFAULT_READ_POLICY_LOAD_DURATION 100
-/*
- * Default value by which the load of rotational disks is increased, to bias
- * them in favor of non-rotationnal disks.
- */
-#define BTRFS_DEFAULT_READ_POLICY_LOAD_ROTATING_INC 0
-
struct btrfs_fs_devices {
u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
u8 metadata_uuid[BTRFS_FSID_SIZE];
struct kobject fsid_kobj;
struct kobject *devices_kobj;
struct kobject *devinfo_kobj;
- struct kobject *read_policies_kobj;
- struct kobject read_policy_load_kobj;
struct completion kobj_unregister;
enum btrfs_chunk_allocation_policy chunk_alloc_policy;
/* Policy used to read the mirrored stripes */
enum btrfs_read_policy read_policy;
-
- /* Configuration specific for the load read policy */
- u32 read_policy_load_duration;
- u32 read_policy_load_rotating_inc;
};
#define BTRFS_BIO_INLINE_CSUM_SIZE 64