From patchwork Thu May 5 13:47:01 2022
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Pankaj Raghav
X-Patchwork-Id: 12839582
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
by smtp.lore.kernel.org (Postfix) with ESMTP id 8A00FC433EF
for ; Thu, 5 May 2022 13:49:54 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1380111AbiEENxa (ORCPT );
Thu, 5 May 2022 09:53:30 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38416 "EHLO
lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with ESMTP id S1380148AbiEENxZ (ORCPT
); Thu, 5 May 2022 09:53:25 -0400
Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com
[210.118.77.11])
by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B773A59941
for ;
Thu, 5 May 2022 06:49:43 -0700 (PDT)
Received: from eucas1p1.samsung.com (unknown [182.198.249.206])
by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id
20220505134936euoutp013712fbbe55e8df83e32d2c6ac42bd912~sOayHbdz22655526555euoutp01g
for ;
Thu, 5 May 2022 13:49:36 +0000 (GMT)
DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com
20220505134936euoutp013712fbbe55e8df83e32d2c6ac42bd912~sOayHbdz22655526555euoutp01g
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com;
s=mail20170921; t=1651758576;
bh=FgRquCUlTM96nfBunGHxef/LSdqBZ3l0TN68Q/0AcX4=;
h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
b=XyR5R4cSgpoUXLDIeuACGrtgFGHgSZLsRBkOm2wd44VD2jLtIN4Cr39xkskECGdna
i+pyHUlwkm9ykzBx3RD9u33vlsBT6jdgcPKTzdDqT35Dq4QAZn2+ftoFSMgY+RPIDy
7ooQKNH/CqSKImIaJsSC5y8WcFuomVvzBHGaWVR4=
Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by
eucas1p1.samsung.com (KnoxPortal) with ESMTP id
20220505134934eucas1p1b9ba4e2f969ea7b600781ac79335c649~sOawerQ8H2600826008eucas1p1y;
Thu, 5 May 2022 13:49:34 +0000 (GMT)
Received: from eucas1p1.samsung.com ( [182.198.249.206]) by
eusmges2new.samsung.com (EUCPMTA) with SMTP id 3B.6C.09887.EE5D3726;
Thu, 5
May 2022 14:49:34 +0100 (BST)
Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by
eucas1p2.samsung.com (KnoxPortal) with ESMTPA id
20220505134934eucas1p2de726a86c47310171425a17a7ce2858b~sOav3grtd2878928789eucas1p2F;
Thu, 5 May 2022 13:49:34 +0000 (GMT)
Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by
eusmtrp2.samsung.com (KnoxPortal) with ESMTP id
20220505134934eusmtrp22744208461eabef54595df6fbd598287~sOav2mgZr2604426044eusmtrp24;
Thu, 5 May 2022 13:49:34 +0000 (GMT)
X-AuditID: cbfec7f4-45bff7000000269f-b9-6273d5eec455
Received: from eusmtip2.samsung.com ( [203.254.199.222]) by
eusmgms2.samsung.com (EUCPMTA) with SMTP id 72.2A.09404.DE5D3726;
Thu, 5
May 2022 14:49:33 +0100 (BST)
Received: from localhost (unknown [106.210.248.170]) by eusmtip2.samsung.com
(KnoxPortal) with ESMTPA id
20220505134933eusmtip2fa887742218995cb0b399247ce86bc53~sOavf3Ojp1531915319eusmtip2N;
Thu, 5 May 2022 13:49:33 +0000 (GMT)
From: Pankaj Raghav
To: axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com,
dsterba@suse.com, jaegeuk@kernel.org, bvanassche@acm.org,
hare@suse.de
Cc: jonathan.derrick@linux.dev, jiangbo.365@bytedance.com,
matias.bjorling@wdc.com, gost.dev@samsung.com, pankydev8@gmail.com,
Pankaj Raghav ,
Luis Chamberlain ,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 01/11] block: make blkdev_nr_zones and blk_queue_zone_no
generic for npo2 zsze
Date: Thu, 5 May 2022 15:47:01 +0200
Message-Id: <20220505134710.132630-2-p.raghav@samsung.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20220505134710.132630-1-p.raghav@samsung.com>
MIME-Version: 1.0
X-Brightmail-Tracker:
H4sIAAAAAAAAA+NgFrrHKsWRmVeSWpSXmKPExsWy7djPc7rvrhYnGcxrULdYfbefzWLah5/M
Fr/Pnme2uPCjkcni5oGdTBZ7Fk1isli5+iiTxZP1s5gteg58YLFY2fKQ2WLvLW2Ly7vmsFlM
aPvKbHFjwlNGi89LW9gt1tx8yuIg4HH5irfHvxNr2Dx2zrrL7nH5bKnHplWdbB4LG6Yye+y+
2QAUb73P6tG3ZRWjx/otV1k8Np+u9vi8Sc6j/UA3UwBvFJdNSmpOZllqkb5dAlfGw5k/WArm
i1Qs/xDRwHhXoIuRk0NCwERi/crXbF2MXBxCAisYJdY/m8EKkhAS+MIo0XLWHCLxmVFi6twD
jF2M7GAdE3QgwssZJa7vWcIM4bxklNi+ZglQMwcHm4CWRGMnO0hcRKCbUeJs8xsWkKHMAl1M
ErPf8IDYwgLJEgtX3WUGsVkEVCX2/vrNDmLzClhJvJx5kA3iOnmJmZe+g8U5Bawl5nQ+ZIWo
EZQ4OfMJ1Ex5ieats8GOkBBYzykx+eVidohmF4mj+0+zQNjCEq+Ob4GKy0j83zmfCcKulnh6
4zdUcwujRP/O9WwgH0gAbes7kwNiMgtoSqzfpQ9R7iix+s1OZogKPokbbwUhTuCTmLRtOlSY
V6KjTQiiWkli588nUEslJC43zYE6xkNi3vP37BMYFWcheWYWkmdmIexdwMi8ilE8tbQ4Nz21
2CgvtVyvODG3uDQvXS85P3cTIzAJnv53/M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hFUkuLc9Nzi430ihNzi0vz0vWS83M3MQJjdtuxn1t2MK589VHvECMTB+MhRgkOZiURXuel
BUlCvCmJlVWpRfnxRaU5qcWHGE2B7p7ILCWanA9MGnkl8YZmBqaGJmaWBqaWZsZK4ryeBR2J
QgLpiSWp2ampBalFMH1MHJxSDUztGixZ2zaG/L4RO6FI8Opdjg+BlT/epFT6bfpyUHzjtSdf
D2eJO95Jmm6eMqm45MrEs6IlAu3sxx//PVausa3Qr9xfTeBO9m2TuIbcdNnWHLHLDxQeRtiK
LVB+euCQlHFWpXbCj9mWohpFT+5mM+/Re/GI4YFIy5vOtb730o6nnrrW8nvyxkudqfGHTrEG
1enaxN/TcrqxqVxXsaFTRVHQPmfxanXW2x9mr+qQkxGpOpFlHSZW46wmKOgoIqf0I91JhW/b
2z3iFz58Zub2YRaP+n90zdr1j5+dEio9Yi68Ri5s5uOs3wuYKlp9qor+KZgtELVWbdjjIlhf
6VmU4bp5WgvfPNOlR/48y2b4o8RSnJFoqMVcVJwIAHdYjaJiAwAA
X-CMS-MailID: 20220505134934eucas1p2de726a86c47310171425a17a7ce2858b
X-Msg-Generator: CA
X-RootMTR: 20220505134934eucas1p2de726a86c47310171425a17a7ce2858b
X-EPHeader: CA
CMS-TYPE: 201P
X-CMS-RootMailID: 20220505134934eucas1p2de726a86c47310171425a17a7ce2858b
References: <20220505134710.132630-1-p.raghav@samsung.com>
Precedence: bulk
List-ID:
X-Mailing-List: linux-block@vger.kernel.org
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
Reviewed by: Adam Manzanares
Reviewed-by: Hannes Reinecke
Signed-off-by: Pankaj Raghav
---
block/blk-zoned.c | 14 +++++++++++---
include/linux/blkdev.h | 8 +++++++-
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 38cd840d8..a09a2eef9 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -111,16 +111,24 @@ 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 1b24c1fb3..22fe512ee 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -675,9 +675,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,
From patchwork Thu May 5 13:47:02 2022
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Pankaj Raghav
X-Patchwork-Id: 12839583
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
by smtp.lore.kernel.org (Postfix) with ESMTP id A22ADC433F5
for ; Thu, 5 May 2022 13:51:09 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1347184AbiEENyq (ORCPT );
Thu, 5 May 2022 09:54:46 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41230 "EHLO
lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with ESMTP id S1380139AbiEENyp (ORCPT
); Thu, 5 May 2022 09:54:45 -0400
Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com
[210.118.77.11])
by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11EEA57151
for ;
Thu, 5 May 2022 06:51:04 -0700 (PDT)
Received: from eucas1p1.samsung.com (unknown [182.198.249.206])
by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id
20220505135102euoutp0129406548e808c5495c1b408d96023c8a~sOcCkJBPz3179931799euoutp01K
for ;
Thu, 5 May 2022 13:51:02 +0000 (GMT)
DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com
20220505135102euoutp0129406548e808c5495c1b408d96023c8a~sOcCkJBPz3179931799euoutp01K
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com;
s=mail20170921; t=1651758662;
bh=UsMZc8nrA7AxKVTJxVI8cGyE/RIyWy6Qqg8/sjz0/6M=;
h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
b=FJet69sF1q9Aykra4Vt7GFXQCGtPdXe91oI2cZjt+v/6dRo/QdzO8B3L2M87GvQQE
KLKiMzEFAjCipzVE6pYJ8He/VMZ5FZR8lmN2pKpR9mr5/Y62dAs6XlCoVaKrNzaVzU
mcS4iAic9zHeUkToSH6fPLp9i3fsp+jpssAPvhlw=
Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by
eucas1p1.samsung.com (KnoxPortal) with ESMTP id
20220505135100eucas1p178adb274f14a57ae0ae2b6e79ce51c4e~sOcAqnyeI2591125911eucas1p15;
Thu, 5 May 2022 13:51:00 +0000 (GMT)
Received: from eucas1p1.samsung.com ( [182.198.249.206]) by
eusmges3new.samsung.com (EUCPMTA) with SMTP id 67.72.10260.446D3726;
Thu, 5
May 2022 14:51:00 +0100 (BST)
Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by
eucas1p2.samsung.com (KnoxPortal) with ESMTPA id
20220505135100eucas1p29e1b1452cc81a76460b938df339cb91a~sOcAA6CLu3233032330eucas1p2s;
Thu, 5 May 2022 13:51:00 +0000 (GMT)
Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by
eusmtrp1.samsung.com (KnoxPortal) with ESMTP id
20220505135100eusmtrp1f71c125d5d60ed706b2635b94212d3d9~sOb--zSZQ1281012810eusmtrp1j;
Thu, 5 May 2022 13:51:00 +0000 (GMT)
X-AuditID: cbfec7f5-bddff70000002814-a4-6273d6446a33
Received: from eusmtip1.samsung.com ( [203.254.199.221]) by
eusmgms2.samsung.com (EUCPMTA) with SMTP id EF.5A.09404.446D3726;
Thu, 5
May 2022 14:51:00 +0100 (BST)
Received: from localhost (unknown [106.210.248.170]) by eusmtip1.samsung.com
(KnoxPortal) with ESMTPA id
20220505135059eusmtip1b42a646b99359fa1cfd66ec590497861~sOb-pmuio0093500935eusmtip1E;
Thu, 5 May 2022 13:50:59 +0000 (GMT)
From: Pankaj Raghav
To: axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com,
dsterba@suse.com, jaegeuk@kernel.org, bvanassche@acm.org,
hare@suse.de
Cc: jonathan.derrick@linux.dev, jiangbo.365@bytedance.com,
matias.bjorling@wdc.com, gost.dev@samsung.com, pankydev8@gmail.com,
Pankaj Raghav ,
Luis Chamberlain ,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 02/11] block: allow blk-zoned devices to have
non-power-of-2 zone size
Date: Thu, 5 May 2022 15:47:02 +0200
Message-Id: <20220505134710.132630-3-p.raghav@samsung.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20220505134710.132630-1-p.raghav@samsung.com>
MIME-Version: 1.0
X-Brightmail-Tracker:
H4sIAAAAAAAAA+NgFnrAKsWRmVeSWpSXmKPExsWy7djPc7ou14qTDI5MN7BYfbefzWLah5/M
Fr/Pnme2uPCjkcni5oGdTBZ7Fk1isli5+iiTxZP1s5gteg58YLFY2fKQ2WLvLW2Ly7vmsFlM
aPvKbHFjwlNGi89LW9gt1tx8yuIg4HH5irfHvxNr2Dx2zrrL7nH5bKnHplWdbB4LG6Yye+y+
2QAUb73P6tG3ZRWjx/otV1k8Np+u9vi8Sc6j/UA3UwBvFJdNSmpOZllqkb5dAlfG/q/t7AVf
VSumtC1hamC8JNfFyMkhIWAicevkMaYuRi4OIYEVjBLTntxngXC+MEosefYbyvnMKPGtfzsr
TEvbrEPsEInljBKtb5azQjgvGSWez29h62Lk4GAT0JJo7AQrEhHoZpQ42/yGBaSbWaCLSWL2
Gx4QW1ggWuLpsRYmkHoWAVWJTyfNQcK8AlYSO7bMYYdYJi8x89J3MJtTwFpiTudDVogaQYmT
M59AjZSXaN46mxlkl4TAZk6JV/t/MEI0u0ism7UPapCwxKvjW6BsGYnTk3tYIOxqiac3fkM1
tzBK9O9cD/aABNC2vjM5ICazgKbE+l36EOWOEl87LjNDVPBJ3HgrCHECn8SkbdOhwrwSHW1C
ENVKEjt/PoFaKiFxuWkOC0SJh8ThiX4TGBVnIfllFpJfZiGsXcDIvIpRPLW0ODc9tdg4L7Vc
rzgxt7g0L10vOT93EyMwEZ7+d/zrDsYVrz7qHWJk4mA8xCjBwawkwuu8tCBJiDclsbIqtSg/
vqg0J7X4EKM0B4uSOG9y5oZEIYH0xJLU7NTUgtQimCwTB6dUA9OMCTdf6jA2vlp9+No6TvHl
u0MuTQ4wubGzzFOlJubbz7sCSyLZy9smZjtffnJDfG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uf1LOhI
FBJITyxJzU5NLUgtgulj4uCUamDK2F/Fc44p6PmNhT5ezg/O+mx/Pffo4xRlryv7LgpLFkj2
muiKuPJfjk9j43m9a+f9roakBfe+M23fZS1TyrJfek9SaPH8id12Zoapa9d2pGZz983PfXs2
MLQu9u1/xYyb33ednK4oYnHh3Yd5NbYy5TIvy5cfczhjF11WdG6uGk+xeMPdL8sMtLk7D7fE
HP22dtLF83F3vk28rJNnZqPZ41Okqq8oeE1RZcvWCJ6y6f8P/56cWm74cccib6b3K9Zyn81b
pLPiHsv0SuvnC9e3M4pMn+r388jkhF8XnjpVsbXezfE5XCnUzN//mU9WxufkjBuz70ct89zi
6LNI03Gv+okKx8zzqlLvnk8xbjuvxFKckWioxVxUnAgAKQciuGMDAAA=
X-CMS-MailID: 20220505135100eucas1p29e1b1452cc81a76460b938df339cb91a
X-Msg-Generator: CA
X-RootMTR: 20220505135100eucas1p29e1b1452cc81a76460b938df339cb91a
X-EPHeader: CA
CMS-TYPE: 201P
X-CMS-RootMailID: 20220505135100eucas1p29e1b1452cc81a76460b938df339cb91a
References: <20220505134710.132630-1-p.raghav@samsung.com>
Precedence: bulk
List-ID:
X-Mailing-List: linux-block@vger.kernel.org
Checking if a given sector is aligned to a zone is a common
operation that is performed for zoned devices. Add
blk_queue_is_zone_start helper to check for this instead of opencoding it
everywhere.
Convert the calculations on zone size to be generic instead of relying on
power_of_2 based logic in the block layer using the helpers wherever
possible.
The only hot path affected by this change for power_of_2 zoned devices
is in blk_check_zone_append() but blk_queue_is_zone_start() helper is
used to optimize the calculation for po2 zone sizes. Note that the append
path cannot be accessed by direct raw access to the block device but only
through a filesystem abstraction.
Finally, allow non power of 2 zoned devices provided that their zone
capacity and zone size are equal. The main motivation to allow non
power_of_2 zoned device is to remove the unmapped LBA between zcap and
zsze for devices that cannot have a power_of_2 zcap.
Reviewed-by: Luis Chamberlain
Signed-off-by: Pankaj Raghav
---
block/blk-core.c | 3 +--
block/blk-zoned.c | 27 +++++++++++++++++++++------
include/linux/blkdev.h | 22 ++++++++++++++++++++++
3 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/block/blk-core.c b/block/blk-core.c
index f305cb66c..b7051b7ea 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -634,8 +634,7 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q,
return BLK_STS_NOTSUPP;
/* The bio sector must point to the start of a sequential zone */
- if (pos & (blk_queue_zone_sectors(q) - 1) ||
- !blk_queue_zone_is_seq(q, pos))
+ if (!blk_queue_is_zone_start(q, pos) || !blk_queue_zone_is_seq(q, pos))
return BLK_STS_IOERR;
/*
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index a09a2eef9..4a90a999c 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -290,10 +290,10 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
return -EINVAL;
/* Check alignment (handle eventual smaller last zone) */
- if (sector & (zone_sectors - 1))
+ if (!blk_queue_is_zone_start(q, sector))
return -EINVAL;
- if ((nr_sectors & (zone_sectors - 1)) && end_sector != capacity)
+ if (!blk_queue_is_zone_start(q, nr_sectors) && end_sector != capacity)
return -EINVAL;
/*
@@ -491,14 +491,29 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx,
* smaller last zone.
*/
if (zone->start == 0) {
- if (zone->len == 0 || !is_power_of_2(zone->len)) {
- pr_warn("%s: Invalid zoned device with non power of two zone size (%llu)\n",
- disk->disk_name, zone->len);
+ if (zone->len == 0) {
+ pr_warn("%s: Invalid zone size",
+ disk->disk_name);
+ return -ENODEV;
+ }
+
+ /*
+ * Don't allow zoned device with non power_of_2 zone size with
+ * zone capacity less than zone size.
+ */
+ if (!is_power_of_2(zone->len) &&
+ zone->capacity < zone->len) {
+ pr_warn("%s: Invalid zoned size with non power of 2 zone size and zone capacity < zone size",
+ disk->disk_name);
return -ENODEV;
}
args->zone_sectors = zone->len;
- args->nr_zones = (capacity + zone->len - 1) >> ilog2(zone->len);
+ /*
+ * Division is used to calculate nr_zones for both power_of_2
+ * and non power_of_2 zone sizes as it is not in the hot path.
+ */
+ args->nr_zones = div64_u64(capacity + zone->len - 1, zone->len);
} else if (zone->start + args->zone_sectors < capacity) {
if (zone->len != args->zone_sectors) {
pr_warn("%s: Invalid zoned device with non constant zone size\n",
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 22fe512ee..32d7bd7b1 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -686,6 +686,22 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q,
return div64_u64(sector, zone_sectors);
}
+static inline bool blk_queue_is_zone_start(struct request_queue *q, sector_t sec)
+{
+ sector_t zone_sectors = blk_queue_zone_sectors(q);
+ u64 remainder = 0;
+
+ if (!blk_queue_is_zoned(q))
+ return false;
+
+ if (is_power_of_2(zone_sectors))
+ return IS_ALIGNED(sec, zone_sectors);
+
+ div64_u64_rem(sec, zone_sectors, &remainder);
+ /* if there is a remainder, then the sector is not aligned */
+ return remainder == 0;
+}
+
static inline bool blk_queue_zone_is_seq(struct request_queue *q,
sector_t sector)
{
@@ -732,6 +748,12 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q,
{
return 0;
}
+
+static inline bool blk_queue_is_zone_start(struct request_queue *q, sector_t sec)
+{
+ return false;
+}
+
static inline unsigned int queue_max_open_zones(const struct request_queue *q)
{
return 0;
From patchwork Thu May 5 13:47:04 2022
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Pankaj Raghav
X-Patchwork-Id: 12839584
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
by smtp.lore.kernel.org (Postfix) with ESMTP id 85A39C433EF
for ; Thu, 5 May 2022 13:51:14 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1380155AbiEENyu (ORCPT );
Thu, 5 May 2022 09:54:50 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41278 "EHLO
lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with ESMTP id S1380148AbiEENyr (ORCPT
); Thu, 5 May 2022 09:54:47 -0400
Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com
[210.118.77.12])
by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B205457109
for ;
Thu, 5 May 2022 06:51:06 -0700 (PDT)
Received: from eucas1p2.samsung.com (unknown [182.198.249.207])
by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id
20220505135105euoutp02ec355313bd8d9cd7567a895202231c11~sOcFEJVRO0043500435euoutp02e
for ;
Thu, 5 May 2022 13:51:05 +0000 (GMT)
DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com
20220505135105euoutp02ec355313bd8d9cd7567a895202231c11~sOcFEJVRO0043500435euoutp02e
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com;
s=mail20170921; t=1651758665;
bh=vrYMM/cTOrW0/UYYWyRRUQC9LsDHx9p6dz/qEYyG7Ug=;
h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
b=b9vcZ7tQ94f3VdiXUlJw+T1XLGmoWXNflO074KduS8EF9ysX5kXm1rt2m1oyipPJF
U50l3s5pkVpoTOl0YLZI8MqqXX9N6AQmW707OVASef5mBymqwItd13057wGOgNgTDD
KO6hTkj5nwC4MhPJeWVTwHKOJIMsISUeYasAXfkU=
Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by
eucas1p2.samsung.com (KnoxPortal) with ESMTP id
20220505135103eucas1p23cfe1abbea461339e96795ea1bacf823~sOcDQPzY83233532335eucas1p2q;
Thu, 5 May 2022 13:51:03 +0000 (GMT)
Received: from eucas1p2.samsung.com ( [182.198.249.207]) by
eusmges2new.samsung.com (EUCPMTA) with SMTP id 1C.AC.09887.746D3726;
Thu, 5
May 2022 14:51:03 +0100 (BST)
Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by
eucas1p1.samsung.com (KnoxPortal) with ESMTPA id
20220505135102eucas1p10efc01a623d97cbd6634943faa506353~sOcCcJ-_r2600826008eucas1p1D;
Thu, 5 May 2022 13:51:02 +0000 (GMT)
Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by
eusmtrp2.samsung.com (KnoxPortal) with ESMTP id
20220505135102eusmtrp2d6c56ae84c8e8295e4cea35a306dff91~sOcCX3XLs2658826588eusmtrp2C;
Thu, 5 May 2022 13:51:02 +0000 (GMT)
X-AuditID: cbfec7f4-45bff7000000269f-e9-6273d6477c32
Received: from eusmtip1.samsung.com ( [203.254.199.221]) by
eusmgms1.samsung.com (EUCPMTA) with SMTP id 5D.F2.09522.646D3726;
Thu, 5
May 2022 14:51:02 +0100 (BST)
Received: from localhost (unknown [106.210.248.170]) by eusmtip1.samsung.com
(KnoxPortal) with ESMTPA id
20220505135102eusmtip1164954ce909a59d1b207a210c6e6fd14~sOcCAQS_N0093500935eusmtip1F;
Thu, 5 May 2022 13:51:02 +0000 (GMT)
From: Pankaj Raghav
To: axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com,
dsterba@suse.com, jaegeuk@kernel.org, bvanassche@acm.org,
hare@suse.de
Cc: jonathan.derrick@linux.dev, jiangbo.365@bytedance.com,
matias.bjorling@wdc.com, gost.dev@samsung.com, pankydev8@gmail.com,
Pankaj Raghav ,
Luis Chamberlain ,
Sagi Grimberg ,
Chaitanya Kulkarni ,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-block@vger.kernel.org
Subject: [PATCH v2 04/11] nvmet: Allow ZNS target to support non-power_of_2
zone sizes
Date: Thu, 5 May 2022 15:47:04 +0200
Message-Id: <20220505134710.132630-5-p.raghav@samsung.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20220505134710.132630-1-p.raghav@sams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m/djEuaGncerrdn0hZYvHhpON+hnNMh/32tbD11n+ifXqBesupTKRNr12uJtHPd
/lHCDRY5dUJPGDVUWLiDl03duFNN33jqvZ1Nj/cxa7Yr33r9qqOorGXt+3Pe6+cut18j/O/x
JA+pWYes32zcd/1T/Ldbu3PLIjPqbZdw7XC54SxzY2e9dtDLTwZpksfWlarPtlPiKyti2Zh3
Wa9+n8qnm6+fZp66Y/84Y94uiwKp1udFrprqVmfaJbc1OWx/f2rvpS2s52/7rPaX6FtvGa8+
a+X65yGxqetNzVd+7WoMnmD388vu4xdvONxZ+uxbjFPqgfqkucuXbI6VsFJ+J6fx/M09JZbi
jERDLeai4kQAFrE/TYEDAAA=
X-CMS-MailID: 20220505135102eucas1p10efc01a623d97cbd6634943faa506353
X-Msg-Generator: CA
X-RootMTR: 20220505135102eucas1p10efc01a623d97cbd6634943faa506353
X-EPHeader: CA
CMS-TYPE: 201P
X-CMS-RootMailID: 20220505135102eucas1p10efc01a623d97cbd6634943faa506353
References: <20220505134710.132630-1-p.raghav@samsung.com>
Precedence: bulk
List-ID:
X-Mailing-List: linux-block@vger.kernel.org
A generic bdev_zone_no helper is added to calculate zone number for a given
sector in a block device. This helper internally uses blk_queue_zone_no to
find the zone number.
Use the helper bdev_zone_no() to calculate nr of zones. This let's us
make modifications to the math if needed in one place and adds now
support for npo2 zone devices.
Reviewed by: Adam Manzanares
Reviewed-by: Bart Van Assche
Reviewed-by: Hannes Reinecke
Signed-off-by: Luis Chamberlain
Signed-off-by: Pankaj Raghav
---
drivers/nvme/target/zns.c | 2 +-
include/linux/blkdev.h | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c
index 82b61acf7..5516dd6cc 100644
--- a/drivers/nvme/target/zns.c
+++ b/drivers/nvme/target/zns.c
@@ -242,7 +242,7 @@ static unsigned long nvmet_req_nr_zones_from_slba(struct nvmet_req *req)
unsigned int sect = nvmet_lba_to_sect(req->ns, req->cmd->zmr.slba);
return blkdev_nr_zones(req->ns->bdev->bd_disk) -
- (sect >> ilog2(bdev_zone_sectors(req->ns->bdev)));
+ bdev_zone_no(req->ns->bdev, sect);
}
static unsigned long get_nr_zones_from_buf(struct nvmet_req *req, u32 bufsize)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 32d7bd7b1..967790f51 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1370,6 +1370,13 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev)
return 0;
}
+static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec)
+{
+ struct request_queue *q = bdev_get_queue(bdev);
+
+ return blk_queue_zone_no(q, sec);
+}
+
static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
{
struct request_queue *q = bdev_get_queue(bdev);
From patchwork Thu May 5 13:47:10 2022
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Pankaj Raghav
X-Patchwork-Id: 12839611
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
by smtp.lore.kernel.org (Postfix) with ESMTP id 2AACDC433F5
for ; Thu, 5 May 2022 13:51:48 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1378788AbiEENzY (ORCPT );
Thu, 5 May 2022 09:55:24 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41932 "EHLO
lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with ESMTP id S1380158AbiEENzG (ORCPT
); Thu, 5 May 2022 09:55:06 -0400
Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com
[210.118.77.12])
by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4A6C57B11
for ;
Thu, 5 May 2022 06:51:14 -0700 (PDT)
Received: from eucas1p1.samsung.com (unknown [182.198.249.206])
by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id
20220505135113euoutp0257883721688f3c153e1114269fbc2e7c~sOcMExWuC0106901069euoutp02D
for ;
Thu, 5 May 2022 13:51:13 +0000 (GMT)
DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com
20220505135113euoutp0257883721688f3c153e1114269fbc2e7c~sOcMExWuC0106901069euoutp02D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com;
s=mail20170921; t=1651758673;
bh=D05Y2RArrxR/ZcNMh/RJzrqiPuoU2BIWW0WuxZX2YSQ=;
h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
b=AVnq6TSnIid+zbL06EOGkBSL2O2TkR13NExMANbNJi+q+cDC0F4SVYMeHkkGmXaso
jsh698805thBcg3VdtBGAin4C29T5s1PuG6Rv6dUVZseHbBObdreYkrtUpFxJ5rf7i
pxwqPDEtjMj1WBUiXM0sNQF2Q7fKEmQlzfaC3IYw=
Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by
eucas1p1.samsung.com (KnoxPortal) with ESMTP id
20220505135111eucas1p11ac926dfc697a45ef23092a11af516e6~sOcKakWSP1070010700eucas1p1H;
Thu, 5 May 2022 13:51:11 +0000 (GMT)
Received: from eucas1p1.samsung.com ( [182.198.249.206]) by
eusmges1new.samsung.com (EUCPMTA) with SMTP id 22.0D.10009.F46D3726;
Thu, 5
May 2022 14:51:11 +0100 (BST)
Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by
eucas1p1.samsung.com (KnoxPortal) with ESMTPA id
20220505135110eucas1p1fc49b2574920b9a2a274f9d77feb5d18~sOcJuHBiZ2591125911eucas1p1J;
Thu, 5 May 2022 13:51:10 +0000 (GMT)
Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by
eusmtrp1.samsung.com (KnoxPortal) with ESMTP id
20220505135110eusmtrp165d3f6c9363c20b14b019590934c8c59~sOcJtOm2O1365913659eusmtrp1L;
Thu, 5 May 2022 13:51:10 +0000 (GMT)
X-AuditID: cbfec7f2-e95ff70000002719-4f-6273d64f4513
Received: from eusmtip2.samsung.com ( [203.254.199.222]) by
eusmgms2.samsung.com (EUCPMTA) with SMTP id 2C.6A.09404.E46D3726;
Thu, 5
May 2022 14:51:10 +0100 (BST)
Received: from localhost (unknown [106.210.248.170]) by eusmtip2.samsung.com
(KnoxPortal) with ESMTPA id
20220505135110eusmtip2d2bc0b30a6c2752fd7d0ead76cf2177e~sOcJWiFKS1656016560eusmtip2R;
Thu, 5 May 2022 13:51:10 +0000 (GMT)
From: Pankaj Raghav
To: axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com,
dsterba@suse.com, jaegeuk@kernel.org, bvanassche@acm.org,
hare@suse.de
Cc: jonathan.derrick@linux.dev, jiangbo.365@bytedance.com,
matias.bjorling@wdc.com, gost.dev@samsung.com, pankydev8@gmail.com,
Pankaj Raghav ,
Luis Chamberlain ,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 10/11] null_blk: allow non power of 2 zoned devices
Date: Thu, 5 May 2022 15:47:10 +0200
Message-Id: <20220505134710.132630-11-p.raghav@samsung.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20220505134710.132630-1-p.raghav@samsung.com>
MIME-Version: 1.0
X-Brightmail-Tracker:
H4sIAAAAAAAAA+NgFnrIKsWRmVeSWpSXmKPExsWy7djPc7r+14qTDK4d47FYfbefzWLah5/M
Fr/Pnme2uPCjkcni5oGdTBZ7Fk1isli5+iiTxZP1s5gteg58YLFY2fKQ2WLvLW2Ly7vmsFlM
aPvKbHFjwlNGi89LW9gt1tx8yuIg4HH5irfHvxNr2Dx2zrrL7nH5bKnHplWdbB4LG6Yye+y+
2QAUb73P6tG3ZRWjx/otV1k8Np+u9vi8Sc6j/UA3UwBvFJdNSmpOZllqkb5dAlfGrrnbmQse
61acfvWCuYFxvUoXIyeHhICJxIvrTxm7GLk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CA
X-RootMTR: 20220505135110eucas1p1fc49b2574920b9a2a274f9d77feb5d18
X-EPHeader: CA
CMS-TYPE: 201P
X-CMS-RootMailID: 20220505135110eucas1p1fc49b2574920b9a2a274f9d77feb5d18
References: <20220505134710.132630-1-p.raghav@samsung.com>
Precedence: bulk
List-ID:
X-Mailing-List: linux-block@vger.kernel.org
Convert the power of 2 based calculation with zone size to be generic in
null_zone_no with optimization for power of 2 based zone sizes.
The nr_zones calculation in null_init_zoned_dev has been replaced with a
division without special handling for power of 2 based zone sizes as
this function is called only during the initialization and will not
invoked in the hot path.
Performance Measurement:
Device:
zone size = 128M, blocksize=4k
FIO cmd:
fio --name=zbc --filename=/dev/nullb0 --direct=1 --zonemode=zbd --size=23G
--io_size= --ioengine=io_uring --iodepth= --rw= --bs=4k
--loops=4
The following results are an average of 4 runs on AMD Ryzen 5 5600X with
32GB of RAM:
Sequential Write:
x-----------------x---------------------------------x---------------------------------x
| IOdepth | 8 | 16 |
x-----------------x---------------------------------x---------------------------------x
| | KIOPS |BW(MiB/s) | Lat(usec) | KIOPS |BW(MiB/s) | Lat(usec) |
x-----------------x---------------------------------x---------------------------------x
| Without patch | 578 | 2257 | 12.80 | 576 | 2248 | 25.78 |
x-----------------x---------------------------------x---------------------------------x
| With patch | 581 | 2268 | 12.74 | 576 | 2248 | 25.85 |
x-----------------x---------------------------------x---------------------------------x
Sequential read:
x-----------------x---------------------------------x---------------------------------x
| IOdepth | 8 | 16 |
x-----------------x---------------------------------x---------------------------------x
| | KIOPS |BW(MiB/s) | Lat(usec) | KIOPS |BW(MiB/s) | Lat(usec) |
x-----------------x---------------------------------x---------------------------------x
| Without patch | 667 | 2605 | 11.79 | 675 | 2637 | 23.49 |
x-----------------x---------------------------------x---------------------------------x
| With patch | 667 | 2605 | 11.79 | 675 | 2638 | 23.48 |
x-----------------x---------------------------------x---------------------------------x
Random read:
x-----------------x---------------------------------x---------------------------------x
| IOdepth | 8 | 16 |
x-----------------x---------------------------------x---------------------------------x
| | KIOPS |BW(MiB/s) | Lat(usec) | KIOPS |BW(MiB/s) | Lat(usec) |
x-----------------x---------------------------------x---------------------------------x
| Without patch | 522 | 2038 | 15.05 | 514 | 2006 | 30.87 |
x-----------------x---------------------------------x---------------------------------x
| With patch | 522 | 2039 | 15.04 | 523 | 2042 | 30.33 |
x-----------------x---------------------------------x---------------------------------x
Minor variations are noticed in Sequential write with io depth 8 and
in random read with io depth 16. But overall no noticeable differences
were noticed
Reviewed-by: Luis Chamberlain
Reviewed by: Adam Manzanares
Reviewed-by: Hannes Reinecke
Signed-off-by: Pankaj Raghav
---
drivers/block/null_blk/main.c | 5 ++---
drivers/block/null_blk/zoned.c | 14 +++++++-------
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 5cb4c92cd..ed9a58201 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1929,9 +1929,8 @@ static int null_validate_conf(struct nullb_device *dev)
if (dev->queue_mode == NULL_Q_BIO)
dev->mbps = 0;
- if (dev->zoned &&
- (!dev->zone_size || !is_power_of_2(dev->zone_size))) {
- pr_err("zone_size must be power-of-two\n");
+ if (dev->zoned && !dev->zone_size) {
+ pr_err("zone_size must not be zero\n");
return -EINVAL;
}
diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
index dae54dd1a..00c34e65e 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -13,7 +13,10 @@ static inline sector_t mb_to_sects(unsigned long mb)
static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect)
{
- return sect >> ilog2(dev->zone_size_sects);
+ if (is_power_of_2(dev->zone_size_sects))
+ return sect >> ilog2(dev->zone_size_sects);
+
+ return div64_u64(sect, dev->zone_size_sects);
}
static inline void null_lock_zone_res(struct nullb_device *dev)
@@ -62,10 +65,6 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
sector_t sector = 0;
unsigned int i;
- if (!is_power_of_2(dev->zone_size)) {
- pr_err("zone_size must be power-of-two\n");
- return -EINVAL;
- }
if (dev->zone_size > dev->size) {
pr_err("Zone size larger than device capacity\n");
return -EINVAL;
@@ -83,8 +82,9 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
zone_capacity_sects = mb_to_sects(dev->zone_capacity);
dev_capacity_sects = mb_to_sects(dev->size);
dev->zone_size_sects = mb_to_sects(dev->zone_size);
- dev->nr_zones = round_up(dev_capacity_sects, dev->zone_size_sects)
- >> ilog2(dev->zone_size_sects);
+ dev->nr_zones =
+ div64_u64(roundup(dev_capacity_sects, dev->zone_size_sects),
+ dev->zone_size_sects);
dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct nullb_zone),
GFP_KERNEL | __GFP_ZERO);