Skip to content

Commit 48ff708

Browse files
osandovkdave
authored andcommitted
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: Filipe Manana <[email protected]> Signed-off-by: Omar Sandoval <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 9ed0a72 commit 48ff708

File tree

6 files changed

+2
-72
lines changed

6 files changed

+2
-72
lines changed

fs/btrfs/block-group.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,6 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
593593

594594
if (need_resched() ||
595595
rwsem_is_contended(&fs_info->commit_root_sem)) {
596-
if (wakeup)
597-
caching_ctl->progress = last;
598596
btrfs_release_path(path);
599597
up_read(&fs_info->commit_root_sem);
600598
mutex_unlock(&caching_ctl->mutex);
@@ -618,9 +616,6 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
618616
key.objectid = last;
619617
key.offset = 0;
620618
key.type = BTRFS_EXTENT_ITEM_KEY;
621-
622-
if (wakeup)
623-
caching_ctl->progress = last;
624619
btrfs_release_path(path);
625620
goto next;
626621
}
@@ -655,7 +650,6 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
655650

656651
total_found += add_new_free_space(block_group, last,
657652
block_group->start + block_group->length);
658-
caching_ctl->progress = (u64)-1;
659653

660654
out:
661655
btrfs_free_path(path);
@@ -725,8 +719,6 @@ static noinline void caching_thread(struct btrfs_work *work)
725719
}
726720
#endif
727721

728-
caching_ctl->progress = (u64)-1;
729-
730722
up_read(&fs_info->commit_root_sem);
731723
btrfs_free_excluded_extents(block_group);
732724
mutex_unlock(&caching_ctl->mutex);
@@ -755,7 +747,6 @@ int btrfs_cache_block_group(struct btrfs_block_group *cache, bool wait)
755747
mutex_init(&caching_ctl->mutex);
756748
init_waitqueue_head(&caching_ctl->wait);
757749
caching_ctl->block_group = cache;
758-
caching_ctl->progress = cache->start;
759750
refcount_set(&caching_ctl->count, 2);
760751
btrfs_init_work(&caching_ctl->work, caching_thread, NULL, NULL);
761752

@@ -2075,11 +2066,9 @@ static int read_one_block_group(struct btrfs_fs_info *info,
20752066
/* Should not have any excluded extents. Just in case, though. */
20762067
btrfs_free_excluded_extents(cache);
20772068
} else if (cache->length == cache->used) {
2078-
cache->last_byte_to_unpin = (u64)-1;
20792069
cache->cached = BTRFS_CACHE_FINISHED;
20802070
btrfs_free_excluded_extents(cache);
20812071
} else if (cache->used == 0) {
2082-
cache->last_byte_to_unpin = (u64)-1;
20832072
cache->cached = BTRFS_CACHE_FINISHED;
20842073
add_new_free_space(cache, cache->start,
20852074
cache->start + cache->length);
@@ -2135,7 +2124,6 @@ static int fill_dummy_bgs(struct btrfs_fs_info *fs_info)
21352124
/* Fill dummy cache as FULL */
21362125
bg->length = em->len;
21372126
bg->flags = map->type;
2138-
bg->last_byte_to_unpin = (u64)-1;
21392127
bg->cached = BTRFS_CACHE_FINISHED;
21402128
bg->used = em->len;
21412129
bg->flags = map->type;
@@ -2481,7 +2469,6 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
24812469
set_free_space_tree_thresholds(cache);
24822470
cache->used = bytes_used;
24832471
cache->flags = type;
2484-
cache->last_byte_to_unpin = (u64)-1;
24852472
cache->cached = BTRFS_CACHE_FINISHED;
24862473
cache->global_root_id = calculate_global_root_id(fs_info, cache->start);
24872474

fs/btrfs/block-group.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ struct btrfs_caching_control {
6363
wait_queue_head_t wait;
6464
struct btrfs_work work;
6565
struct btrfs_block_group *block_group;
66-
u64 progress;
6766
refcount_t count;
6867
};
6968

@@ -115,7 +114,6 @@ struct btrfs_block_group {
115114
/* Cache tracking stuff */
116115
int cached;
117116
struct btrfs_caching_control *caching_ctl;
118-
u64 last_byte_to_unpin;
119117

120118
struct btrfs_space_info *space_info;
121119

fs/btrfs/extent-tree.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,13 +2686,8 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
26862686
len = cache->start + cache->length - start;
26872687
len = min(len, end + 1 - start);
26882688

2689-
down_read(&fs_info->commit_root_sem);
2690-
if (start < cache->last_byte_to_unpin && return_free_space) {
2691-
u64 add_len = min(len, cache->last_byte_to_unpin - start);
2692-
2693-
btrfs_add_free_space(cache, start, add_len);
2694-
}
2695-
up_read(&fs_info->commit_root_sem);
2689+
if (return_free_space)
2690+
btrfs_add_free_space(cache, start, len);
26962691

26972692
start += len;
26982693
total_unpinned += len;

fs/btrfs/free-space-tree.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,6 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
14531453
ASSERT(key.type == BTRFS_FREE_SPACE_BITMAP_KEY);
14541454
ASSERT(key.objectid < end && key.objectid + key.offset <= end);
14551455

1456-
caching_ctl->progress = key.objectid;
1457-
14581456
offset = key.objectid;
14591457
while (offset < key.objectid + key.offset) {
14601458
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,
14901488
goto out;
14911489
}
14921490

1493-
caching_ctl->progress = (u64)-1;
1494-
14951491
ret = 0;
14961492
out:
14971493
return ret;
@@ -1531,8 +1527,6 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
15311527
ASSERT(key.type == BTRFS_FREE_SPACE_EXTENT_KEY);
15321528
ASSERT(key.objectid < end && key.objectid + key.offset <= end);
15331529

1534-
caching_ctl->progress = key.objectid;
1535-
15361530
total_found += add_new_free_space(block_group, key.objectid,
15371531
key.objectid + key.offset);
15381532
if (total_found > CACHING_CTL_WAKE_UP) {
@@ -1552,8 +1546,6 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
15521546
goto out;
15531547
}
15541548

1555-
caching_ctl->progress = (u64)-1;
1556-
15571549
ret = 0;
15581550
out:
15591551
return ret;

fs/btrfs/transaction.c

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ static noinline void switch_commit_roots(struct btrfs_trans_handle *trans)
161161
struct btrfs_transaction *cur_trans = trans->transaction;
162162
struct btrfs_fs_info *fs_info = trans->fs_info;
163163
struct btrfs_root *root, *tmp;
164-
struct btrfs_caching_control *caching_ctl, *next;
165164

166165
/*
167166
* 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)
196195
}
197196
spin_unlock(&cur_trans->dropped_roots_lock);
198197

199-
/*
200-
* We have to update the last_byte_to_unpin under the commit_root_sem,
201-
* at the same time we swap out the commit roots.
202-
*
203-
* This is because we must have a real view of the last spot the caching
204-
* kthreads were while caching. Consider the following views of the
205-
* extent tree for a block group
206-
*
207-
* commit root
208-
* +----+----+----+----+----+----+----+
209-
* |\\\\| |\\\\|\\\\| |\\\\|\\\\|
210-
* +----+----+----+----+----+----+----+
211-
* 0 1 2 3 4 5 6 7
212-
*
213-
* new commit root
214-
* +----+----+----+----+----+----+----+
215-
* | | | |\\\\| | |\\\\|
216-
* +----+----+----+----+----+----+----+
217-
* 0 1 2 3 4 5 6 7
218-
*
219-
* If the cache_ctl->progress was at 3, then we are only allowed to
220-
* unpin [0,1) and [2,3], because the caching thread has already
221-
* processed those extents. We are not allowed to unpin [5,6), because
222-
* the caching thread will re-start it's search from 3, and thus find
223-
* the hole from [4,6) to add to the free space cache.
224-
*/
225-
write_lock(&fs_info->block_group_cache_lock);
226-
list_for_each_entry_safe(caching_ctl, next,
227-
&fs_info->caching_block_groups, list) {
228-
struct btrfs_block_group *cache = caching_ctl->block_group;
229-
230-
if (btrfs_block_group_done(cache)) {
231-
cache->last_byte_to_unpin = (u64)-1;
232-
list_del_init(&caching_ctl->list);
233-
btrfs_put_caching_control(caching_ctl);
234-
} else {
235-
cache->last_byte_to_unpin = caching_ctl->progress;
236-
}
237-
}
238-
write_unlock(&fs_info->block_group_cache_lock);
239198
up_write(&fs_info->commit_root_sem);
240199
}
241200

fs/btrfs/zoned.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,6 @@ void btrfs_calc_zone_unusable(struct btrfs_block_group *cache)
15661566
free = cache->zone_capacity - cache->alloc_offset;
15671567

15681568
/* We only need ->free_space in ALLOC_SEQ block groups */
1569-
cache->last_byte_to_unpin = (u64)-1;
15701569
cache->cached = BTRFS_CACHE_FINISHED;
15711570
cache->free_space_ctl->free_space = free;
15721571
cache->zone_unusable = unusable;

0 commit comments

Comments
 (0)