diff options
author | Dennis Zhou <dennis@kernel.org> | 2020-01-02 22:26:38 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2020-01-20 16:40:59 +0100 |
commit | 19b2a2c71979f849cadc33af3577f739cc95e1f0 (patch) | |
tree | d39430f1c2faac2d4bb1a5207ff05f0b73a541c6 /fs/btrfs/free-space-cache.c | |
parent | btrfs: limit max discard size for async discard (diff) | |
download | linux-19b2a2c71979f849cadc33af3577f739cc95e1f0.tar.xz linux-19b2a2c71979f849cadc33af3577f739cc95e1f0.zip |
btrfs: make max async discard size tunable
Expose max_discard_size as a tunable via sysfs and switch the current
fixed maximum to the default value.
Signed-off-by: Dennis Zhou <dennis@kernel.org>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/free-space-cache.c')
-rw-r--r-- | fs/btrfs/free-space-cache.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 438043aab6fb..db90bea30a8d 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -3428,6 +3428,8 @@ static int trim_no_bitmap(struct btrfs_block_group *block_group, u64 *total_trimmed, u64 start, u64 end, u64 minlen, bool async) { + struct btrfs_discard_ctl *discard_ctl = + &block_group->fs_info->discard_ctl; struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; struct btrfs_free_space *entry; struct rb_node *node; @@ -3436,6 +3438,7 @@ static int trim_no_bitmap(struct btrfs_block_group *block_group, u64 extent_bytes; enum btrfs_trim_state extent_trim_state; u64 bytes; + const u64 max_discard_size = READ_ONCE(discard_ctl->max_discard_size); while (start < end) { struct btrfs_trim_range trim_entry; @@ -3475,11 +3478,11 @@ static int trim_no_bitmap(struct btrfs_block_group *block_group, goto next; } unlink_free_space(ctl, entry); - if (bytes > BTRFS_ASYNC_DISCARD_MAX_SIZE) { - bytes = BTRFS_ASYNC_DISCARD_MAX_SIZE; - extent_bytes = BTRFS_ASYNC_DISCARD_MAX_SIZE; - entry->offset += BTRFS_ASYNC_DISCARD_MAX_SIZE; - entry->bytes -= BTRFS_ASYNC_DISCARD_MAX_SIZE; + if (max_discard_size && bytes > max_discard_size) { + bytes = max_discard_size; + extent_bytes = max_discard_size; + entry->offset += max_discard_size; + entry->bytes -= max_discard_size; link_free_space(ctl, entry); } else { kmem_cache_free(btrfs_free_space_cachep, entry); @@ -3584,12 +3587,15 @@ static int trim_bitmaps(struct btrfs_block_group *block_group, u64 *total_trimmed, u64 start, u64 end, u64 minlen, bool async) { + struct btrfs_discard_ctl *discard_ctl = + &block_group->fs_info->discard_ctl; struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; struct btrfs_free_space *entry; int ret = 0; int ret2; u64 bytes; u64 offset = offset_to_bitmap(ctl, start); + const u64 max_discard_size = READ_ONCE(discard_ctl->max_discard_size); while (offset < end) { bool next_bitmap = false; @@ -3659,8 +3665,8 @@ static int trim_bitmaps(struct btrfs_block_group *block_group, goto next; } - if (async && bytes > BTRFS_ASYNC_DISCARD_MAX_SIZE) - bytes = BTRFS_ASYNC_DISCARD_MAX_SIZE; + if (async && max_discard_size && bytes > max_discard_size) + bytes = max_discard_size; bitmap_clear_bits(ctl, entry, start, bytes); if (entry->bytes == 0) |