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 <dennis@kernel.org> Reviewed-by: David Sterba <dsterba@suse.com> [ update changelog ] Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:

committed by
David Sterba

parent
dfb79ddb13
commit
5dc7c10b87
@@ -819,9 +819,11 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
|
||||
if (ret)
|
||||
goto free_cache;
|
||||
e->bitmap_extents = count_bitmap_extents(ctl, e);
|
||||
if (!btrfs_free_space_trimmed(e))
|
||||
if (!btrfs_free_space_trimmed(e)) {
|
||||
ctl->discardable_extents[BTRFS_STAT_CURR] +=
|
||||
e->bitmap_extents;
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] += e->bytes;
|
||||
}
|
||||
}
|
||||
|
||||
io_ctl_drop_pages(&io_ctl);
|
||||
@@ -1643,8 +1645,10 @@ __unlink_free_space(struct btrfs_free_space_ctl *ctl,
|
||||
rb_erase(&info->offset_index, &ctl->free_space_offset);
|
||||
ctl->free_extents--;
|
||||
|
||||
if (!info->bitmap && !btrfs_free_space_trimmed(info))
|
||||
if (!info->bitmap && !btrfs_free_space_trimmed(info)) {
|
||||
ctl->discardable_extents[BTRFS_STAT_CURR]--;
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] -= info->bytes;
|
||||
}
|
||||
}
|
||||
|
||||
static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
|
||||
@@ -1665,8 +1669,10 @@ static int link_free_space(struct btrfs_free_space_ctl *ctl,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (!info->bitmap && !btrfs_free_space_trimmed(info))
|
||||
if (!info->bitmap && !btrfs_free_space_trimmed(info)) {
|
||||
ctl->discardable_extents[BTRFS_STAT_CURR]++;
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] += info->bytes;
|
||||
}
|
||||
|
||||
ctl->free_space += info->bytes;
|
||||
ctl->free_extents++;
|
||||
@@ -1745,8 +1751,10 @@ static inline void __bitmap_clear_bits(struct btrfs_free_space_ctl *ctl,
|
||||
extent_delta++;
|
||||
|
||||
info->bitmap_extents += extent_delta;
|
||||
if (!btrfs_free_space_trimmed(info))
|
||||
if (!btrfs_free_space_trimmed(info)) {
|
||||
ctl->discardable_extents[BTRFS_STAT_CURR] += extent_delta;
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] -= bytes;
|
||||
}
|
||||
}
|
||||
|
||||
static void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl,
|
||||
@@ -1781,8 +1789,10 @@ static void bitmap_set_bits(struct btrfs_free_space_ctl *ctl,
|
||||
extent_delta--;
|
||||
|
||||
info->bitmap_extents += extent_delta;
|
||||
if (!btrfs_free_space_trimmed(info))
|
||||
if (!btrfs_free_space_trimmed(info)) {
|
||||
ctl->discardable_extents[BTRFS_STAT_CURR] += extent_delta;
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] += bytes;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2053,9 +2063,11 @@ static u64 add_bytes_to_bitmap(struct btrfs_free_space_ctl *ctl,
|
||||
* whole bitmap untrimmed if at any point we add untrimmed regions.
|
||||
*/
|
||||
if (trim_state == BTRFS_TRIM_STATE_UNTRIMMED) {
|
||||
if (btrfs_free_space_trimmed(info))
|
||||
if (btrfs_free_space_trimmed(info)) {
|
||||
ctl->discardable_extents[BTRFS_STAT_CURR] +=
|
||||
info->bitmap_extents;
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] += info->bytes;
|
||||
}
|
||||
info->trim_state = BTRFS_TRIM_STATE_UNTRIMMED;
|
||||
}
|
||||
|
||||
@@ -2713,15 +2725,21 @@ __btrfs_return_cluster_to_free_space(
|
||||
bitmap = (entry->bitmap != NULL);
|
||||
if (!bitmap) {
|
||||
/* Merging treats extents as if they were new */
|
||||
if (!btrfs_free_space_trimmed(entry))
|
||||
if (!btrfs_free_space_trimmed(entry)) {
|
||||
ctl->discardable_extents[BTRFS_STAT_CURR]--;
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] -=
|
||||
entry->bytes;
|
||||
}
|
||||
|
||||
try_merge_free_space(ctl, entry, false);
|
||||
steal_from_bitmap(ctl, entry, false);
|
||||
|
||||
/* As we insert directly, update these statistics */
|
||||
if (!btrfs_free_space_trimmed(entry))
|
||||
if (!btrfs_free_space_trimmed(entry)) {
|
||||
ctl->discardable_extents[BTRFS_STAT_CURR]++;
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] +=
|
||||
entry->bytes;
|
||||
}
|
||||
}
|
||||
tree_insert_offset(&ctl->free_space_offset,
|
||||
entry->offset, &entry->offset_index, bitmap);
|
||||
@@ -3011,6 +3029,8 @@ out:
|
||||
spin_lock(&ctl->tree_lock);
|
||||
|
||||
ctl->free_space -= bytes;
|
||||
if (!entry->bitmap && !btrfs_free_space_trimmed(entry))
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] -= bytes;
|
||||
if (entry->bytes == 0) {
|
||||
ctl->free_extents--;
|
||||
if (entry->bitmap) {
|
||||
@@ -3515,9 +3535,11 @@ static void reset_trimming_bitmap(struct btrfs_free_space_ctl *ctl, u64 offset)
|
||||
spin_lock(&ctl->tree_lock);
|
||||
entry = tree_search_offset(ctl, offset, 1, 0);
|
||||
if (entry) {
|
||||
if (btrfs_free_space_trimmed(entry))
|
||||
if (btrfs_free_space_trimmed(entry)) {
|
||||
ctl->discardable_extents[BTRFS_STAT_CURR] +=
|
||||
entry->bitmap_extents;
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] += entry->bytes;
|
||||
}
|
||||
entry->trim_state = BTRFS_TRIM_STATE_UNTRIMMED;
|
||||
}
|
||||
|
||||
@@ -3531,6 +3553,7 @@ static void end_trimming_bitmap(struct btrfs_free_space_ctl *ctl,
|
||||
entry->trim_state = BTRFS_TRIM_STATE_TRIMMED;
|
||||
ctl->discardable_extents[BTRFS_STAT_CURR] -=
|
||||
entry->bitmap_extents;
|
||||
ctl->discardable_bytes[BTRFS_STAT_CURR] -= entry->bytes;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user