* [PATCH v4 0/2] block: skip rcu_barrier() when releasing zoned disks
@ 2026-11-27 3:43 Qiliang Yuan
2026-11-27 3:43 ` [PATCH v4 1/2] block: don't wait for all RCU callbacks when freeing zone write plugs Qiliang Yuan
2026-11-27 3:43 ` [PATCH v4 2/2] block: free remaining zone write plugs directly on disk release Qiliang Yuan
0 siblings, 2 replies; 5+ messages in thread
From: Qiliang Yuan @ 2026-11-27 3:43 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe; +Cc: Bart Van Assche, linux-block, Qiliang Yuan
Releasing a zoned disk calls rcu_barrier() before destroying its zone
write plug mempool, which waits for every RCU callback in the system.
Patch 1 calls it only when plugs of the disk still wait for RCU
freeing. Patch 2 frees the plugs left in the hash table directly, so
disks with partially written zones skip the wait as well.
Removing 32 zoned null_blk devices goes from 848 to 428 ms (-50%), and
from 865 to 433 ms (-50%) with four partially written zones on each.
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
V3 -> V4:
- Call rcu_barrier() only when plugs of the disk wait for RCU freeing,
instead of wait_var_event(), which did not flush lazy RCU callbacks
(Bart Van Assche)
- Add patch 2 to free the plugs left in the hash table directly at disk
release (Bart Van Assche)
- Drop the Reviewed-by of Damien Le Moal from patch 1, the wait changed
V2 -> V3:
- Initialize nr_zone_wplugs_freeing in disk_init_zone_resources() (Damien Le Moal)
V1 -> V2:
- Keep the original comment above the wait (Damien Le Moal)
- Add Reviewed-by (Damien Le Moal)
v3: https://lore.kernel.org/r/20261125-feat-blk-zoned-rcu-barrier-v3-1-707f65bae05a@linux.dev
v2: https://lore.kernel.org/r/20261124-feat-blk-zoned-rcu-barrier-v2-1-6d2212a48c5c@linux.dev
v1: https://lore.kernel.org/r/20261121-feat-blk-zoned-rcu-barrier-v1-1-766875b525be@linux.dev
---
Qiliang Yuan (2):
block: don't wait for all RCU callbacks when freeing zone write plugs
block: free remaining zone write plugs directly on disk release
block/blk-zoned.c | 29 +++++++++++++++++++++++------
include/linux/blkdev.h | 1 +
2 files changed, 24 insertions(+), 6 deletions(-)
---
base-commit: 5f22fb20497f4983094131f00a734362300d22d2
change-id: 20261120-feat-blk-zoned-rcu-barrier-cb9044e67ab3
Best regards,
--
Qiliang Yuan <qiliang.yuan@linux.dev>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/2] block: don't wait for all RCU callbacks when freeing zone write plugs
2026-11-27 3:43 [PATCH v4 0/2] block: skip rcu_barrier() when releasing zoned disks Qiliang Yuan
@ 2026-11-27 3:43 ` Qiliang Yuan
2026-11-30 4:32 ` Damien Le Moal
2026-11-27 3:43 ` [PATCH v4 2/2] block: free remaining zone write plugs directly on disk release Qiliang Yuan
1 sibling, 1 reply; 5+ messages in thread
From: Qiliang Yuan @ 2026-11-27 3:43 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe; +Cc: Bart Van Assche, linux-block, Qiliang Yuan
Zone write plugs are allocated from a per-disk mempool and freed with
call_rcu(). Before destroying the mempool, which happens every time a
zoned disk is released, disk_destroy_zone_wplugs_hash_table() calls
rcu_barrier() so that no zone write plug is still waiting to be returned
to it.
rcu_barrier() waits for the RCU callbacks queued on every CPU by anyone,
which usually takes a grace period or more, even when the disk had no
zone write plug left to free. Removing many zoned disks, such as the SMR
drives of a storage node taken offline, pays this once per disk.
Count the zone write plugs of the disk that wait for their RCU callback,
and call rcu_barrier() only when that count is not zero. Use
rcu_barrier() rather than waiting for the count to drop, so that lazily
queued callbacks (CONFIG_RCU_LAZY) are still flushed.
Removing 32 zoned null_blk or scsi_debug devices, base and patched
kernels alternating over 4 rounds of 5 runs, median of the 20 runs and
interquartile range in parentheses; "with plugs" leaves four partially
written zones, and so four zone write plugs, on each null_blk device:
devices before (ms) after (ms) change
null_blk 848 (828-862) 424 (410-430) -50%
null_blk, with plugs 865 (854-876) 876 (866-886) +1%
scsi_debug, host-managed 1057 (1024-1092) 740 (722-779) -30%
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
block/blk-zoned.c | 14 ++++++++++++--
include/linux/blkdev.h | 1 +
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 4c58892961912..e181ddb1b41b2 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -724,8 +724,15 @@ static void disk_free_zone_wplug_rcu(struct rcu_head *rcu_head)
{
struct blk_zone_wplug *zwplug =
container_of(rcu_head, struct blk_zone_wplug, rcu_head);
+ struct gendisk *disk = zwplug->disk;
- mempool_free(zwplug, zwplug->disk->zone_wplugs_pool);
+ mempool_free(zwplug, disk->zone_wplugs_pool);
+ /*
+ * Pairs with atomic_read_acquire() in
+ * disk_destroy_zone_wplugs_hash_table().
+ */
+ smp_mb__before_atomic();
+ atomic_dec(&disk->nr_zone_wplugs_freeing);
}
static void disk_free_zone_wplug(struct blk_zone_wplug *zwplug)
@@ -745,6 +752,7 @@ static void disk_free_zone_wplug(struct blk_zone_wplug *zwplug)
atomic_dec(&disk->nr_zone_wplugs);
spin_unlock_irqrestore(&disk->zone_wplugs_hash_lock, flags);
+ atomic_inc(&disk->nr_zone_wplugs_freeing);
call_rcu(&zwplug->rcu_head, disk_free_zone_wplug_rcu);
}
@@ -2022,6 +2030,7 @@ void disk_init_zone_resources(struct gendisk *disk)
{
mutex_init(&disk->zone_revalidate_mutex);
atomic_set(&disk->nr_zone_wplugs, 0);
+ atomic_set(&disk->nr_zone_wplugs_freeing, 0);
spin_lock_init(&disk->zone_wplugs_hash_lock);
spin_lock_init(&disk->zone_wplugs_list_lock);
INIT_LIST_HEAD(&disk->zone_wplugs_list);
@@ -2149,7 +2158,8 @@ static void disk_destroy_zone_wplugs_hash_table(struct gendisk *disk)
* Wait for the zone write plugs to be RCU-freed before destroying the
* mempool.
*/
- rcu_barrier();
+ if (atomic_read_acquire(&disk->nr_zone_wplugs_freeing))
+ rcu_barrier();
mempool_destroy(disk->zone_wplugs_pool);
disk->zone_wplugs_pool = NULL;
}
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 215753171cef0..b3b356f832267 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -204,6 +204,7 @@ struct gendisk {
u8 __rcu *zones_state;
unsigned int zone_wplugs_hash_bits;
atomic_t nr_zone_wplugs;
+ atomic_t nr_zone_wplugs_freeing;
spinlock_t zone_wplugs_hash_lock;
struct mempool *zone_wplugs_pool;
struct hlist_head *zone_wplugs_hash;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4 2/2] block: free remaining zone write plugs directly on disk release
2026-11-27 3:43 [PATCH v4 0/2] block: skip rcu_barrier() when releasing zoned disks Qiliang Yuan
2026-11-27 3:43 ` [PATCH v4 1/2] block: don't wait for all RCU callbacks when freeing zone write plugs Qiliang Yuan
@ 2026-11-27 3:43 ` Qiliang Yuan
2026-11-30 4:32 ` Damien Le Moal
1 sibling, 1 reply; 5+ messages in thread
From: Qiliang Yuan @ 2026-11-27 3:43 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe; +Cc: Bart Van Assche, linux-block, Qiliang Yuan
disk_destroy_zone_wplugs_hash_table() runs from disk_release() and frees
the zone write plugs still in the hash table by marking them dead, which
drops their last reference and queues them for RCU freeing. Nothing can
look up a plug at that point: the function already walks the hash table
without zone_wplugs_hash_lock and frees the table itself with kfree().
Zoned drives taken offline usually have partially written zones, so
their plugs are still in the hash table when the disk is released. Each
such disk then queues RCU callbacks and waits for them in rcu_barrier()
before destroying the mempool.
Unhash these plugs and return them to the mempool directly, keeping the
checks of disk_free_zone_wplug(). The zones state array that freeing
them would update is freed right after by disk_release_zone_resources().
Removing 32 zoned null_blk or scsi_debug devices, kernels with and
without this patch alternating over 4 rounds of 5 runs, in the same
rounds as the previous patch, median of the 20 runs and interquartile
range in parentheses; "with plugs" leaves four partially written zones,
and so four zone write plugs, on each null_blk device, and the
scsi_debug devices have no plugs left at release:
devices before (ms) after (ms) change
null_blk 424 (410-430) 428 (414-438) +1%
null_blk, with plugs 876 (866-886) 433 (426-438) -51%
scsi_debug, host-managed 740 (722-779) 742 (722-767) 0%
Suggested-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
block/blk-zoned.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index e181ddb1b41b2..bb8e614bf1bb3 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -2138,14 +2138,21 @@ static void disk_destroy_zone_wplugs_hash_table(struct gendisk *disk)
if (!disk->zone_wplugs_hash)
return;
- /* Free all the zone write plugs we have. */
+ /*
+ * Free all the zone write plugs we have. The disk is being released, so
+ * no one can look them up anymore and there is no need to wait for an
+ * RCU grace period. The zones state array is freed right after this.
+ */
for (i = 0; i < disk_zone_wplugs_hash_size(disk); i++) {
while (!hlist_empty(&disk->zone_wplugs_hash[i])) {
zwplug = hlist_entry(disk->zone_wplugs_hash[i].first,
struct blk_zone_wplug, node);
- spin_lock_irq(&zwplug->lock);
- disk_mark_zone_wplug_dead(zwplug);
- spin_unlock_irq(&zwplug->lock);
+ WARN_ON_ONCE(refcount_read(&zwplug->ref) != 1);
+ WARN_ON_ONCE(zwplug->flags & BLK_ZONE_WPLUG_PLUGGED);
+ WARN_ON_ONCE(!bio_list_empty(&zwplug->bio_list));
+ hlist_del(&zwplug->node);
+ atomic_dec(&disk->nr_zone_wplugs);
+ mempool_free(zwplug, disk->zone_wplugs_pool);
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4 1/2] block: don't wait for all RCU callbacks when freeing zone write plugs
2026-11-27 3:43 ` [PATCH v4 1/2] block: don't wait for all RCU callbacks when freeing zone write plugs Qiliang Yuan
@ 2026-11-30 4:32 ` Damien Le Moal
0 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2026-11-30 4:32 UTC (permalink / raw)
To: Qiliang Yuan, Jens Axboe; +Cc: Bart Van Assche, linux-block
On 11/27/26 12:43, Qiliang Yuan wrote:
> Zone write plugs are allocated from a per-disk mempool and freed with
> call_rcu(). Before destroying the mempool, which happens every time a
> zoned disk is released, disk_destroy_zone_wplugs_hash_table() calls
> rcu_barrier() so that no zone write plug is still waiting to be returned
> to it.
>
> rcu_barrier() waits for the RCU callbacks queued on every CPU by anyone,
> which usually takes a grace period or more, even when the disk had no
> zone write plug left to free. Removing many zoned disks, such as the SMR
> drives of a storage node taken offline, pays this once per disk.
>
> Count the zone write plugs of the disk that wait for their RCU callback,
> and call rcu_barrier() only when that count is not zero. Use
> rcu_barrier() rather than waiting for the count to drop, so that lazily
> queued callbacks (CONFIG_RCU_LAZY) are still flushed.
>
> Removing 32 zoned null_blk or scsi_debug devices, base and patched
> kernels alternating over 4 rounds of 5 runs, median of the 20 runs and
> interquartile range in parentheses; "with plugs" leaves four partially
> written zones, and so four zone write plugs, on each null_blk device:
>
> devices before (ms) after (ms) change
> null_blk 848 (828-862) 424 (410-430) -50%
> null_blk, with plugs 865 (854-876) 876 (866-886) +1%
> scsi_debug, host-managed 1057 (1024-1092) 740 (722-779) -30%
>
> Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
I am not sure that the atomic_read_acquire() is necessary (atomic_read() should
be fine), but I guess it does not hurt either.
So,
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 2/2] block: free remaining zone write plugs directly on disk release
2026-11-27 3:43 ` [PATCH v4 2/2] block: free remaining zone write plugs directly on disk release Qiliang Yuan
@ 2026-11-30 4:32 ` Damien Le Moal
0 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2026-11-30 4:32 UTC (permalink / raw)
To: Qiliang Yuan, Jens Axboe; +Cc: Bart Van Assche, linux-block
On 11/27/26 12:43, Qiliang Yuan wrote:
> disk_destroy_zone_wplugs_hash_table() runs from disk_release() and frees
> the zone write plugs still in the hash table by marking them dead, which
> drops their last reference and queues them for RCU freeing. Nothing can
> look up a plug at that point: the function already walks the hash table
> without zone_wplugs_hash_lock and frees the table itself with kfree().
>
> Zoned drives taken offline usually have partially written zones, so
> their plugs are still in the hash table when the disk is released. Each
> such disk then queues RCU callbacks and waits for them in rcu_barrier()
> before destroying the mempool.
>
> Unhash these plugs and return them to the mempool directly, keeping the
> checks of disk_free_zone_wplug(). The zones state array that freeing
> them would update is freed right after by disk_release_zone_resources().
>
> Removing 32 zoned null_blk or scsi_debug devices, kernels with and
> without this patch alternating over 4 rounds of 5 runs, in the same
> rounds as the previous patch, median of the 20 runs and interquartile
> range in parentheses; "with plugs" leaves four partially written zones,
> and so four zone write plugs, on each null_blk device, and the
> scsi_debug devices have no plugs left at release:
>
> devices before (ms) after (ms) change
> null_blk 424 (410-430) 428 (414-438) +1%
> null_blk, with plugs 876 (866-886) 433 (426-438) -51%
> scsi_debug, host-managed 740 (722-779) 742 (722-767) 0%
>
> Suggested-by: Bart Van Assche <bvanassche@acm.org>
> Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
Looks good to me.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-30 4:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 3:43 [PATCH v4 0/2] block: skip rcu_barrier() when releasing zoned disks Qiliang Yuan
2026-11-27 3:43 ` [PATCH v4 1/2] block: don't wait for all RCU callbacks when freeing zone write plugs Qiliang Yuan
2026-11-30 4:32 ` Damien Le Moal
2026-11-27 3:43 ` [PATCH v4 2/2] block: free remaining zone write plugs directly on disk release Qiliang Yuan
2026-11-30 4:32 ` Damien Le Moal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox