* [PATCH 0/2] btrfs: adjust async discard tuning @ 2023-04-05 16:20 Boris Burkov 2023-04-05 16:20 ` [PATCH 1/2] btrfs: set default discard iops_limit to 1000 Boris Burkov 2023-04-05 16:20 ` [PATCH 2/2] btrfs: reinterpret async discard iops_limit=0 as no delay Boris Burkov 0 siblings, 2 replies; 5+ messages in thread From: Boris Burkov @ 2023-04-05 16:20 UTC (permalink / raw) To: linux-btrfs, kernel-team Since discard=async became the implicit default in btrfs in the 6.2 kernel, there have been numerous complaints about discard being too spread out on workstation systems. This results in situations like a users drive not being idle for an unexpectedly long period of time. This is caused by a relatively low default iops limit of 10, so this series raises the default limit to 1000 (1ms delay) and modifies a weird fallback behavior for limit=0 to be interpreted as unlimited. Link: https://lore.kernel.org/linux-btrfs/ZCxKc5ZzP3Np71IC@infradead.org/T/#m6ebdeb475809ed7714b21b8143103fb7e5a966da Link: https://bugzilla.redhat.com/show_bug.cgi?id=2182228 Link: https://www.reddit.com/r/archlinux/comments/121htxn/btrfs_discard_storm_on_62x_kernel/ Boris Burkov (2): btrfs: set default discard iops_limit to 1000 btrfs: reinterpret async discard iops_limit=0 as no delay fs/btrfs/discard.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) -- 2.40.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] btrfs: set default discard iops_limit to 1000 2023-04-05 16:20 [PATCH 0/2] btrfs: adjust async discard tuning Boris Burkov @ 2023-04-05 16:20 ` Boris Burkov 2023-04-05 17:34 ` Roman Mamedov 2023-04-05 16:20 ` [PATCH 2/2] btrfs: reinterpret async discard iops_limit=0 as no delay Boris Burkov 1 sibling, 1 reply; 5+ messages in thread From: Boris Burkov @ 2023-04-05 16:20 UTC (permalink / raw) To: linux-btrfs, kernel-team Previously, the default was a relatively conservative 10. This results in a 100ms delay, so with ~300 discards in a commit, it takes the full 30s till the next commit to finish the discards. On a workstation, this results in the disk never going idle, wasting power/battery, etc. Set the default to 1000, which results in using the smallest possible delay, currently, which is 1ms. This has shown to not pathologically keep the disk busy by the original reporter. Link: https://lore.kernel.org/linux-btrfs/ZCxKc5ZzP3Np71IC@infradead.org/T/#m6ebdeb475809ed7714b21b8143103fb7e5a966da Signed-off-by: Boris Burkov <boris@bur.io> --- fs/btrfs/discard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index 317aeff6c1da..aef789bcff8f 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -60,7 +60,7 @@ #define BTRFS_DISCARD_TARGET_MSEC (6 * 60 * 60UL * MSEC_PER_SEC) #define BTRFS_DISCARD_MIN_DELAY_MSEC (1UL) #define BTRFS_DISCARD_MAX_DELAY_MSEC (1000UL) -#define BTRFS_DISCARD_MAX_IOPS (10U) +#define BTRFS_DISCARD_MAX_IOPS (10000U) /* Monotonically decreasing minimum length filters after index 0 */ static int discard_minlen[BTRFS_NR_DISCARD_LISTS] = { -- 2.40.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] btrfs: set default discard iops_limit to 1000 2023-04-05 16:20 ` [PATCH 1/2] btrfs: set default discard iops_limit to 1000 Boris Burkov @ 2023-04-05 17:34 ` Roman Mamedov 2023-04-05 18:46 ` Boris Burkov 0 siblings, 1 reply; 5+ messages in thread From: Roman Mamedov @ 2023-04-05 17:34 UTC (permalink / raw) To: Boris Burkov; +Cc: linux-btrfs, kernel-team On Wed, 5 Apr 2023 09:20:32 -0700 Boris Burkov <boris@bur.io> wrote: > Previously, the default was a relatively conservative 10. This results > in a 100ms delay, so with ~300 discards in a commit, it takes the full > 30s till the next commit to finish the discards. On a workstation, this > results in the disk never going idle, wasting power/battery, etc. > > Set the default to 1000, which results in using the smallest possible > delay, currently, which is 1ms. This has shown to not pathologically > keep the disk busy by the original reporter. > > Link: https://lore.kernel.org/linux-btrfs/ZCxKc5ZzP3Np71IC@infradead.org/T/#m6ebdeb475809ed7714b21b8143103fb7e5a966da > Signed-off-by: Boris Burkov <boris@bur.io> > --- > fs/btrfs/discard.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c > index 317aeff6c1da..aef789bcff8f 100644 > --- a/fs/btrfs/discard.c > +++ b/fs/btrfs/discard.c > @@ -60,7 +60,7 @@ > #define BTRFS_DISCARD_TARGET_MSEC (6 * 60 * 60UL * MSEC_PER_SEC) > #define BTRFS_DISCARD_MIN_DELAY_MSEC (1UL) > #define BTRFS_DISCARD_MAX_DELAY_MSEC (1000UL) > -#define BTRFS_DISCARD_MAX_IOPS (10U) > +#define BTRFS_DISCARD_MAX_IOPS (10000U) But the patch sets 10000? > > /* Monotonically decreasing minimum length filters after index 0 */ > static int discard_minlen[BTRFS_NR_DISCARD_LISTS] = { -- With respect, Roman ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] btrfs: set default discard iops_limit to 1000 2023-04-05 17:34 ` Roman Mamedov @ 2023-04-05 18:46 ` Boris Burkov 0 siblings, 0 replies; 5+ messages in thread From: Boris Burkov @ 2023-04-05 18:46 UTC (permalink / raw) To: Roman Mamedov; +Cc: linux-btrfs, kernel-team On Wed, Apr 05, 2023 at 10:34:49PM +0500, Roman Mamedov wrote: > On Wed, 5 Apr 2023 09:20:32 -0700 > Boris Burkov <boris@bur.io> wrote: > > > Previously, the default was a relatively conservative 10. This results > > in a 100ms delay, so with ~300 discards in a commit, it takes the full > > 30s till the next commit to finish the discards. On a workstation, this > > results in the disk never going idle, wasting power/battery, etc. > > > > Set the default to 1000, which results in using the smallest possible > > delay, currently, which is 1ms. This has shown to not pathologically > > keep the disk busy by the original reporter. > > > > Link: https://lore.kernel.org/linux-btrfs/ZCxKc5ZzP3Np71IC@infradead.org/T/#m6ebdeb475809ed7714b21b8143103fb7e5a966da > > Signed-off-by: Boris Burkov <boris@bur.io> > > --- > > fs/btrfs/discard.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c > > index 317aeff6c1da..aef789bcff8f 100644 > > --- a/fs/btrfs/discard.c > > +++ b/fs/btrfs/discard.c > > @@ -60,7 +60,7 @@ > > #define BTRFS_DISCARD_TARGET_MSEC (6 * 60 * 60UL * MSEC_PER_SEC) > > #define BTRFS_DISCARD_MIN_DELAY_MSEC (1UL) > > #define BTRFS_DISCARD_MAX_DELAY_MSEC (1000UL) > > -#define BTRFS_DISCARD_MAX_IOPS (10U) > > +#define BTRFS_DISCARD_MAX_IOPS (10000U) > > But the patch sets 10000? Oops. Thanks! ... Just testing the clamping? I did run the code and observe 100ms delays between workfn runs, for what it's worth, so it "should be fine" but I'll resend setting it to 1k properly. > > > > > /* Monotonically decreasing minimum length filters after index 0 */ > > static int discard_minlen[BTRFS_NR_DISCARD_LISTS] = { > > > -- > With respect, > Roman ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] btrfs: reinterpret async discard iops_limit=0 as no delay 2023-04-05 16:20 [PATCH 0/2] btrfs: adjust async discard tuning Boris Burkov 2023-04-05 16:20 ` [PATCH 1/2] btrfs: set default discard iops_limit to 1000 Boris Burkov @ 2023-04-05 16:20 ` Boris Burkov 1 sibling, 0 replies; 5+ messages in thread From: Boris Burkov @ 2023-04-05 16:20 UTC (permalink / raw) To: linux-btrfs, kernel-team Currently, a limit of 0 results in a hardcoded metering over 6 hours. Since the default is a set limit, I suspect no one truly depends on this rather arbitrary setting. Repurpose it for an arguably more useful "unlimited" mode, where the delay is 0. Note that if block groups are too new, or go fully empty, there is still a delay associated with those conditions. Those delays implement heuristics for not trimming a region we are relatively likely to fully overwrite soon. Signed-off-by: Boris Burkov <boris@bur.io> --- fs/btrfs/discard.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index aef789bcff8f..ac419ce9ab0a 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -56,8 +56,6 @@ #define BTRFS_DISCARD_DELAY (120ULL * NSEC_PER_SEC) #define BTRFS_DISCARD_UNUSED_DELAY (10ULL * NSEC_PER_SEC) -/* Target completion latency of discarding all discardable extents */ -#define BTRFS_DISCARD_TARGET_MSEC (6 * 60 * 60UL * MSEC_PER_SEC) #define BTRFS_DISCARD_MIN_DELAY_MSEC (1UL) #define BTRFS_DISCARD_MAX_DELAY_MSEC (1000UL) #define BTRFS_DISCARD_MAX_IOPS (10000U) @@ -577,6 +575,7 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl) s32 discardable_extents; s64 discardable_bytes; u32 iops_limit; + unsigned long min_delay = BTRFS_DISCARD_MIN_DELAY_MSEC; unsigned long delay; discardable_extents = atomic_read(&discard_ctl->discardable_extents); @@ -607,13 +606,16 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl) } iops_limit = READ_ONCE(discard_ctl->iops_limit); - if (iops_limit) + + if (iops_limit) { delay = MSEC_PER_SEC / iops_limit; - else - delay = BTRFS_DISCARD_TARGET_MSEC / discardable_extents; + } else { + /* unset iops_limit means go as fast as possible, so allow a delay of 0 */ + delay = 0; + min_delay = 0; + } - delay = clamp(delay, BTRFS_DISCARD_MIN_DELAY_MSEC, - BTRFS_DISCARD_MAX_DELAY_MSEC); + delay = clamp(delay, min_delay, BTRFS_DISCARD_MAX_DELAY_MSEC); discard_ctl->delay_ms = delay; spin_unlock(&discard_ctl->lock); -- 2.40.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-04-05 18:46 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-04-05 16:20 [PATCH 0/2] btrfs: adjust async discard tuning Boris Burkov 2023-04-05 16:20 ` [PATCH 1/2] btrfs: set default discard iops_limit to 1000 Boris Burkov 2023-04-05 17:34 ` Roman Mamedov 2023-04-05 18:46 ` Boris Burkov 2023-04-05 16:20 ` [PATCH 2/2] btrfs: reinterpret async discard iops_limit=0 as no delay Boris Burkov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox