On Mon, Oct 07, 2019 at 04:17:41PM -0400, Dennis Zhou wrote:
> Use the number of discardable extents to help guide our discard delay
> interval. This value is reevaluated every transaction commit.
>
> Signed-off-by: Dennis Zhou <dennis@xxxxxxxxxx>
> ---
> fs/btrfs/ctree.h | 2 ++
> fs/btrfs/discard.c | 31 +++++++++++++++++++++++++++++--
> fs/btrfs/discard.h | 3 +++
> fs/btrfs/extent-tree.c | 4 +++-
> fs/btrfs/sysfs.c | 30 ++++++++++++++++++++++++++++++
> 5 files changed, 67 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 8479ab037812..b0823961d049 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -449,6 +449,8 @@ struct btrfs_discard_ctl {
> struct list_head discard_list[BTRFS_NR_DISCARD_LISTS];
> atomic_t discard_extents;
> atomic64_t discardable_bytes;
> + atomic_t delay;
> + atomic_t iops_limit;
> };
>
> /* delayed seq elem */
> diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c
> index 75a2ff14b3c0..c7afb5f8240d 100644
> --- a/fs/btrfs/discard.c
> +++ b/fs/btrfs/discard.c
> @@ -15,6 +15,11 @@
>
> #define BTRFS_DISCARD_DELAY (300ULL * NSEC_PER_SEC)
>
> +/* target discard delay in milliseconds */
> +#define BTRFS_DISCARD_TARGET_MSEC (6 * 60 * 60ULL * MSEC_PER_SEC)
> +#define BTRFS_DISCARD_MAX_DELAY (10000UL)
> +#define BTRFS_DISCARD_MAX_IOPS (10UL)
> +
> static struct list_head *
> btrfs_get_discard_list(struct btrfs_discard_ctl *discard_ctl,
> struct btrfs_block_group_cache *cache)
> @@ -170,10 +175,12 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl,
>
> cache = find_next_cache(discard_ctl, now);
> if (cache) {
> - u64 delay = 0;
> + u64 delay = atomic_read(&discard_ctl->delay);
>
> if (now < cache->discard_delay)
> - delay = nsecs_to_jiffies(cache->discard_delay - now);
> + delay = max_t(u64, delay,
> + nsecs_to_jiffies(cache->discard_delay -
> + now));
Small nit, instead
delay = nsecs_to_jiffies(cache->discard_delay - now);
delay = max_t(u64, delay,
atomic_read(&discard_ctl->delay);
Looks a little cleaner. Otherwise
Reviewed-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
Thanks,
Josef