Skip to content

Commit ef9cddf

Browse files
boryaskdave
authored andcommitted
btrfs: reinterpret async discard iops_limit=0 as no delay
Currently, a limit of 0 results in a hard coded 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. CC: [email protected] # 6.2+ Reviewed-by: Neal Gompa <[email protected]> Signed-off-by: Boris Burkov <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent e9f5942 commit ef9cddf

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

fs/btrfs/discard.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
#define BTRFS_DISCARD_DELAY (120ULL * NSEC_PER_SEC)
5757
#define BTRFS_DISCARD_UNUSED_DELAY (10ULL * NSEC_PER_SEC)
5858

59-
/* Target completion latency of discarding all discardable extents */
60-
#define BTRFS_DISCARD_TARGET_MSEC (6 * 60 * 60UL * MSEC_PER_SEC)
6159
#define BTRFS_DISCARD_MIN_DELAY_MSEC (1UL)
6260
#define BTRFS_DISCARD_MAX_DELAY_MSEC (1000UL)
6361
#define BTRFS_DISCARD_MAX_IOPS (1000U)
@@ -577,6 +575,7 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl)
577575
s32 discardable_extents;
578576
s64 discardable_bytes;
579577
u32 iops_limit;
578+
unsigned long min_delay = BTRFS_DISCARD_MIN_DELAY_MSEC;
580579
unsigned long delay;
581580

582581
discardable_extents = atomic_read(&discard_ctl->discardable_extents);
@@ -607,13 +606,19 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl)
607606
}
608607

609608
iops_limit = READ_ONCE(discard_ctl->iops_limit);
610-
if (iops_limit)
609+
610+
if (iops_limit) {
611611
delay = MSEC_PER_SEC / iops_limit;
612-
else
613-
delay = BTRFS_DISCARD_TARGET_MSEC / discardable_extents;
612+
} else {
613+
/*
614+
* Unset iops_limit means go as fast as possible, so allow a
615+
* delay of 0.
616+
*/
617+
delay = 0;
618+
min_delay = 0;
619+
}
614620

615-
delay = clamp(delay, BTRFS_DISCARD_MIN_DELAY_MSEC,
616-
BTRFS_DISCARD_MAX_DELAY_MSEC);
621+
delay = clamp(delay, min_delay, BTRFS_DISCARD_MAX_DELAY_MSEC);
617622
discard_ctl->delay_ms = delay;
618623

619624
spin_unlock(&discard_ctl->lock);

0 commit comments

Comments
 (0)