linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: discard before adding to the free space cache
@ 2019-12-09 19:38 Dennis Zhou
  2019-12-09 20:01 ` Nikolay Borisov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dennis Zhou @ 2019-12-09 19:38 UTC (permalink / raw)
  To: David Sterba, Chris Mason, Josef Bacik, Omar Sandoval, Nikolay Borisov
  Cc: kernel-team, linux-btrfs, Dennis Zhou

Returning free space to the free space cache lets it immediately be
reused. So discard before returning the free space otherwise we can race
here.

Fixes: 55e734b728c0 ("btrfs: Don't discard unwritten extents")
Cc: Nikolay Borisov <nborisov@suse.com>
Cc: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Dennis Zhou <dennis@kernel.org>
---
 fs/btrfs/inode.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 625439875299..1ab13943cdf0 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3250,13 +3250,14 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
 		    clear_reserved_extent &&
 		    !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
 		    !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) {
-			btrfs_free_reserved_extent(fs_info,
-						   ordered_extent->start,
-						   ordered_extent->disk_len, 1);
 			if (ret && btrfs_test_opt(fs_info, DISCARD))
 				btrfs_discard_extent(fs_info,
 						ordered_extent->start,
 						ordered_extent->disk_len, NULL);
+
+			btrfs_free_reserved_extent(fs_info,
+						   ordered_extent->start,
+						   ordered_extent->disk_len, 1);
 		}
 	}
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: discard before adding to the free space cache
  2019-12-09 19:38 [PATCH] btrfs: discard before adding to the free space cache Dennis Zhou
@ 2019-12-09 20:01 ` Nikolay Borisov
  2019-12-11  8:58 ` Johannes Thumshirn
  2020-01-02 14:44 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Nikolay Borisov @ 2019-12-09 20:01 UTC (permalink / raw)
  To: Dennis Zhou, David Sterba, Chris Mason, Josef Bacik, Omar Sandoval
  Cc: kernel-team, linux-btrfs



On 9.12.19 г. 21:38 ч., Dennis Zhou wrote:
> Returning free space to the free space cache lets it immediately be
> reused. So discard before returning the free space otherwise we can race
> here.
> 
> Fixes: 55e734b728c0 ("btrfs: Don't discard unwritten extents")
> Cc: Nikolay Borisov <nborisov@suse.com>
> Cc: Omar Sandoval <osandov@osandov.com>
> Signed-off-by: Dennis Zhou <dennis@kernel.org>

Fair point.

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


> ---
>  fs/btrfs/inode.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 625439875299..1ab13943cdf0 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -3250,13 +3250,14 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
>  		    clear_reserved_extent &&
>  		    !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
>  		    !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) {
> -			btrfs_free_reserved_extent(fs_info,
> -						   ordered_extent->start,
> -						   ordered_extent->disk_len, 1);
>  			if (ret && btrfs_test_opt(fs_info, DISCARD))
>  				btrfs_discard_extent(fs_info,
>  						ordered_extent->start,
>  						ordered_extent->disk_len, NULL);
> +
> +			btrfs_free_reserved_extent(fs_info,
> +						   ordered_extent->start,
> +						   ordered_extent->disk_len, 1);
>  		}
>  	}
>  
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: discard before adding to the free space cache
  2019-12-09 19:38 [PATCH] btrfs: discard before adding to the free space cache Dennis Zhou
  2019-12-09 20:01 ` Nikolay Borisov
@ 2019-12-11  8:58 ` Johannes Thumshirn
  2020-01-02 14:44 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2019-12-11  8:58 UTC (permalink / raw)
  To: Dennis Zhou, David Sterba, Chris Mason, Josef Bacik,
	Omar Sandoval, Nikolay Borisov
  Cc: kernel-team, linux-btrfs

Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>


-- 
Johannes Thumshirn                            SUSE Labs Filesystems
jthumshirn@suse.de                                +49 911 74053 689
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5
90409 Nürnberg
Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: discard before adding to the free space cache
  2019-12-09 19:38 [PATCH] btrfs: discard before adding to the free space cache Dennis Zhou
  2019-12-09 20:01 ` Nikolay Borisov
  2019-12-11  8:58 ` Johannes Thumshirn
@ 2020-01-02 14:44 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2020-01-02 14:44 UTC (permalink / raw)
  To: Dennis Zhou
  Cc: David Sterba, Chris Mason, Josef Bacik, Omar Sandoval,
	Nikolay Borisov, kernel-team, linux-btrfs

On Mon, Dec 09, 2019 at 11:38:46AM -0800, Dennis Zhou wrote:
> Returning free space to the free space cache lets it immediately be
> reused. So discard before returning the free space otherwise we can race
> here.
> 
> Fixes: 55e734b728c0 ("btrfs: Don't discard unwritten extents")

Unstable commit id as the patch is still in misc-next, so I'm going to
fold the fix to the original patch. Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-02 14:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-09 19:38 [PATCH] btrfs: discard before adding to the free space cache Dennis Zhou
2019-12-09 20:01 ` Nikolay Borisov
2019-12-11  8:58 ` Johannes Thumshirn
2020-01-02 14:44 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).