From 5dc7c10b87474c98116d3438739743cd77263e9f Mon Sep 17 00:00:00 2001 From: Dennis Zhou Date: Fri, 13 Dec 2019 16:22:21 -0800 Subject: btrfs: keep track of discardable_bytes for async discard Keep track of this metric so that we can understand how ahead or behind we are in discarding rate. This uses the same accounting method as discardable_extents, deltas between previous/current values and propagating them up. Signed-off-by: Dennis Zhou Reviewed-by: David Sterba [ update changelog ] Signed-off-by: David Sterba --- fs/btrfs/discard.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'fs/btrfs/discard.c') diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index 99663641abf4..62298a438fa5 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -356,6 +356,7 @@ void btrfs_discard_update_discardable(struct btrfs_block_group *block_group, { struct btrfs_discard_ctl *discard_ctl; s32 extents_delta; + s64 bytes_delta; if (!block_group || !btrfs_test_opt(block_group->fs_info, DISCARD_ASYNC)) return; @@ -369,6 +370,14 @@ void btrfs_discard_update_discardable(struct btrfs_block_group *block_group, ctl->discardable_extents[BTRFS_STAT_PREV] = ctl->discardable_extents[BTRFS_STAT_CURR]; } + + bytes_delta = ctl->discardable_bytes[BTRFS_STAT_CURR] - + ctl->discardable_bytes[BTRFS_STAT_PREV]; + if (bytes_delta) { + atomic64_add(bytes_delta, &discard_ctl->discardable_bytes); + ctl->discardable_bytes[BTRFS_STAT_PREV] = + ctl->discardable_bytes[BTRFS_STAT_CURR]; + } } /** @@ -454,6 +463,7 @@ void btrfs_discard_init(struct btrfs_fs_info *fs_info) INIT_LIST_HEAD(&discard_ctl->discard_list[i]); atomic_set(&discard_ctl->discardable_extents, 0); + atomic64_set(&discard_ctl->discardable_bytes, 0); } void btrfs_discard_cleanup(struct btrfs_fs_info *fs_info) -- cgit v1.2.3