From: Pankaj Raghav <p.raghav@samsung.com>
To: damien.lemoal@opensource.wdc.com, axboe@kernel.dk,
snitzer@kernel.org, hch@lst.de, agk@redhat.com
Cc: pankydev8@gmail.com, gost.dev@samsung.com,
matias.bjorling@wdc.com, hare@suse.de, bvanassche@acm.org,
linux-kernel@vger.kernel.org, dm-devel@redhat.com,
linux-nvme@lists.infradead.org, jaegeuk@kernel.org,
Johannes.Thumshirn@wdc.com, linux-block@vger.kernel.org,
Pankaj Raghav <p.raghav@samsung.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Adam Manzanares <a.manzanares@samsung.com>
Subject: [PATCH v11 01/13] block: make bdev_nr_zones and disk_zone_no generic for npo2 zone size
Date: Tue, 16 Aug 2022 15:15:24 +0200 [thread overview]
Message-ID: <20220816131536.189406-2-p.raghav@samsung.com> (raw)
In-Reply-To: <20220816131536.189406-1-p.raghav@samsung.com>
Adapt bdev_nr_zones and disk_zone_no functions so that they can
also work for non-power-of-2 zone sizes.
As the existing deployments assume that a device zone size is a power of
2 number of sectors, power-of-2 optimized calculation is used 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>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
---
block/blk-zoned.c | 13 +++++++++----
include/linux/blkdev.h | 8 +++++++-
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index a264621d4905..dce9c95b4bcd 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -111,17 +111,22 @@ EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock);
* bdev_nr_zones - Get number of zones
* @bdev: Target device
*
- * 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 bdev_nr_zones(struct block_device *bdev)
{
sector_t zone_sectors = bdev_zone_sectors(bdev);
+ sector_t capacity = bdev_nr_sectors(bdev);
if (!bdev_is_zoned(bdev))
return 0;
- return (bdev_nr_sectors(bdev) + zone_sectors - 1) >>
- ilog2(zone_sectors);
+
+ if (is_power_of_2(zone_sectors))
+ return (capacity + zone_sectors - 1) >> ilog2(zone_sectors);
+
+ return DIV_ROUND_UP_SECTOR_T(capacity, zone_sectors);
}
EXPORT_SYMBOL_GPL(bdev_nr_zones);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 84b13fdd34a7..ab82d1ff0cce 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -674,9 +674,15 @@ static inline unsigned int disk_nr_zones(struct gendisk *disk)
static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
{
+ sector_t zone_sectors = disk->queue->limits.chunk_sectors;
+
if (!blk_queue_is_zoned(disk->queue))
return 0;
- return sector >> ilog2(disk->queue->limits.chunk_sectors);
+
+ if (is_power_of_2(zone_sectors))
+ return sector >> ilog2(zone_sectors);
+
+ return div64_u64(sector, zone_sectors);
}
static inline bool disk_zone_is_seq(struct gendisk *disk, sector_t sector)
--
2.25.1
next prev parent reply other threads:[~2022-08-16 13:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20220816131537eucas1p2e8f3faef3eaf7d77ecccb6043f74c171@eucas1p2.samsung.com>
2022-08-16 13:15 ` [PATCH v11 00/13] support zoned block devices with non-power-of-2 zone sizes Pankaj Raghav
[not found] ` <CGME20220816131538eucas1p173e1c91bada451ae8a37d5b4ba3550b0@eucas1p1.samsung.com>
2022-08-16 13:15 ` Pankaj Raghav [this message]
[not found] ` <CGME20220816131539eucas1p171840f8cb3a2983274fce0322c0f4901@eucas1p1.samsung.com>
2022-08-16 13:15 ` [PATCH v11 02/13] block:rearrange bdev_{is_zoned,zone_sectors,get_queue} helpers in blkdev.h Pankaj Raghav
[not found] ` <CGME20220816131540eucas1p2f8d8579f4050da3257ee0150c194e0af@eucas1p2.samsung.com>
2022-08-16 13:15 ` [PATCH v11 03/13] block: allow blk-zoned devices to have non-power-of-2 zone size Pankaj Raghav
[not found] ` <CGME20220816131541eucas1p1a025fa0b664cb89a5c3f513863f69032@eucas1p1.samsung.com>
2022-08-16 13:15 ` [PATCH v11 04/13] nvmet: Allow ZNS target to support non-power_of_2 zone sizes Pankaj Raghav
[not found] ` <CGME20220816131543eucas1p12fd75be0a752006267bbe2c5b3b1a444@eucas1p1.samsung.com>
2022-08-16 13:15 ` [PATCH v11 05/13] nvme: zns: Allow ZNS drives that have non-power_of_2 zone size Pankaj Raghav
[not found] ` <CGME20220816131544eucas1p24ce643970cc92636f9a42d24318ab051@eucas1p2.samsung.com>
2022-08-16 13:15 ` [PATCH v11 06/13] null_blk: allow zoned devices with non power-of-2 zone sizes Pankaj Raghav
[not found] ` <CGME20220816131545eucas1p2cc7e6aad76abbe106a695f7396d38344@eucas1p2.samsung.com>
2022-08-16 13:15 ` [PATCH v11 07/13] zonefs: allow non power of 2 zoned devices Pankaj Raghav
[not found] ` <CGME20220816131546eucas1p190ff39f4a53b379b873ea83029370f4c@eucas1p1.samsung.com>
2022-08-16 13:15 ` [PATCH v11 08/13] dm-zoned: ensure only power of 2 zone sizes are allowed Pankaj Raghav
[not found] ` <CGME20220816131547eucas1p1b38862475577332351efe91e5428e295@eucas1p1.samsung.com>
2022-08-16 13:15 ` [PATCH v11 09/13] dm-zone: use generic helpers to calculate offset from zone start Pankaj Raghav
[not found] ` <CGME20220816131548eucas1p1f480f8312e3060d0f633d97a90d7c84b@eucas1p1.samsung.com>
2022-08-16 13:15 ` [PATCH v11 10/13] dm-table: allow zoned devices with non power-of-2 zone sizes Pankaj Raghav
[not found] ` <CGME20220816131549eucas1p2b7079d3222e2a3313c7bf19c712d6e0e@eucas1p2.samsung.com>
2022-08-16 13:15 ` [PATCH v11 11/13] dm: call dm_zone_endio after the target endio callback for zoned devices Pankaj Raghav
[not found] ` <CGME20220816131550eucas1p2d13098e9f0ed146ed1d01dc4dd984820@eucas1p2.samsung.com>
2022-08-16 13:15 ` [PATCH v11 12/13] dm: introduce DM_EMULATED_ZONES target type Pankaj Raghav
[not found] ` <CGME20220816131551eucas1p218faf35348e78a73aaa87d5477ecdb2e@eucas1p2.samsung.com>
2022-08-16 13:15 ` [PATCH v11 13/13] dm: add power-of-2 target for zoned devices with non power-of-2 zone sizes Pankaj Raghav
2022-08-16 16:01 ` Damien Le Moal
2022-08-17 7:35 ` Pankaj Raghav
2022-08-17 16:10 ` Damien Le Moal
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=20220816131536.189406-2-p.raghav@samsung.com \
--to=p.raghav@samsung.com \
--cc=Johannes.Thumshirn@wdc.com \
--cc=a.manzanares@samsung.com \
--cc=agk@redhat.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=damien.lemoal@opensource.wdc.com \
--cc=dm-devel@redhat.com \
--cc=gost.dev@samsung.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jaegeuk@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=matias.bjorling@wdc.com \
--cc=mcgrof@kernel.org \
--cc=pankydev8@gmail.com \
--cc=snitzer@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
all inboxes | Powered by JetHome®