diff mbox series

btrfs: don't block if we can't acquire the reclaim lock

Message ID 8fc77aa7ffbc61e7e55d57e8cfc7423642558b17.1625500974.git.johannes.thumshirn@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: don't block if we can't acquire the reclaim lock | expand

Commit Message

Johannes Thumshirn July 5, 2021, 4:32 p.m. UTC
If we can acquire the reclaim_bgs_lock in on block group reclaim, we block
until it is free. This can potentially stall for a long time.

While reclaim of block groups is necessary for a good user experience on a
zoned file system, there still is no need to block as it is best effort
only, just like when we're deleting unused block groups.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/block-group.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Nikolay Borisov July 6, 2021, 11:21 a.m. UTC | #1
On 5.07.21 г. 19:32, Johannes Thumshirn wrote:
> If we can acquire the reclaim_bgs_lock in on block group reclaim, we block
nit: s/can/can't/ , also remove 'in' ?
> until it is free. This can potentially stall for a long time.
> 
> While reclaim of block groups is necessary for a good user experience on a
> zoned file system, there still is no need to block as it is best effort
> only, just like when we're deleting unused block groups.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>  fs/btrfs/block-group.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index c557327b4545..9e7d9d0c763d 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -1498,7 +1498,15 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
>  	if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE))
>  		return;
>  
> -	mutex_lock(&fs_info->reclaim_bgs_lock);
> +	/*
> +	 * Long running balances can keep us blocked here for eternity, so
> +	 * simply skip reclaim if we're unable to get the mutex.
> +	 */
> +	if (!mutex_trylock(&fs_info->reclaim_bgs_lock)) {
> +		btrfs_exclop_finish(fs_info);
> +		return;
> +	}
> +
>  	spin_lock(&fs_info->unused_bgs_lock);
>  	while (!list_empty(&fs_info->reclaim_bgs)) {
>  		u64 zone_unusable;
>
Johannes Thumshirn July 6, 2021, 11:23 a.m. UTC | #2
On 06/07/2021 13:21, Nikolay Borisov wrote:
> 
> 
> On 5.07.21 г. 19:32, Johannes Thumshirn wrote:
>> If we can acquire the reclaim_bgs_lock in on block group reclaim, we block
> nit: s/can/can't/ , also remove 'in' ?

Oops, you're right. David can you fix this up on apply?
David Sterba July 7, 2021, 3:29 p.m. UTC | #3
On Tue, Jul 06, 2021 at 01:32:38AM +0900, Johannes Thumshirn wrote:
> If we can acquire the reclaim_bgs_lock in on block group reclaim, we block
> until it is free. This can potentially stall for a long time.
> 
> While reclaim of block groups is necessary for a good user experience on a
> zoned file system, there still is no need to block as it is best effort
> only, just like when we're deleting unused block groups.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Added to misc-next with the fixup, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index c557327b4545..9e7d9d0c763d 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1498,7 +1498,15 @@  void btrfs_reclaim_bgs_work(struct work_struct *work)
 	if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE))
 		return;
 
-	mutex_lock(&fs_info->reclaim_bgs_lock);
+	/*
+	 * Long running balances can keep us blocked here for eternity, so
+	 * simply skip reclaim if we're unable to get the mutex.
+	 */
+	if (!mutex_trylock(&fs_info->reclaim_bgs_lock)) {
+		btrfs_exclop_finish(fs_info);
+		return;
+	}
+
 	spin_lock(&fs_info->unused_bgs_lock);
 	while (!list_empty(&fs_info->reclaim_bgs)) {
 		u64 zone_unusable;