Commit 48ff7083 authored by Omar Sandoval's avatar Omar Sandoval Committed by David Sterba

btrfs: get rid of block group caching progress logic

struct btrfs_caching_ctl::progress and struct
btrfs_block_group::last_byte_to_unpin were previously needed to ensure
that unpin_extent_range() didn't return a range to the free space cache
before the caching thread had a chance to cache that range. However, the
commit "btrfs: fix space cache corruption and potential double
allocations" made it so that we always synchronously cache the block
group at the time that we pin the extent, so this machinery is no longer
necessary.
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarOmar Sandoval <osandov@fb.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 9ed0a72e
...@@ -593,8 +593,6 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) ...@@ -593,8 +593,6 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
if (need_resched() || if (need_resched() ||
rwsem_is_contended(&fs_info->commit_root_sem)) { rwsem_is_contended(&fs_info->commit_root_sem)) {
if (wakeup)
caching_ctl->progress = last;
btrfs_release_path(path); btrfs_release_path(path);
up_read(&fs_info->commit_root_sem); up_read(&fs_info->commit_root_sem);
mutex_unlock(&caching_ctl->mutex); mutex_unlock(&caching_ctl->mutex);
...@@ -618,9 +616,6 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) ...@@ -618,9 +616,6 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
key.objectid = last; key.objectid = last;
key.offset = 0; key.offset = 0;
key.type = BTRFS_EXTENT_ITEM_KEY; key.type = BTRFS_EXTENT_ITEM_KEY;
if (wakeup)
caching_ctl->progress = last;
btrfs_release_path(path); btrfs_release_path(path);
goto next; goto next;
} }
...@@ -655,7 +650,6 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) ...@@ -655,7 +650,6 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
total_found += add_new_free_space(block_group, last, total_found += add_new_free_space(block_group, last,
block_group->start + block_group->length); block_group->start + block_group->length);
caching_ctl->progress = (u64)-1;
out: out:
btrfs_free_path(path); btrfs_free_path(path);
...@@ -725,8 +719,6 @@ static noinline void caching_thread(struct btrfs_work *work) ...@@ -725,8 +719,6 @@ static noinline void caching_thread(struct btrfs_work *work)
} }
#endif #endif
caching_ctl->progress = (u64)-1;
up_read(&fs_info->commit_root_sem); up_read(&fs_info->commit_root_sem);
btrfs_free_excluded_extents(block_group); btrfs_free_excluded_extents(block_group);
mutex_unlock(&caching_ctl->mutex); mutex_unlock(&caching_ctl->mutex);
...@@ -755,7 +747,6 @@ int btrfs_cache_block_group(struct btrfs_block_group *cache, bool wait) ...@@ -755,7 +747,6 @@ int btrfs_cache_block_group(struct btrfs_block_group *cache, bool wait)
mutex_init(&caching_ctl->mutex); mutex_init(&caching_ctl->mutex);
init_waitqueue_head(&caching_ctl->wait); init_waitqueue_head(&caching_ctl->wait);
caching_ctl->block_group = cache; caching_ctl->block_group = cache;
caching_ctl->progress = cache->start;
refcount_set(&caching_ctl->count, 2); refcount_set(&caching_ctl->count, 2);
btrfs_init_work(&caching_ctl->work, caching_thread, NULL, NULL); btrfs_init_work(&caching_ctl->work, caching_thread, NULL, NULL);
...@@ -2075,11 +2066,9 @@ static int read_one_block_group(struct btrfs_fs_info *info, ...@@ -2075,11 +2066,9 @@ static int read_one_block_group(struct btrfs_fs_info *info,
/* Should not have any excluded extents. Just in case, though. */ /* Should not have any excluded extents. Just in case, though. */
btrfs_free_excluded_extents(cache); btrfs_free_excluded_extents(cache);
} else if (cache->length == cache->used) { } else if (cache->length == cache->used) {
cache->last_byte_to_unpin = (u64)-1;
cache->cached = BTRFS_CACHE_FINISHED; cache->cached = BTRFS_CACHE_FINISHED;
btrfs_free_excluded_extents(cache); btrfs_free_excluded_extents(cache);
} else if (cache->used == 0) { } else if (cache->used == 0) {
cache->last_byte_to_unpin = (u64)-1;
cache->cached = BTRFS_CACHE_FINISHED; cache->cached = BTRFS_CACHE_FINISHED;
add_new_free_space(cache, cache->start, add_new_free_space(cache, cache->start,
cache->start + cache->length); cache->start + cache->length);
...@@ -2135,7 +2124,6 @@ static int fill_dummy_bgs(struct btrfs_fs_info *fs_info) ...@@ -2135,7 +2124,6 @@ static int fill_dummy_bgs(struct btrfs_fs_info *fs_info)
/* Fill dummy cache as FULL */ /* Fill dummy cache as FULL */
bg->length = em->len; bg->length = em->len;
bg->flags = map->type; bg->flags = map->type;
bg->last_byte_to_unpin = (u64)-1;
bg->cached = BTRFS_CACHE_FINISHED; bg->cached = BTRFS_CACHE_FINISHED;
bg->used = em->len; bg->used = em->len;
bg->flags = map->type; bg->flags = map->type;
...@@ -2481,7 +2469,6 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran ...@@ -2481,7 +2469,6 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
set_free_space_tree_thresholds(cache); set_free_space_tree_thresholds(cache);
cache->used = bytes_used; cache->used = bytes_used;
cache->flags = type; cache->flags = type;
cache->last_byte_to_unpin = (u64)-1;
cache->cached = BTRFS_CACHE_FINISHED; cache->cached = BTRFS_CACHE_FINISHED;
cache->global_root_id = calculate_global_root_id(fs_info, cache->start); cache->global_root_id = calculate_global_root_id(fs_info, cache->start);
......
...@@ -63,7 +63,6 @@ struct btrfs_caching_control { ...@@ -63,7 +63,6 @@ struct btrfs_caching_control {
wait_queue_head_t wait; wait_queue_head_t wait;
struct btrfs_work work; struct btrfs_work work;
struct btrfs_block_group *block_group; struct btrfs_block_group *block_group;
u64 progress;
refcount_t count; refcount_t count;
}; };
...@@ -115,7 +114,6 @@ struct btrfs_block_group { ...@@ -115,7 +114,6 @@ struct btrfs_block_group {
/* Cache tracking stuff */ /* Cache tracking stuff */
int cached; int cached;
struct btrfs_caching_control *caching_ctl; struct btrfs_caching_control *caching_ctl;
u64 last_byte_to_unpin;
struct btrfs_space_info *space_info; struct btrfs_space_info *space_info;
......
...@@ -2686,13 +2686,8 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info, ...@@ -2686,13 +2686,8 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
len = cache->start + cache->length - start; len = cache->start + cache->length - start;
len = min(len, end + 1 - start); len = min(len, end + 1 - start);
down_read(&fs_info->commit_root_sem); if (return_free_space)
if (start < cache->last_byte_to_unpin && return_free_space) { btrfs_add_free_space(cache, start, len);
u64 add_len = min(len, cache->last_byte_to_unpin - start);
btrfs_add_free_space(cache, start, add_len);
}
up_read(&fs_info->commit_root_sem);
start += len; start += len;
total_unpinned += len; total_unpinned += len;
......
...@@ -1453,8 +1453,6 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl, ...@@ -1453,8 +1453,6 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
ASSERT(key.type == BTRFS_FREE_SPACE_BITMAP_KEY); ASSERT(key.type == BTRFS_FREE_SPACE_BITMAP_KEY);
ASSERT(key.objectid < end && key.objectid + key.offset <= end); ASSERT(key.objectid < end && key.objectid + key.offset <= end);
caching_ctl->progress = key.objectid;
offset = key.objectid; offset = key.objectid;
while (offset < key.objectid + key.offset) { while (offset < key.objectid + key.offset) {
bit = free_space_test_bit(block_group, path, offset); bit = free_space_test_bit(block_group, path, offset);
...@@ -1490,8 +1488,6 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl, ...@@ -1490,8 +1488,6 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
goto out; goto out;
} }
caching_ctl->progress = (u64)-1;
ret = 0; ret = 0;
out: out:
return ret; return ret;
...@@ -1531,8 +1527,6 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl, ...@@ -1531,8 +1527,6 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
ASSERT(key.type == BTRFS_FREE_SPACE_EXTENT_KEY); ASSERT(key.type == BTRFS_FREE_SPACE_EXTENT_KEY);
ASSERT(key.objectid < end && key.objectid + key.offset <= end); ASSERT(key.objectid < end && key.objectid + key.offset <= end);
caching_ctl->progress = key.objectid;
total_found += add_new_free_space(block_group, key.objectid, total_found += add_new_free_space(block_group, key.objectid,
key.objectid + key.offset); key.objectid + key.offset);
if (total_found > CACHING_CTL_WAKE_UP) { if (total_found > CACHING_CTL_WAKE_UP) {
...@@ -1552,8 +1546,6 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl, ...@@ -1552,8 +1546,6 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
goto out; goto out;
} }
caching_ctl->progress = (u64)-1;
ret = 0; ret = 0;
out: out:
return ret; return ret;
......
...@@ -161,7 +161,6 @@ static noinline void switch_commit_roots(struct btrfs_trans_handle *trans) ...@@ -161,7 +161,6 @@ static noinline void switch_commit_roots(struct btrfs_trans_handle *trans)
struct btrfs_transaction *cur_trans = trans->transaction; struct btrfs_transaction *cur_trans = trans->transaction;
struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_root *root, *tmp; struct btrfs_root *root, *tmp;
struct btrfs_caching_control *caching_ctl, *next;
/* /*
* At this point no one can be using this transaction to modify any tree * At this point no one can be using this transaction to modify any tree
...@@ -196,46 +195,6 @@ static noinline void switch_commit_roots(struct btrfs_trans_handle *trans) ...@@ -196,46 +195,6 @@ static noinline void switch_commit_roots(struct btrfs_trans_handle *trans)
} }
spin_unlock(&cur_trans->dropped_roots_lock); spin_unlock(&cur_trans->dropped_roots_lock);
/*
* We have to update the last_byte_to_unpin under the commit_root_sem,
* at the same time we swap out the commit roots.
*
* This is because we must have a real view of the last spot the caching
* kthreads were while caching. Consider the following views of the
* extent tree for a block group
*
* commit root
* +----+----+----+----+----+----+----+
* |\\\\| |\\\\|\\\\| |\\\\|\\\\|
* +----+----+----+----+----+----+----+
* 0 1 2 3 4 5 6 7
*
* new commit root
* +----+----+----+----+----+----+----+
* | | | |\\\\| | |\\\\|
* +----+----+----+----+----+----+----+
* 0 1 2 3 4 5 6 7
*
* If the cache_ctl->progress was at 3, then we are only allowed to
* unpin [0,1) and [2,3], because the caching thread has already
* processed those extents. We are not allowed to unpin [5,6), because
* the caching thread will re-start it's search from 3, and thus find
* the hole from [4,6) to add to the free space cache.
*/
write_lock(&fs_info->block_group_cache_lock);
list_for_each_entry_safe(caching_ctl, next,
&fs_info->caching_block_groups, list) {
struct btrfs_block_group *cache = caching_ctl->block_group;
if (btrfs_block_group_done(cache)) {
cache->last_byte_to_unpin = (u64)-1;
list_del_init(&caching_ctl->list);
btrfs_put_caching_control(caching_ctl);
} else {
cache->last_byte_to_unpin = caching_ctl->progress;
}
}
write_unlock(&fs_info->block_group_cache_lock);
up_write(&fs_info->commit_root_sem); up_write(&fs_info->commit_root_sem);
} }
......
...@@ -1566,7 +1566,6 @@ void btrfs_calc_zone_unusable(struct btrfs_block_group *cache) ...@@ -1566,7 +1566,6 @@ void btrfs_calc_zone_unusable(struct btrfs_block_group *cache)
free = cache->zone_capacity - cache->alloc_offset; free = cache->zone_capacity - cache->alloc_offset;
/* We only need ->free_space in ALLOC_SEQ block groups */ /* We only need ->free_space in ALLOC_SEQ block groups */
cache->last_byte_to_unpin = (u64)-1;
cache->cached = BTRFS_CACHE_FINISHED; cache->cached = BTRFS_CACHE_FINISHED;
cache->free_space_ctl->free_space = free; cache->free_space_ctl->free_space = free;
cache->zone_unusable = unusable; cache->zone_unusable = unusable;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment