]> git.hungrycats.org Git - linux/commitdiff
btrfs: zoned: wait until zone is finished when allocation didn't progress
authorNaohiro Aota <naohiro.aota@wdc.com>
Fri, 8 Jul 2022 23:18:50 +0000 (08:18 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:42:27 +0000 (14:42 +0200)
[ Upstream commit 2ce543f478433a0eec0f72090d7e814f1d53d456 ]

When the allocated position doesn't progress, we cannot submit IOs to
finish a block group, but there should be ongoing IOs that will finish a
block group. So, in that case, we wait for a zone to be finished and retry
the allocation after that.

Introduce a new flag BTRFS_FS_NEED_ZONE_FINISH for fs_info->flags to
indicate we need a zone finish to have proceeded. The flag is set when the
allocator detected it cannot activate a new block group. And, it is cleared
once a zone is finished.

CC: stable@vger.kernel.org # 5.16+
Fixes: afba2bc036b0 ("btrfs: zoned: implement active zone tracking")
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/inode.c
fs/btrfs/zoned.c

index 97f5a3d320ff4d478493ef14e8cab3202aa23131..76fbe4cf2a28f68aa915c888a9ffcc744ca3dede 100644 (file)
@@ -635,6 +635,9 @@ enum {
        /* Indicate we have half completed snapshot deletions pending. */
        BTRFS_FS_UNFINISHED_DROPS,
 
+       /* Indicate we have to finish a zone to do next allocation. */
+       BTRFS_FS_NEED_ZONE_FINISH,
+
 #if BITS_PER_LONG == 32
        /* Indicate if we have error/warn message printed on 32bit systems */
        BTRFS_FS_32BIT_ERROR,
@@ -1074,6 +1077,8 @@ struct btrfs_fs_info {
 
        spinlock_t zone_active_bgs_lock;
        struct list_head zone_active_bgs;
+       /* Waiters when BTRFS_FS_NEED_ZONE_FINISH is set */
+       wait_queue_head_t zone_finish_wait;
 
 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
        spinlock_t ref_verify_lock;
index bf5c6ac67e87cbd22e106cda48cba91dc3deee75..59fa7bf3a2e554883915ca086e85c83b63b96fcf 100644 (file)
@@ -3239,6 +3239,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
        init_waitqueue_head(&fs_info->transaction_blocked_wait);
        init_waitqueue_head(&fs_info->async_submit_wait);
        init_waitqueue_head(&fs_info->delayed_iputs_wait);
+       init_waitqueue_head(&fs_info->zone_finish_wait);
 
        /* Usable values until the real ones are cached from the superblock */
        fs_info->nodesize = 4096;
index 9753fc47e488143ee60bfce8369e187792ba5225..64d310ecbb846f905e13f685b201bdf3c80433c7 100644 (file)
@@ -1606,8 +1606,13 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
                if (ret == 0)
                        done_offset = end;
 
-               if (done_offset == start)
-                       return -ENOSPC;
+               if (done_offset == start) {
+                       struct btrfs_fs_info *info = inode->root->fs_info;
+
+                       wait_var_event(&info->zone_finish_wait,
+                                      !test_bit(BTRFS_FS_NEED_ZONE_FINISH, &info->flags));
+                       continue;
+               }
 
                if (!locked_page_done) {
                        __set_page_dirty_nobuffers(locked_page);
index 0c2d81b0e3d3eef83094e127cd3e5aa0626ef0e4..45e29b8c705c1e71fc35276f605e99d927c6adc9 100644 (file)
@@ -1993,6 +1993,9 @@ int btrfs_zone_finish(struct btrfs_block_group *block_group)
        /* For active_bg_list */
        btrfs_put_block_group(block_group);
 
+       clear_bit(BTRFS_FS_NEED_ZONE_FINISH, &fs_info->flags);
+       wake_up_all(&fs_info->zone_finish_wait);
+
        return 0;
 }
 
@@ -2021,6 +2024,9 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
        }
        mutex_unlock(&fs_info->chunk_mutex);
 
+       if (!ret)
+               set_bit(BTRFS_FS_NEED_ZONE_FINISH, &fs_info->flags);
+
        return ret;
 }