All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pankaj Raghav <p.raghav@samsung.com>
To: axboe@kernel.dk, hch@lst.de, snitzer@redhat.com,
	damien.lemoal@opensource.wdc.com, hare@suse.de,
	Johannes.Thumshirn@wdc.com
Cc: linux-nvme@lists.infradead.org, dm-devel@redhat.com,
	dsterba@suse.com, jiangbo.365@bytedance.com,
	linux-kernel@vger.kernel.org, gost.dev@samsung.com,
	linux-block@vger.kernel.org, jaegeuk@kernel.org,
	Pankaj Raghav <p.raghav@samsung.com>,
	Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH v5 1/7] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze
Date: Mon, 23 May 2022 18:15:55 +0200	[thread overview]
Message-ID: <20220523161601.58078-2-p.raghav@samsung.com> (raw)
In-Reply-To: <20220523161601.58078-1-p.raghav@samsung.com>

Adapt blkdev_nr_zones and blk_queue_zone_no function so that it can
also work for non-power-of-2 zone sizes.

As the existing deployments of zoned devices had power-of-2
assumption, power-of-2 optimized calculation is kept for those devices.

There are no direct hot paths modified and the changes just
introduce one new branch per call.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed by: Adam Manzanares <a.manzanares@samsung.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
 block/blk-zoned.c      | 12 +++++++++---
 include/linux/blkdev.h |  8 +++++++-
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 38cd840d8838..e7eec513dd42 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -111,16 +111,22 @@ EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock);
  * blkdev_nr_zones - Get number of zones
  * @disk:	Target gendisk
  *
- * Return the total number of zones of a zoned block device.  For a block
- * device without zone capabilities, the number of zones is always 0.
+ * Return the total number of zones of a zoned block device, including the
+ * eventual small last zone if present. For a block device without zone
+ * capabilities, the number of zones is always 0.
  */
 unsigned int blkdev_nr_zones(struct gendisk *disk)
 {
 	sector_t zone_sectors = blk_queue_zone_sectors(disk->queue);
+	sector_t capacity = get_capacity(disk);
 
 	if (!blk_queue_is_zoned(disk->queue))
 		return 0;
-	return (get_capacity(disk) + zone_sectors - 1) >> ilog2(zone_sectors);
+
+	if (is_power_of_2(zone_sectors))
+		return (capacity + zone_sectors - 1) >> ilog2(zone_sectors);
+
+	return div64_u64(capacity + zone_sectors - 1, zone_sectors);
 }
 EXPORT_SYMBOL_GPL(blkdev_nr_zones);
 
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 60d016138997..c4e4c7071b7b 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -665,9 +665,15 @@ static inline unsigned int blk_queue_nr_zones(struct request_queue *q)
 static inline unsigned int blk_queue_zone_no(struct request_queue *q,
 					     sector_t sector)
 {
+	sector_t zone_sectors = blk_queue_zone_sectors(q);
+
 	if (!blk_queue_is_zoned(q))
 		return 0;
-	return sector >> ilog2(q->limits.chunk_sectors);
+
+	if (is_power_of_2(zone_sectors))
+		return sector >> ilog2(zone_sectors);
+
+	return div64_u64(sector, zone_sectors);
 }
 
 static inline bool blk_queue_zone_is_seq(struct request_queue *q,
-- 
2.25.1


WARNING: multiple messages have this Message-ID (diff)
From: Pankaj Raghav <p.raghav@samsung.com>
To: axboe@kernel.dk, hch@lst.de, snitzer@redhat.com,
	damien.lemoal@opensource.wdc.com, hare@suse.de,
	Johannes.Thumshirn@wdc.com
Cc: Pankaj Raghav <p.raghav@samsung.com>,
	gost.dev@samsung.com, jiangbo.365@bytedance.com,
	linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-block@vger.kernel.org, dm-devel@redhat.com,
	Luis Chamberlain <mcgrof@kernel.org>,
	dsterba@suse.com, jaegeuk@kernel.org
Subject: [dm-devel] [PATCH v5 1/7] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze
Date: Mon, 23 May 2022 18:15:55 +0200	[thread overview]
Message-ID: <20220523161601.58078-2-p.raghav@samsung.com> (raw)
In-Reply-To: <20220523161601.58078-1-p.raghav@samsung.com>

Adapt blkdev_nr_zones and blk_queue_zone_no function so that it can
also work for non-power-of-2 zone sizes.

As the existing deployments of zoned devices had power-of-2
assumption, power-of-2 optimized calculation is kept for those devices.

There are no direct hot paths modified and the changes just
introduce one new branch per call.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed by: Adam Manzanares <a.manzanares@samsung.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
 block/blk-zoned.c      | 12 +++++++++---
 include/linux/blkdev.h |  8 +++++++-
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 38cd840d8838..e7eec513dd42 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -111,16 +111,22 @@ EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock);
  * blkdev_nr_zones - Get number of zones
  * @disk:	Target gendisk
  *
- * Return the total number of zones of a zoned block device.  For a block
- * device without zone capabilities, the number of zones is always 0.
+ * Return the total number of zones of a zoned block device, including the
+ * eventual small last zone if present. For a block device without zone
+ * capabilities, the number of zones is always 0.
  */
 unsigned int blkdev_nr_zones(struct gendisk *disk)
 {
 	sector_t zone_sectors = blk_queue_zone_sectors(disk->queue);
+	sector_t capacity = get_capacity(disk);
 
 	if (!blk_queue_is_zoned(disk->queue))
 		return 0;
-	return (get_capacity(disk) + zone_sectors - 1) >> ilog2(zone_sectors);
+
+	if (is_power_of_2(zone_sectors))
+		return (capacity + zone_sectors - 1) >> ilog2(zone_sectors);
+
+	return div64_u64(capacity + zone_sectors - 1, zone_sectors);
 }
 EXPORT_SYMBOL_GPL(blkdev_nr_zones);
 
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 60d016138997..c4e4c7071b7b 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -665,9 +665,15 @@ static inline unsigned int blk_queue_nr_zones(struct request_queue *q)
 static inline unsigned int blk_queue_zone_no(struct request_queue *q,
 					     sector_t sector)
 {
+	sector_t zone_sectors = blk_queue_zone_sectors(q);
+
 	if (!blk_queue_is_zoned(q))
 		return 0;
-	return sector >> ilog2(q->limits.chunk_sectors);
+
+	if (is_power_of_2(zone_sectors))
+		return sector >> ilog2(zone_sectors);
+
+	return div64_u64(sector, zone_sectors);
 }
 
 static inline bool blk_queue_zone_is_seq(struct request_queue *q,
-- 
2.25.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


  parent reply	other threads:[~2022-05-23 16:16 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20220523161603eucas1p1719a165f769b5ad69717ad9b5f4decc3@eucas1p1.samsung.com>
2022-05-23 16:15 ` [PATCH v5 0/7] support non power of 2 zoned devices Pankaj Raghav
2022-05-23 16:15   ` [dm-devel] " Pankaj Raghav
     [not found]   ` <CGME20220523161604eucas1p2927e20dbd0602c08b6df4fc41e62dfbe@eucas1p2.samsung.com>
2022-05-23 16:15     ` Pankaj Raghav [this message]
2022-05-23 16:15       ` [dm-devel] [PATCH v5 1/7] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Pankaj Raghav
     [not found]   ` <CGME20220523161606eucas1p2676c4d47f9fcb145f69b29db1f04fe6e@eucas1p2.samsung.com>
2022-05-23 16:15     ` [PATCH v5 2/7] block: allow blk-zoned devices to have non-power-of-2 zone size Pankaj Raghav
2022-05-23 16:15       ` [dm-devel] " Pankaj Raghav
2022-05-24  5:19       ` Hannes Reinecke
2022-05-24  5:19         ` [dm-devel] " Hannes Reinecke
2022-05-24  7:10         ` Pankaj Raghav
2022-05-24  7:10           ` [dm-devel] " Pankaj Raghav
2022-05-24  7:14           ` Hannes Reinecke
2022-05-24  7:14             ` [dm-devel] " Hannes Reinecke
     [not found]   ` <CGME20220523161607eucas1p2b6245eafb81dee3e2efbec3ab86a854d@eucas1p2.samsung.com>
2022-05-23 16:15     ` [PATCH v5 3/7] nvme: zns: Allow ZNS drives that have non-power_of_2 " Pankaj Raghav
2022-05-23 16:15       ` [dm-devel] " Pankaj Raghav
2022-05-24  5:21       ` Hannes Reinecke
2022-05-24  5:21         ` [dm-devel] " Hannes Reinecke
     [not found]   ` <CGME20220523161609eucas1p16c381cd9438240905bfdb0a739132e65@eucas1p1.samsung.com>
2022-05-23 16:15     ` [PATCH v5 4/7] nvmet: Allow ZNS target to support non-power_of_2 zone sizes Pankaj Raghav
2022-05-23 16:15       ` [dm-devel] " Pankaj Raghav
     [not found]   ` <CGME20220523161610eucas1p212e81eda6b03a2d1ce8b763c9ec933ca@eucas1p2.samsung.com>
2022-05-23 16:15     ` [PATCH v5 5/7] null_blk: allow non power of 2 zoned devices Pankaj Raghav
2022-05-23 16:15       ` [dm-devel] " Pankaj Raghav
2022-05-24  2:40       ` kernel test robot
2022-05-24  2:40         ` [dm-devel] " kernel test robot
2022-05-24  7:30         ` Pankaj Raghav
2022-05-24  7:30           ` Pankaj Raghav
2022-05-24  7:30           ` [dm-devel] " Pankaj Raghav
2022-05-24 15:22           ` Nathan Chancellor
2022-05-24 15:22             ` Nathan Chancellor
2022-05-24 15:22             ` [dm-devel] " Nathan Chancellor
2022-05-24 15:32             ` Pankaj Raghav
2022-05-24 15:32               ` Pankaj Raghav
2022-05-24 15:32               ` [dm-devel] " Pankaj Raghav
2022-05-24 19:07       ` kernel test robot
2022-05-24 19:07         ` [dm-devel] " kernel test robot
     [not found]   ` <CGME20220523161612eucas1p102a76ba431c934230309042521018915@eucas1p1.samsung.com>
2022-05-23 16:16     ` [PATCH v5 6/7] null_blk: use zone_size_sects_shift for " Pankaj Raghav
2022-05-23 16:16       ` [dm-devel] " Pankaj Raghav
2022-05-23 18:11       ` Luis Chamberlain
2022-05-23 18:11         ` [dm-devel] " Luis Chamberlain
2022-05-24  5:22       ` Hannes Reinecke
2022-05-24  5:22         ` [dm-devel] " Hannes Reinecke
     [not found]   ` <CGME20220523161613eucas1p256b21b1a631324b4814465decf3958ce@eucas1p2.samsung.com>
2022-05-23 16:16     ` [PATCH v5 7/7] dm-zoned: ensure only power of 2 zone sizes are allowed Pankaj Raghav
2022-05-23 16:16       ` [dm-devel] " Pankaj Raghav

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=20220523161601.58078-2-p.raghav@samsung.com \
    --to=p.raghav@samsung.com \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=dm-devel@redhat.com \
    --cc=dsterba@suse.com \
    --cc=gost.dev@samsung.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jaegeuk@kernel.org \
    --cc=jiangbo.365@bytedance.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mcgrof@kernel.org \
    --cc=snitzer@redhat.com \
    /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 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.