public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Cc: Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	Naohiro Aota <naohiro.aota@wdc.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Damien Le Moal <dlemoal@kernel.org>
Subject: Re: [PATCH 1/2] btrfs: zoned: use rcu list for iterating devices to collect stats
Date: Mon, 22 Jan 2024 22:34:28 +0100	[thread overview]
Message-ID: <20240122213428.GE31555@twin.jikos.cz> (raw)
In-Reply-To: <20240122-reclaim-fix-v1-1-761234a6d005@wdc.com>

On Mon, Jan 22, 2024 at 02:51:03AM -0800, Johannes Thumshirn wrote:
> As btrfs_zoned_should_reclaim only has to iterate the device list in order
> to collect stats on the device's total and used bytes, we don't need to
> take the full blown mutex, but can iterate the device list in a rcu_read
> context.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>  fs/btrfs/zoned.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index 168af9d000d1..b7e7b5a5a6fa 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -2423,15 +2423,15 @@ bool btrfs_zoned_should_reclaim(struct btrfs_fs_info *fs_info)
>  	if (fs_info->bg_reclaim_threshold == 0)
>  		return false;
>  
> -	mutex_lock(&fs_devices->device_list_mutex);
> -	list_for_each_entry(device, &fs_devices->devices, dev_list) {
> +	rcu_read_lock();
> +	list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
>  		if (!device->bdev)
>  			continue;
>  
>  		total += device->disk_total_bytes;
>  		used += device->bytes_used;
>  	}
> -	mutex_unlock(&fs_devices->device_list_mutex);
> +	rcu_read_unlock();

This is basically only a hint and inaccuracies in the total or used
values would be transient, right? The sum is calculated each time the
funciton is called, not stored anywhere so in the unlikely case of
device removal it may skip reclaim once, but then pick it up later.
Any actual removal of the block groups in verified again and properly
locked in btrfs_reclaim_bgs_work().

  parent reply	other threads:[~2024-01-22 21:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22 10:51 [PATCH 0/2] btrfs: zoned: kick reclaim earlier on fast zoned devices Johannes Thumshirn
2024-01-22 10:51 ` [PATCH 1/2] btrfs: zoned: use rcu list for iterating devices to collect stats Johannes Thumshirn
2024-01-22 12:12   ` Naohiro Aota
2024-01-22 21:34   ` David Sterba [this message]
2024-01-23  7:49     ` Johannes Thumshirn
2024-01-23 18:35       ` David Sterba
2024-01-22 10:51 ` [PATCH 2/2] btrfs: zoned: wake up cleaner sooner if needed Johannes Thumshirn
2024-01-22 12:22   ` Naohiro Aota
2024-01-22 12:30     ` Johannes Thumshirn
2024-01-22 14:39       ` Naohiro Aota
2024-01-22 14:43         ` Johannes Thumshirn
2024-01-22 15:26           ` Naohiro Aota
2024-01-22 23:51   ` Boris Burkov
2024-01-22 16:04 ` [PATCH 0/2] btrfs: zoned: kick reclaim earlier on fast zoned devices Johannes Thumshirn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240122213428.GE31555@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=dlemoal@kernel.org \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=naohiro.aota@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox