]> git.hungrycats.org Git - linux/commitdiff
btrfs: wake up async_delalloc_pages waiters after submit
authorJosef Bacik <josef@toxicpanda.com>
Wed, 14 Jul 2021 18:47:17 +0000 (14:47 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 5 Dec 2021 08:11:11 +0000 (03:11 -0500)
commit ac98141d140444fe93e26471d3074c603b70e2ca upstream.

We use the async_delalloc_pages mechanism to make sure that we've
completed our async work before trying to continue our delalloc
flushing.  The reason for this is we need to see any ordered extents
that were created by our delalloc flushing.  However we're waking up
before we do the submit work, which is before we create the ordered
extents.  This is a pretty wide race window where we could potentially
think there are no ordered extents and thus exit shrink_delalloc
prematurely.  Fix this by waking us up after we've done the work to
create ordered extents.

CC: stable@vger.kernel.org # 5.4+
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 0901af53da8f4cfee3bb364a35f66d0d4a9b93ba)
(cherry picked from commit 044785b485a3367309b6ac8f9c9ec720ad3755f6)

fs/btrfs/inode.c

index 8581014c84344144520d41dbf4ad1e6fc8f635fc..38384874a43494a53a79149091a41d49f47a0337 100644 (file)
@@ -1252,11 +1252,6 @@ static noinline void async_cow_submit(struct btrfs_work *work)
        nr_pages = (async_chunk->end - async_chunk->start + PAGE_SIZE) >>
                PAGE_SHIFT;
 
-       /* atomic_sub_return implies a barrier */
-       if (atomic_sub_return(nr_pages, &fs_info->async_delalloc_pages) <
-           5 * SZ_1M)
-               cond_wake_up_nomb(&fs_info->async_submit_wait);
-
        /*
         * ->inode could be NULL if async_chunk_start has failed to compress,
         * in which case we don't have anything to submit, yet we need to
@@ -1265,6 +1260,11 @@ static noinline void async_cow_submit(struct btrfs_work *work)
         */
        if (async_chunk->inode)
                submit_compressed_extents(async_chunk);
+
+       /* atomic_sub_return implies a barrier */
+       if (atomic_sub_return(nr_pages, &fs_info->async_delalloc_pages) <
+           5 * SZ_1M)
+               cond_wake_up_nomb(&fs_info->async_submit_wait);
 }
 
 static noinline void async_cow_free(struct btrfs_work *work)