Skip to content

Commit d53ba47

Browse files
Josef Bacikchrismason-xx
authored andcommitted
Btrfs: use commit root when loading free space cache
A user reported that booting his box up with btrfs root on 3.4 was way slower than on 3.3 because I removed the ideal caching code. It turns out that we don't load the free space cache if we're in a commit for deadlock reasons, but since we're reading the cache and it hasn't changed yet we are safe reading the inode and free space item from the commit root, so do that and remove all of the deadlock checks so we don't unnecessarily skip loading the free space cache. The user reported this fixed the slowness. Thanks, Tested-by: Calvin Walton <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 4edc2ca commit d53ba47

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,7 @@ static int cache_block_group(struct btrfs_block_group_cache *cache,
529529
* allocate blocks for the tree root we can't do the fast caching since
530530
* we likely hold important locks.
531531
*/
532-
if (trans && (!trans->transaction->in_commit) &&
533-
(root && root != root->fs_info->tree_root) &&
534-
btrfs_test_opt(root, SPACE_CACHE)) {
532+
if (fs_info->mount_opt & BTRFS_MOUNT_SPACE_CACHE) {
535533
ret = load_free_space_cache(fs_info, cache);
536534

537535
spin_lock(&cache->lock);

fs/btrfs/free-space-cache.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -747,13 +747,6 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
747747
bool matched;
748748
u64 used = btrfs_block_group_used(&block_group->item);
749749

750-
/*
751-
* If we're unmounting then just return, since this does a search on the
752-
* normal root and not the commit root and we could deadlock.
753-
*/
754-
if (btrfs_fs_closing(fs_info))
755-
return 0;
756-
757750
/*
758751
* If this block group has been marked to be cleared for one reason or
759752
* another then we can't trust the on disk cache, so just return.
@@ -768,6 +761,8 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
768761
path = btrfs_alloc_path();
769762
if (!path)
770763
return 0;
764+
path->search_commit_root = 1;
765+
path->skip_locking = 1;
771766

772767
inode = lookup_free_space_inode(root, block_group, path);
773768
if (IS_ERR(inode)) {

0 commit comments

Comments
 (0)