Linux block layer
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Christoph Hellwig <hch@lst.de>
Subject: [PATCH v2 02/13] block: refactor disk_revalidate_zone_resources()
Date: Fri,  7 Aug 2026 01:04:34 +0900	[thread overview]
Message-ID: <20260806160445.848337-3-dlemoal@kernel.org> (raw)
In-Reply-To: <20260806160445.848337-1-dlemoal@kernel.org>

The function disk_revalidate_zone_resources() is misnamed as it does not
revalidate anything but rather allocates the revalidation arguments and
then calls disk_alloc_zone_resources() to initialize the disk zone
resources if they are needed and not already allocated.

Make this function less confusing by renaming it
disk_init_revalidate_args() and moving the call to
disk_alloc_zone_resources() into blk_revalidate_disk_zones(). As before,
this function is only called if the zone resources are needed and not yet
allocated.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
---
 block/blk-zoned.c | 69 ++++++++++++++++++++++++-----------------------
 1 file changed, 36 insertions(+), 33 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index b47e32bf4602..0580f0bc333c 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -1854,12 +1854,20 @@ static int disk_zone_wplugs_worker(void *data)
 
 void disk_init_zone_resources(struct gendisk *disk)
 {
+	atomic_set(&disk->nr_zone_wplugs, 0);
 	spin_lock_init(&disk->zone_wplugs_hash_lock);
 	spin_lock_init(&disk->zone_wplugs_list_lock);
 	INIT_LIST_HEAD(&disk->zone_wplugs_list);
 	init_completion(&disk->zone_wplugs_worker_bio_done);
 }
 
+static unsigned int disk_get_nr_zones(struct gendisk *disk)
+{
+	struct queue_limits *lim = &disk->queue->limits;
+
+	return DIV_ROUND_UP_ULL(get_capacity(disk), lim->chunk_sectors);
+}
+
 /*
  * For the size of a disk zone write plug hash table, use the size of the
  * zone write plug mempool, which is the maximum of the disk open zones and
@@ -1869,13 +1877,21 @@ void disk_init_zone_resources(struct gendisk *disk)
 #define BLK_ZONE_WPLUG_MAX_HASH_BITS		9
 #define BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE	128
 
-static int disk_alloc_zone_resources(struct gendisk *disk,
-				     unsigned int pool_size)
+static int disk_alloc_zone_resources(struct gendisk *disk)
 {
-	unsigned int i;
+	struct queue_limits *lim = &disk->queue->limits;
+	unsigned int nr_zones = disk_get_nr_zones(disk);
+	unsigned int pool_size, i;
 	int ret = -ENOMEM;
 
-	atomic_set(&disk->nr_zone_wplugs, 0);
+	/*
+	 * If the device has no limit on the maximum number of open and active
+	 * zones, use BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE.
+	 */
+	pool_size = max(lim->max_open_zones, lim->max_active_zones);
+	if (!pool_size)
+		pool_size = min(BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE, nr_zones);
+
 	disk->zone_wplugs_hash_bits =
 		min(ilog2(pool_size) + 1, BLK_ZONE_WPLUG_MAX_HASH_BITS);
 
@@ -2001,41 +2017,18 @@ struct blk_revalidate_zone_args {
 	sector_t	sector;
 };
 
-static int disk_revalidate_zone_resources(struct gendisk *disk,
+static int disk_init_revalidate_args(struct gendisk *disk,
 				struct blk_revalidate_zone_args *args)
 {
-	struct queue_limits *lim = &disk->queue->limits;
-	unsigned int pool_size;
-	int ret = 0;
-
 	args->disk = disk;
-	args->nr_zones =
-		DIV_ROUND_UP_ULL(get_capacity(disk), lim->chunk_sectors);
+	args->nr_zones = disk_get_nr_zones(disk);
 
 	/* Cached zone conditions: 1 byte per zone */
 	args->zones_cond = kzalloc(args->nr_zones, GFP_NOIO);
 	if (!args->zones_cond)
 		return -ENOMEM;
 
-	if (!disk_need_zone_resources(disk))
-		return 0;
-
-	/*
-	 * If the device has no limit on the maximum number of open and active
-	 * zones, use BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE.
-	 */
-	pool_size = max(lim->max_open_zones, lim->max_active_zones);
-	if (!pool_size)
-		pool_size =
-			min(BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE, args->nr_zones);
-
-	if (!disk->zone_wplugs_hash) {
-		ret = disk_alloc_zone_resources(disk, pool_size);
-		if (ret)
-			kfree(args->zones_cond);
-	}
-
-	return ret;
+	return 0;
 }
 
 /*
@@ -2328,11 +2321,21 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
 	}
 
 	/*
-	 * Ensure that all memory allocations in this context are done as if
-	 * GFP_NOIO was specified.
+	 * Allocate zone resources if they are needed and we have not done
+	 * so yet, and initialize the revalidation arguments passed to report
+	 * zones. Ensure that all memory allocations in this context are done as
+	 * if GFP_NOIO was specified.
 	 */
 	noio_flag = memalloc_noio_save();
-	ret = disk_revalidate_zone_resources(disk, &args);
+	if (disk_need_zone_resources(disk) && !disk->zone_wplugs_hash) {
+		ret = disk_alloc_zone_resources(disk);
+		if (ret) {
+			memalloc_noio_restore(noio_flag);
+			return ret;
+		}
+	}
+
+	ret = disk_init_revalidate_args(disk, &args);
 	if (ret) {
 		memalloc_noio_restore(noio_flag);
 		return ret;
-- 
2.55.0


  parent reply	other threads:[~2026-08-06 16:04 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 16:04 [PATCH v2 00/13] Improve handling of offline and read-only zones Damien Le Moal
2026-08-06 16:04 ` [PATCH v2 01/13] block: remove disk_free_zone_resources() Damien Le Moal
2026-08-10 14:46   ` Christoph Hellwig
2026-08-06 16:04 ` Damien Le Moal [this message]
2026-08-10 14:47   ` [PATCH v2 02/13] block: refactor disk_revalidate_zone_resources() Christoph Hellwig
2026-08-06 16:04 ` [PATCH v2 03/13] block: refactor disk_update_zone_resources() Damien Le Moal
2026-08-07  9:03   ` Hannes Reinecke
2026-08-10 14:48   ` Christoph Hellwig
2026-08-06 16:04 ` [PATCH v2 04/13] block: remember a zone type regardless of its condition Damien Le Moal
2026-08-07  9:11   ` Hannes Reinecke
2026-08-10 14:52   ` Christoph Hellwig
2026-08-06 16:04 ` [PATCH v2 05/13] block: refactor bdev_zone_is_seq() Damien Le Moal
2026-08-07  9:12   ` Hannes Reinecke
2026-08-06 16:04 ` [PATCH v2 06/13] block: introduce disk_for_all_zone_wplugs() Damien Le Moal
2026-08-07 10:20   ` Hannes Reinecke
2026-08-06 16:04 ` [PATCH v2 07/13] block: drop all zone write plugs on capacity changes Damien Le Moal
2026-08-07 10:24   ` Hannes Reinecke
2026-08-06 16:04 ` [PATCH v2 08/13] block: propagate readonly and offline conditions to zone write plugs Damien Le Moal
2026-08-07 10:32   ` Hannes Reinecke
2026-08-06 16:04 ` [PATCH v2 09/13] block: always treat offline and read-only zones as dead Damien Le Moal
2026-08-07 10:46   ` Hannes Reinecke
2026-08-07 15:48     ` Damien Le Moal
2026-08-06 16:04 ` [PATCH v2 10/13] block: fail zone management operations to read-only and offline zones Damien Le Moal
2026-08-07 11:42   ` Hannes Reinecke
2026-08-06 16:04 ` [PATCH v2 11/13] block: allow read-only and offline conventional zones Damien Le Moal
2026-08-07 11:48   ` Hannes Reinecke
2026-08-06 16:04 ` [PATCH v2 12/13] block: simplify disk_zone_set_cond() Damien Le Moal
2026-08-07 11:51   ` Hannes Reinecke
2026-08-06 16:04 ` [PATCH v2 13/13] block: flag zoned disks with GENHD_FL_NO_PART Damien Le Moal
2026-08-07 11:53   ` Hannes Reinecke
2026-08-07 15:34 ` [PATCH v2 00/13] Improve handling of offline and read-only zones Bart Van Assche

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=20260806160445.848337-3-dlemoal@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    /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