Re: [PATCH 2/2] btrfs: zoned: wake up cleaner sooner if needed

From: Johannes Thumshirn
Date: Mon Jan 22 2024 - 09:43:21 EST


On 22.01.24 15:39, Naohiro Aota wrote:
>>>
>>> Also, looking into btrfs_zoned_should_reclaim(), it sums device->bytes_used
>>> for each fs_devices->devices. And, device->bytes_used is set at
>>> create_chunk() or at btrfs_remove_chunk(). Isn't it feasible to do the
>>> calculation only there?
>>
>> Oh sh*t! Right we should check bytes_used from all space_infos in
>> btrfs_zoned_should_reclaim() and compare that to the disk total bytes.
>
> You mean device->bytes_used? space_info->bytes_used does not count free
> space and zone_unusable in BGs, so using that changes the behavior. Even,
> it won't kick the thread if there are many zone_unusable but small used
> space.
>

I did mean btrfs_space_info_used():

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index b7e7b5a5a6fa..d5242c96c97c 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -2414,6 +2414,7 @@ bool btrfs_zoned_should_reclaim(struct
btrfs_fs_info *fs_info)
{
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
struct btrfs_device *device;
+ struct btrfs_space_info *space_info;
u64 used = 0;
u64 total = 0;
u64 factor;
@@ -2429,10 +2430,15 @@ bool btrfs_zoned_should_reclaim(struct
btrfs_fs_info *fs_info)
continue;

total += device->disk_total_bytes;
- used += device->bytes_used;
}
rcu_read_unlock();

+ list_for_each_entry(space_info, &fs_info->space_info, list) {
+ spin_lock(&space_info->lock);
+ used += btrfs_space_info_used(space_info, true);
+ spin_unlock(&space_info->lock);
+ }
+
factor = div64_u64(used * 100, total);
return factor >= fs_info->bg_reclaim_threshold;
}