Commit 6e88f116 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by David Sterba

btrfs: discard: store async discard delay as ns not as jiffies

Most delay calculations are done in ns or ms, so store
discard_ctl->delay in ms and convert the final delay to jiffies only at
the end.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent e50404a8
...@@ -472,7 +472,7 @@ struct btrfs_discard_ctl { ...@@ -472,7 +472,7 @@ struct btrfs_discard_ctl {
atomic_t discardable_extents; atomic_t discardable_extents;
atomic64_t discardable_bytes; atomic64_t discardable_bytes;
u64 max_discard_size; u64 max_discard_size;
unsigned long delay; u64 delay_ms;
u32 iops_limit; u32 iops_limit;
u32 kbps_limit; u32 kbps_limit;
u64 discard_extent_bytes; u64 discard_extent_bytes;
......
...@@ -355,7 +355,7 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, ...@@ -355,7 +355,7 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl,
block_group = find_next_block_group(discard_ctl, now); block_group = find_next_block_group(discard_ctl, now);
if (block_group) { if (block_group) {
unsigned long delay = discard_ctl->delay; u64 delay = discard_ctl->delay_ms * NSEC_PER_MSEC;
u32 kbps_limit = READ_ONCE(discard_ctl->kbps_limit); u32 kbps_limit = READ_ONCE(discard_ctl->kbps_limit);
/* /*
...@@ -366,9 +366,9 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, ...@@ -366,9 +366,9 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl,
if (kbps_limit && discard_ctl->prev_discard) { if (kbps_limit && discard_ctl->prev_discard) {
u64 bps_limit = ((u64)kbps_limit) * SZ_1K; u64 bps_limit = ((u64)kbps_limit) * SZ_1K;
u64 bps_delay = div64_u64(discard_ctl->prev_discard * u64 bps_delay = div64_u64(discard_ctl->prev_discard *
MSEC_PER_SEC, bps_limit); NSEC_PER_SEC, bps_limit);
delay = max(delay, msecs_to_jiffies(bps_delay)); delay = max(delay, bps_delay);
} }
/* /*
...@@ -378,11 +378,11 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, ...@@ -378,11 +378,11 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl,
if (now < block_group->discard_eligible_time) { if (now < block_group->discard_eligible_time) {
u64 bg_timeout = block_group->discard_eligible_time - now; u64 bg_timeout = block_group->discard_eligible_time - now;
delay = max(delay, nsecs_to_jiffies(bg_timeout)); delay = max(delay, bg_timeout);
} }
mod_delayed_work(discard_ctl->discard_workers, mod_delayed_work(discard_ctl->discard_workers,
&discard_ctl->work, delay); &discard_ctl->work, nsecs_to_jiffies(delay));
} }
out: out:
spin_unlock(&discard_ctl->lock); spin_unlock(&discard_ctl->lock);
...@@ -555,7 +555,7 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl) ...@@ -555,7 +555,7 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl)
delay = clamp(delay, BTRFS_DISCARD_MIN_DELAY_MSEC, delay = clamp(delay, BTRFS_DISCARD_MIN_DELAY_MSEC,
BTRFS_DISCARD_MAX_DELAY_MSEC); BTRFS_DISCARD_MAX_DELAY_MSEC);
discard_ctl->delay = msecs_to_jiffies(delay); discard_ctl->delay_ms = delay;
spin_unlock(&discard_ctl->lock); spin_unlock(&discard_ctl->lock);
} }
...@@ -688,7 +688,7 @@ void btrfs_discard_init(struct btrfs_fs_info *fs_info) ...@@ -688,7 +688,7 @@ void btrfs_discard_init(struct btrfs_fs_info *fs_info)
atomic_set(&discard_ctl->discardable_extents, 0); atomic_set(&discard_ctl->discardable_extents, 0);
atomic64_set(&discard_ctl->discardable_bytes, 0); atomic64_set(&discard_ctl->discardable_bytes, 0);
discard_ctl->max_discard_size = BTRFS_ASYNC_DISCARD_DEFAULT_MAX_SIZE; discard_ctl->max_discard_size = BTRFS_ASYNC_DISCARD_DEFAULT_MAX_SIZE;
discard_ctl->delay = BTRFS_DISCARD_MAX_DELAY_MSEC; discard_ctl->delay_ms = BTRFS_DISCARD_MAX_DELAY_MSEC;
discard_ctl->iops_limit = BTRFS_DISCARD_MAX_IOPS; discard_ctl->iops_limit = BTRFS_DISCARD_MAX_IOPS;
discard_ctl->kbps_limit = 0; discard_ctl->kbps_limit = 0;
discard_ctl->discard_extent_bytes = 0; discard_ctl->discard_extent_bytes = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment