All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] btrfs: zoned: use alloc_list instead of RCU locked device_list
@ 2022-03-16 16:21 Johannes Thumshirn
  2022-03-16 16:35 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Johannes Thumshirn @ 2022-03-16 16:21 UTC (permalink / raw)
  To: David Sterba; +Cc: Johannes Thumshirn, Anand Jain, linux-btrfs

Anand pointed out, that instead of using the RCU locked version of
fs_devices->device_list we can use fs_devices->alloc_list, protected by
the chunk_mutex to traverse the list of active devices in
btrfs_can_activate_zone().

We are in the chunk allocation thread. The newer chunk allocation
happens from the devices in the fs_device->alloc_list protected by the
chunk_mutex.

  btrfs_create_chunk()
    lockdep_assert_held(&info->chunk_mutex);
    gather_device_info
      list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list)

Also, a device that reappears after the mount won't join the alloc_list
yet and, it will be in the dev_list, which we don't want to consider in
the context of the chunk alloc.

Suggested-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
Changes since v1:
* Fix crash Anand reported
---
 fs/btrfs/zoned.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 49446bb5a5d1..1b1b310c3c51 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1975,15 +1975,16 @@ int btrfs_zone_finish(struct btrfs_block_group *block_group)
 
 bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
 {
+	struct btrfs_fs_info *fs_info = fs_devices->fs_info;
 	struct btrfs_device *device;
 	bool ret = false;
 
-	if (!btrfs_is_zoned(fs_devices->fs_info))
+	if (!btrfs_is_zoned(fs_info))
 		return true;
 
 	/* Check if there is a device with active zones left */
-	rcu_read_lock();
-	list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
+	mutex_lock(&fs_info->chunk_mutex);
+	list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list) {
 		struct btrfs_zoned_device_info *zinfo = device->zone_info;
 
 		if (!device->bdev)
@@ -1995,7 +1996,7 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
 			break;
 		}
 	}
-	rcu_read_unlock();
+	mutex_unlock(&fs_info->chunk_mutex);
 
 	return ret;
 }
-- 
2.35.1


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

* Re: [PATCH v2] btrfs: zoned: use alloc_list instead of RCU locked device_list
  2022-03-16 16:21 [PATCH v2] btrfs: zoned: use alloc_list instead of RCU locked device_list Johannes Thumshirn
@ 2022-03-16 16:35 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2022-03-16 16:35 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: David Sterba, Anand Jain, linux-btrfs

On Wed, Mar 16, 2022 at 09:21:12AM -0700, Johannes Thumshirn wrote:
> Anand pointed out, that instead of using the RCU locked version of
> fs_devices->device_list we can use fs_devices->alloc_list, protected by
> the chunk_mutex to traverse the list of active devices in
> btrfs_can_activate_zone().
> 
> We are in the chunk allocation thread. The newer chunk allocation
> happens from the devices in the fs_device->alloc_list protected by the
> chunk_mutex.
> 
>   btrfs_create_chunk()
>     lockdep_assert_held(&info->chunk_mutex);
>     gather_device_info
>       list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list)
> 
> Also, a device that reappears after the mount won't join the alloc_list
> yet and, it will be in the dev_list, which we don't want to consider in
> the context of the chunk alloc.
> 
> Suggested-by: Anand Jain <anand.jain@oracle.com>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> Changes since v1:
> * Fix crash Anand reported

Patch updated, thanks.

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

end of thread, other threads:[~2022-03-16 16:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16 16:21 [PATCH v2] btrfs: zoned: use alloc_list instead of RCU locked device_list Johannes Thumshirn
2022-03-16 16:35 ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.