cached zone reporting fixes
Subsystems (2)
Hi Jens,
this series fixes two issues with the new zone writeplug caching code found running xfstests on ZNS devices.
Diffstat:
block/blk-zoned.c | 46 +++++++++++++++++++++++++++++----------------- include/linux/blkdev.h | 1 + 2 files changed, 30 insertions(+), 17 deletions(-)
PATCH 1/2 block: don't leak disk->zones_cond for !disk_need_zone_resources
disk->zones_cond is allocated for all zoned devices, but disk_free_zone_resources skips it when the zone write plug hash is not allocated, leaking the allocation for non-mq devices that don't emulate zone append. This is reported by kmemleak-enabled xfstests for various tests that use simple device mapper targets.
Fix this by moving all code that requires writes plugs from disk_free_zone_resources into disk_destroy_zone_wplugs_hash_table and executing the rest of the code, including the disk->zones_cond freeing unconditionally.
--- block/blk-zoned.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
block/blk-zoned.c +8 -12
@@ -1834,6 +1834,14 @@ static void disk_destroy_zone_wplugs_hash_table(struct gendisk *disk)kfree (disk->zone_wplugs_hash); disk->zone_wplugs_hash =NULL ; disk->zone_wplugs_hash_bits =0 ; + +/* +* Wait for the zone write plugs to be RCU-freed before destroying the +* mempool. +*/ +rcu_barrier (); +mempool_destroy (disk->zone_wplugs_pool); + disk->zone_wplugs_pool =NULL ; }static void disk_set_zones_cond_array (struct gendisk *disk,u8 *zones_cond)
@@ -1850,9 +1858,6 @@ static void disk_set_zones_cond_array(struct gendisk *disk, u8 *zones_cond)void disk_free_zone_resources (struct gendisk *disk) { -if (!disk->zone_wplugs_pool) -return ; -if (disk->zone_wplugs_wq) {destroy_workqueue (disk->zone_wplugs_wq); disk->zone_wplugs_wq =NULL ;
@@ -1860,15 +1865,6 @@ void disk_free_zone_resources(struct gendisk *disk)disk_destroy_zone_wplugs_hash_table (disk); -/* -* Wait for the zone write plugs to be RCU-freed before -* destorying the mempool. -*/ -rcu_barrier (); - -mempool_destroy (disk->zone_wplugs_pool); - disk->zone_wplugs_pool =NULL ; -disk_set_zones_cond_array (disk,NULL ); disk->zone_capacity =0 ; disk->last_zone_capacity =0 ;
Signature · 1 line
2.47.3
Re: [PATCH 1/2] block: don't leak disk->zones_cond for !disk_need_zone_resources
Quoted 6 lines · Christoph Hellwig
disk->zones_condis allocated for all zoned devices, butdisk_free_zone_resourcesskips it when the zone write plug hash is not allocated, leaking the allocation for non-mq devices that don't emulate zone append. This is reported by kmemleak-enabled xfstests for various tests that use simple device mapper targets.
Quoted 7 lines
Fix this by moving all code that requires writes plugs from
disk_free_zone_resourcesintodisk_destroy_zone_wplugs_hash_tableand executing the rest of the code, including thedisk->zones_condfreeing unconditionally.Fixes 6e945ffb6555 ("block: use zone condition to determine conventional zones")Signed-off-by Christoph Hellwig <[email protected]>
Thanks for the fix. Looks good.
Signature · 2 lines
Damien Le Moal Western Digital Research
PATCH 2/2 block: fix cached zone reporting after zone append was used
In reply to Christoph HellwigNo zone plugs are allocated when a zone is opened by calling Zone Append on it. This makes the cached zone reporting report incorrectly empty zones if the file system is unmounted and report zones is called after that, e.g. by xfstests test cases using the scratch device.
Fix this by recording if zone append was used on a device, and disable cached reporting for the device until a ZONE_RESET_ALL happens that guarantees all zones are empty.
We could probably do even better using a per-zone flag, but the practical use cache for zone reporting after the initial mount are rather limited, so let's keep things simple for now.
--- block/blk-zoned.c | 26 +++++++++++++++++++++----- include/linux/blkdev.h | 1 + 2 files changed, 22 insertions(+), 5 deletions(-)
block/blk-zoned.c +21 -5
@@ -899,6 +899,19 @@ static int blkdev_report_zone_fallback(struct block_device *bdev,return blkdev_do_report_zones (bdev, sector,1 , &args); } +/* +* For devices that natively support zone append operations, we do not use zone +* write plugging for zone append writes, which makes the zone condition +* tracking invalid once zone append was used. In that case fall back to a +* regular report zones to get correct information. +*/ +static inline bool blkdev_has_cached_report_zones (struct block_device *bdev) +{ +return disk_need_zone_resources (bdev->bd_disk) && + (bdev_emulates_zone_append (bdev) || + !test_bit (GD_ZONE_APPEND_USED , &bdev->bd_disk->state)); +} +/** * blkdev_get_zone_info - Get a single zone information from cached data * @bdev: Target block device
@@ -932,6 +945,9 @@ int blkdev_get_zone_info(struct block_device *bdev, sector_t sector,memset (zone,0 ,sizeof (*zone)); sector =ALIGN_DOWN (sector, zone_sectors); +if (!blkdev_has_cached_report_zones (bdev)) +return blkdev_report_zone_fallback (bdev, sector, zone); +rcu_read_lock (); zones_cond =rcu_dereference (disk->zones_cond);if (!disk->zone_wplugs_hash || !zones_cond) {
@@ -1035,11 +1051,7 @@ int blkdev_report_zones_cached(struct block_device *bdev, sector_t sector,if (!nr_zones || sector >= capacity)return 0 ; -/* -* If we do not have any zone write plug resources, fallback to using -* the regular zone report. -*/ -if (!disk_need_zone_resources (disk)) { +if (!blkdev_has_cached_report_zones (bdev)) {struct blk_report_zones_args args = { .cb = cb, .data = data,
@@ -1115,6 +1127,7 @@ static void blk_zone_reset_all_bio_endio(struct bio *bio)for (sector =0 ; sector < capacity; sector +=bdev_zone_sectors (bio->bi_bdev))disk_zone_set_cond (disk, sector,BLK_ZONE_COND_EMPTY ); +clear_bit (GD_ZONE_APPEND_USED , &disk->state); }static void blk_zone_finish_bio_endio (struct bio *bio)
@@ -1474,6 +1487,9 @@ static void blk_zone_wplug_handle_native_zone_append(struct bio *bio)struct blk_zone_wplug *zwplug;unsigned long flags; +if (!test_bit (GD_ZONE_APPEND_USED , &disk->state)) +set_bit (GD_ZONE_APPEND_USED , &disk->state); +/* * We have native support for zone append operations, so we are not * going to handle @bio through plugging. However, we may already have a
include/linux/blkdev.h +1 -0
@@ -173,6 +173,7 @@ struct gendisk {#define GD_ADDED 4#define GD_SUPPRESS_PART_SCAN 5#define GD_OWNS_QUEUE 6 +#define GD_ZONE_APPEND_USED 7struct mutex open_mutex;/* open/close mutex */ unsigned open_partitions;/* number of open partitions */
Signature · 1 line
2.47.3
Re: [PATCH 2/2] block: fix cached zone reporting after zone append was used
Quoted 9 lines · Christoph Hellwig
No zone plugs are allocated when a zone is opened by calling Zone Append on it. This makes the cached zone reporting report incorrectly empty zones if the file system is unmounted and report zones is called after that, e.g. by xfstests test cases using the scratch device.
Fix this by recording if zone append was used on a device, and disable cached reporting for the device until a
ZONE_RESET_ALLhappens that guarantees all zones are empty.
Quoted 6 lines
We could probably do even better using a per-zone flag, but the practical use cache for zone reporting after the initial mount are rather limited, so let's keep things simple for now.
Fixes 31f0656a4ab7 ("block: introduce blkdev_report_zones_cached()")Signed-off-by Christoph Hellwig <[email protected]>
Thanks for this ! I did recreate this issue with zloop as well.
One nit below.
block/blk-zoned.c static void blk_zone_wplug_handle_native_zone_append(struct bio *bio) · line 1491
Quoted 6 lines
block/blk-zoned.c +2
-0@@ -1474,6 +1487,9 @@ static void blk_zone_wplug_handle_native_zone_append(struct bio *bio)struct blk_zone_wplug *zwplug;unsigned long flags; +if (!test_bit (GD_ZONE_APPEND_USED , &disk->state)) +set_bit (GD_ZONE_APPEND_USED , &disk->state);
We could remove the test_bit() here and unconditionally call set_bit(): single atomic op instead of 2.
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH 2/2] block: fix cached zone reporting after zone append was used
Quoted 5 lines · Damien Le Moal
block/blk-zoned.c static void blk_zone_wplug_handle_native_zone_append(struct bio *bio) · line 1491
Quoted 2 lines
block/blk-zoned.c +2
-0+if (!test_bit (GD_ZONE_APPEND_USED , &disk->state)) +set_bit (GD_ZONE_APPEND_USED , &disk->state);We could remove the
test_bit()here and unconditionally callset_bit(): single atomic op instead of 2.
test_bit doesn't need a lock prefix (at least on x86) and avoid unconditionally dirtying the cache line.
Jens Axboe
maintainerRe: [PATCH 2/2] block: fix cached zone reporting after zone append was used
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Damien Le Moal
block/blk-zoned.c static void blk_zone_wplug_handle_native_zone_append(struct bio *bio) · line 1491
Quoted 2 lines
block/blk-zoned.c +2
-0+if (!test_bit (GD_ZONE_APPEND_USED , &disk->state)) +set_bit (GD_ZONE_APPEND_USED , &disk->state);We could remove the
test_bit()here and unconditionally callset_bit(): single atomic op instead of 2.
test_bitdoesn't need a lock prefix (at least on x86) and avoid unconditionally dirtying the cache line.
It's a common enough trick that I'm surprised it isn't documented somewhere. I've used it in the block stack too, since a long time ago.
Signature · 1 line
Jens Axboe
Bart Van Assche
Reviewed-byQuoted 2 lines · Christoph Hellwig
this series fixes two issues with the new zone writeplug caching code found running xfstests on ZNS devices.
For both patches:
Quoted 9 lines · Christoph Hellwig
this series fixes two issues with the new zone writeplug caching code found running xfstests on ZNS devices.
Diffstat:
block/blk-zoned.c | 46 +++++++++++++++++++++++++++++----------------- include/linux/blkdev.h | 1 + 2 files changed, 30 insertions(+), 17 deletions(-)[...]
Applied, thanks!
[1/2] block: don't leak disk->zones_cond for !disk_need_zone_resources
commit: c6886cf610f4bb0b8aa6b88ab013a042e317f898
[2/2] block: fix cached zone reporting after zone append was used
commit: 15638d52cbcf6e969f4a5e2757b118355db583f3Best regards,
Signature · 1 line
Jens Axboe