static struct kmem_cache *btrfs_free_space_cachep;
static struct kmem_cache *btrfs_free_space_bitmap_cachep;
-struct btrfs_trim_range {
- u64 start;
- u64 bytes;
- struct list_head list;
-};
-
static int link_free_space(struct btrfs_free_space_ctl *ctl,
struct btrfs_free_space *info);
static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
spin_lock_init(&ctl->tree_lock);
ctl->block_group = block_group;
ctl->free_space_bytes = RB_ROOT_CACHED;
- INIT_LIST_HEAD(&ctl->trimming_ranges);
- mutex_init(&ctl->cache_writeout_mutex);
/*
* we only want to have 32k of ram per block group for keeping
static int do_trimming(struct btrfs_block_group *block_group,
u64 *total_trimmed, u64 start, u64 bytes,
u64 reserved_start, u64 reserved_bytes,
- enum btrfs_trim_state reserved_trim_state,
- struct btrfs_trim_range *trim_entry)
+ enum btrfs_trim_state reserved_trim_state)
{
struct btrfs_space_info *space_info = block_group->space_info;
struct btrfs_fs_info *fs_info = block_group->fs_info;
- struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
int ret;
bool bg_ro;
const u64 end = start + bytes;
trim_state = BTRFS_TRIM_STATE_TRIMMED;
}
- mutex_lock(&ctl->cache_writeout_mutex);
if (reserved_start < start)
__btrfs_add_free_space(block_group, reserved_start,
start - reserved_start,
__btrfs_add_free_space(block_group, end, reserved_end - end,
reserved_trim_state);
__btrfs_add_free_space(block_group, start, bytes, trim_state);
- list_del(&trim_entry->list);
- mutex_unlock(&ctl->cache_writeout_mutex);
if (!bg_ro) {
spin_lock(&space_info->lock);
const u64 max_discard_size = READ_ONCE(discard_ctl->max_discard_size);
while (start < end) {
- struct btrfs_trim_range trim_entry;
-
- mutex_lock(&ctl->cache_writeout_mutex);
spin_lock(&ctl->tree_lock);
if (ctl->free_space < minlen)
bytes = entry->bytes;
if (bytes < minlen) {
spin_unlock(&ctl->tree_lock);
- mutex_unlock(&ctl->cache_writeout_mutex);
goto next;
}
unlink_free_space(ctl, entry, true);
bytes = min(extent_start + extent_bytes, end) - start;
if (bytes < minlen) {
spin_unlock(&ctl->tree_lock);
- mutex_unlock(&ctl->cache_writeout_mutex);
goto next;
}
}
spin_unlock(&ctl->tree_lock);
- trim_entry.start = extent_start;
- trim_entry.bytes = extent_bytes;
- list_add_tail(&trim_entry.list, &ctl->trimming_ranges);
- mutex_unlock(&ctl->cache_writeout_mutex);
ret = do_trimming(block_group, total_trimmed, start, bytes,
- extent_start, extent_bytes, extent_trim_state,
- &trim_entry);
+ extent_start, extent_bytes, extent_trim_state);
if (ret) {
block_group->discard_cursor = start + bytes;
break;
out_unlock:
block_group->discard_cursor = btrfs_block_group_end(block_group);
spin_unlock(&ctl->tree_lock);
- mutex_unlock(&ctl->cache_writeout_mutex);
return ret;
}
while (offset < end) {
bool next_bitmap = false;
- struct btrfs_trim_range trim_entry;
- mutex_lock(&ctl->cache_writeout_mutex);
spin_lock(&ctl->tree_lock);
if (ctl->free_space < minlen) {
block_group->discard_cursor =
btrfs_block_group_end(block_group);
spin_unlock(&ctl->tree_lock);
- mutex_unlock(&ctl->cache_writeout_mutex);
break;
}
if (!entry || (async && minlen && start == offset &&
btrfs_free_space_trimmed(entry))) {
spin_unlock(&ctl->tree_lock);
- mutex_unlock(&ctl->cache_writeout_mutex);
next_bitmap = true;
goto next;
}
else
entry->trim_state = BTRFS_TRIM_STATE_UNTRIMMED;
spin_unlock(&ctl->tree_lock);
- mutex_unlock(&ctl->cache_writeout_mutex);
next_bitmap = true;
goto next;
}
*/
if (async && *total_trimmed) {
spin_unlock(&ctl->tree_lock);
- mutex_unlock(&ctl->cache_writeout_mutex);
return ret;
}
bytes = min(bytes, end - start);
if (bytes < minlen || (async && maxlen && bytes > maxlen)) {
spin_unlock(&ctl->tree_lock);
- mutex_unlock(&ctl->cache_writeout_mutex);
goto next;
}
free_bitmap(ctl, entry);
spin_unlock(&ctl->tree_lock);
- trim_entry.start = start;
- trim_entry.bytes = bytes;
- list_add_tail(&trim_entry.list, &ctl->trimming_ranges);
- mutex_unlock(&ctl->cache_writeout_mutex);
ret = do_trimming(block_group, total_trimmed, start, bytes,
- start, bytes, 0, &trim_entry);
+ start, bytes, 0);
if (ret) {
reset_trimming_bitmap(ctl, offset);
block_group->discard_cursor =