]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: simplify block group traversal in btrfs_put_block_group_cache
authorJosef Bacik <josef@toxicpanda.com>
Fri, 15 Jul 2022 19:45:26 +0000 (15:45 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 26 Sep 2022 10:27:54 +0000 (12:27 +0200)
We're breaking out and re-searching for the next block group while
evicting any of the block group cache inodes.  This is not needed, the
block groups aren't disappearing here, we can simply loop through the
block groups like normal and iput any inode that we find.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c

index 601743f22a9abbada66931a76ff31df18371c30e..302d4e53877eb8383d2c4229d015cb00248b5564 100644 (file)
@@ -3950,36 +3950,24 @@ void btrfs_reserve_chunk_metadata(struct btrfs_trans_handle *trans,
 void btrfs_put_block_group_cache(struct btrfs_fs_info *info)
 {
        struct btrfs_block_group *block_group;
-       u64 last = 0;
 
-       while (1) {
-               struct inode *inode;
-
-               block_group = btrfs_lookup_first_block_group(info, last);
-               while (block_group) {
-                       btrfs_wait_block_group_cache_done(block_group);
-                       spin_lock(&block_group->lock);
-                       if (test_bit(BLOCK_GROUP_FLAG_IREF,
-                                    &block_group->runtime_flags))
-                               break;
+       block_group = btrfs_lookup_first_block_group(info, 0);
+       while (block_group) {
+               btrfs_wait_block_group_cache_done(block_group);
+               spin_lock(&block_group->lock);
+               if (test_and_clear_bit(BLOCK_GROUP_FLAG_IREF,
+                                      &block_group->runtime_flags)) {
+                       struct inode *inode = block_group->inode;
+
+                       block_group->inode = NULL;
                        spin_unlock(&block_group->lock);
-                       block_group = btrfs_next_block_group(block_group);
-               }
-               if (!block_group) {
-                       if (last == 0)
-                               break;
-                       last = 0;
-                       continue;
-               }
 
-               inode = block_group->inode;
-               clear_bit(BLOCK_GROUP_FLAG_IREF, &block_group->runtime_flags);
-               block_group->inode = NULL;
-               spin_unlock(&block_group->lock);
-               ASSERT(block_group->io_ctl.inode == NULL);
-               iput(inode);
-               last = block_group->start + block_group->length;
-               btrfs_put_block_group(block_group);
+                       ASSERT(block_group->io_ctl.inode == NULL);
+                       iput(inode);
+               } else {
+                       spin_unlock(&block_group->lock);
+               }
+               block_group = btrfs_next_block_group(block_group);
        }
 }