diff mbox series

[2/4] btrfs: wake up async_delalloc_pages waiters after submit

Message ID d1802ad325a04d3640b85e4c928b91dd9316252c.1623419155.git.josef@toxicpanda.com
State Superseded
Headers show
Series None | expand

Commit Message

Josef Bacik June 11, 2021, 1:53 p.m. UTC
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
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/inode.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Nikolay Borisov June 14, 2021, 10:20 a.m. UTC | #1
On 11.06.21 г. 16:53, Josef Bacik wrote:
> 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

> Signed-off-by: Josef Bacik <josef@toxicpanda.com>


Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---

>  fs/btrfs/inode.c | 10 +++++-----

>  1 file changed, 5 insertions(+), 5 deletions(-)

> 

> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c

> index 6cb73ff59c7c..c37271df2c6d 100644

> --- a/fs/btrfs/inode.c

> +++ b/fs/btrfs/inode.c

> @@ -1271,11 +1271,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

> @@ -1284,6 +1279,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)

>
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 6cb73ff59c7c..c37271df2c6d 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1271,11 +1271,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
@@ -1284,6 +1279,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)