On Fri, Dec 13, 2019 at 04:22:23PM -0800, Dennis Zhou wrote:
> Provide an ability to rate limit based on mbps in addition to the iops
> delay calculated from number of discardable extents.
>
> Signed-off-by: Dennis Zhou <dennis@xxxxxxxxxx>
> ---
> fs/btrfs/ctree.h | 2 ++
> fs/btrfs/discard.c | 18 ++++++++++++++++++
> fs/btrfs/sysfs.c | 31 +++++++++++++++++++++++++++++++
> 3 files changed, 51 insertions(+)
>
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 98979566e281..1b2dae5962de 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -467,10 +467,12 @@ struct btrfs_discard_ctl {
> spinlock_t lock;
> struct btrfs_block_group *block_group;
> struct list_head discard_list[BTRFS_NR_DISCARD_LISTS];
> + u64 prev_discard;
> atomic_t discardable_extents;
> atomic64_t discardable_bytes;
> u32 delay;
> u32 iops_limit;
> + u64 bps_limit;
I think this could be u32, which makes it 4G per second. Byte
granularity is IMO not necessary so it could be KiB/sec instead and it
would be future safe with maximum limit of 4TiB/sec.