From patchwork Fri May 6 08:10:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12840707 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 9F8CAC433F5 for ; Fri, 6 May 2022 08:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389841AbiEFIO7 (ORCPT ); Fri, 6 May 2022 04:14:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389834AbiEFIO6 (ORCPT ); Fri, 6 May 2022 04:14:58 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDEE367D2C for ; Fri, 6 May 2022 01:11:13 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081110euoutp02b7df3bfe44675fcc914ff811053a0e55~sdckhPfFM2349323493euoutp02u for ; Fri, 6 May 2022 08:11:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220506081110euoutp02b7df3bfe44675fcc914ff811053a0e55~sdckhPfFM2349323493euoutp02u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824670; bh=lp2K3w6bYU/ZGZyfjOrT9sOG4NQYsIr+x+HLsdgsemk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AcGo/loWZtX/HhUmelZDOIL72Pc0R5AMpwfSstxXD8NYUkRcC1DptVlRK6AisouRi 4vp32SxkE3HRp2VYokX3yFi2V0A3IQdIY0J02c0xeFI4whIEDyd6G6stCx55/J1pzz /ow+vFK9N8qUZ0bwkJY3AjnFhgFmshGnLT//KyUs= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220506081108eucas1p157bd0b3e2c1c9e95cb15481355714182~sdcioadXK1692416924eucas1p1u; Fri, 6 May 2022 08:11:08 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 93.3C.10260.B18D4726; Fri, 6 May 2022 09:11:07 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220506081107eucas1p1070e00b208e00090c235017435be1593~sdciCeg161979919799eucas1p1f; Fri, 6 May 2022 08:11:07 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220506081107eusmtrp2f9facb08d5d065dc059e123c7ff68edc~sdch_Ke7I2593625936eusmtrp2Q; Fri, 6 May 2022 08:11:07 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-cf-6274d81b13d3 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id AA.E9.09404.B18D4726; Fri, 6 May 2022 09:11:07 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220506081106eusmtip18f256f486b1f42e6f968c5b64f6e9360~sdchn8WJL0467104671eusmtip1n; Fri, 6 May 2022 08:11:06 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 01/11] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Fri, 6 May 2022 10:10:55 +0200 Message-Id: <20220506081105.29134-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Sf1CTdRzH+z7Ps2eDa97j4PR7Ds/akSQeQ6PiW3JBR1cPanfaHxV5V83x hOg2bAOMVsqPheOH2xiXypT8ARZgMHH8cLARxzUQwcaBFDANyU1jFhDDaOBBjIcu/3t9Pp/3 +/v+fO6+PFxQT27gpSkyGKVCIhORwURzl98ZJRzO2L+t53eEzDe6cLRk6yLR5Tt6Ep2c9uPI qD/NRQs3nTiyT57hoP5/cjE00mHFkO2iEUM1lx0YcptNOCrpmCZQjWYcR4/Ht6Px2VECGTt/ BsgzZMKQfXQrGrhXzUU2ew+BBlvPkujctx4uMhQ8wtGwwQNQabeFg3yXNFxU/3CKQNdHhQkb 6cFbu+jF69+TdGn+JJd2/tpA0IM3M+mrtYUkfSHna5y2VB2j20ZySPpE/iRJW78a49BT7UMk rWusBbS5cYigLb1q2mBp4OwRfBAcl8LI0rIYZfRrHwcf0FVeBIfLQz/r8JVhOWCUKgJBPEi9 CKu8uZwAC6hqAEsdsUUgeJlnAfyt0gjYwgfg34VusgjwVhyLP7zD9r8D0PLLDS5bTADon8gB ARFJRcLcwpV+KFUMoH7sODcQgVMWDuyv+yTAIZQUNvQ/JgJMUM/Bxh99K8ynXoEXWqyAXW8T LB+YW/EGUa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KVnU5RfWpKqkJFfXGKrFG1oYaRnaGmhZ2RiqWdobB5rZWSqpG9nk5Kak1mW WqRvl6CX0bd4EWPBTJGKA58nMzUw3hLoYuTgkBAwkfi3P6iLkYtDSGApo8TEb/vYuhg5geIS ErcXNjFC2MISf651sUEUPWeU6Hj/jxWkmU1AS6Kxkx0kLiIwlVHi0rqTLCAOs8BpVomtmw4w gRQJCyRKTH6iBTKIRUBVYsuRzywgNq+ApcTC7TuhFshLzLz0nR3E5hSwkmia/BLsCCGgmvlL 9rBC1AtKnJz5BKyXGai+eets5gmMArOQpGYhSS1gZFrFKJJaWpybnltspFecmFtcmpeul5yf u4kRmFC2Hfu5ZQfjylcf9Q4xMnEwHmKU4GBWEuEVnlWSJMSbklhZlVqUH19UmpNafIjRFOju icxSosn5wJSWVxJvaGZgamhiZmlgamlmrCTO61nQkSgkkJ5YkpqdmlqQWgTTx8TBKdXAJFFc pd2j01e94Lmozdn3p+L936yzjWHZ67vwFJ+XjtpdE77ru/NSvqV29leESywQay1Ru3H6b/ih r2fn7Jt0fYbg/G0pq3ucVjvNXXYv9W22trHKU/PYWXO/FywzKdNL9DNfs2K22ROnfRO2Oizs UrN6xa0Y3fKua/an0ILM+C3cn7oXt91It5aZ/Hxyu32s4xmjy22Xdh5LWX930dfclTWWr/60 ylg8a+/f72u9+4PkpIzC4xbPOWbWWP+5xvVffreqc2PY8/ScxR0p86VXCsQuCj2ob/uBeZFY Hut+rmxX1bOlKbNfHLzP4h6/4Gz79SlxJksecT/bdFFvV+qsme+bgl6qme9kni5loxCySIml OCPRUIu5qDgRAH4I+hKxAwAA X-CMS-MailID: 20220506081107eucas1p1070e00b208e00090c235017435be1593 X-Msg-Generator: CA X-RootMTR: 20220506081107eucas1p1070e00b208e00090c235017435be1593 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081107eucas1p1070e00b208e00090c235017435be1593 References: <20220506081105.29134-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 | 13 ++++++++++--- include/linux/blkdev.h | 8 +++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 38cd840d8..140230134 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -111,16 +111,23 @@ 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 Fri May 6 08:10:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12840711 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 5CB44C433EF for ; Fri, 6 May 2022 08:11:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389835AbiEFIPQ (ORCPT ); Fri, 6 May 2022 04:15:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389834AbiEFIPA (ORCPT ); Fri, 6 May 2022 04:15:00 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0182D53A53 for ; Fri, 6 May 2022 01:11:18 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081110euoutp015d94328d0fb2f2aed39f15ba1673e44c~sdclOO7n22290722907euoutp014 for ; Fri, 6 May 2022 08:11:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220506081110euoutp015d94328d0fb2f2aed39f15ba1673e44c~sdclOO7n22290722907euoutp014 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824670; bh=qm0Anrgo2LRVYYSLS0+cudW9OU5s2MlxyVDAMmEqCV0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KgVGAgJ7IhydgqnUmVeHw7z7ZrJrVQET7erqChqjXzRd9D7ZHs1stTZFW0gVqKMRT n62Jx7UEstbPY+qdioxjzNz9Ab21opXKE23M3lo6GwC7bl49Mfe5icj89kW6JMy2o+ XH5CdyJWCnObOMyl3E9Gzikdo99hv40XFyxS6+2U= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220506081109eucas1p295781fbeaf12c041e70e48545704d25f~sdcjnj07r1186311863eucas1p2G; Fri, 6 May 2022 08:11:09 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 94.05.09887.C18D4726; Fri, 6 May 2022 09:11:08 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220506081108eucas1p2ca72ccafb05dfdcc5b8ba9393da1ce60~sdcjBJ5f41330313303eucas1p2P; Fri, 6 May 2022 08:11:08 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220506081108eusmtrp1cd3eeb0040d1f44067a31d3ea2623ed1~sdci_xet53086630866eusmtrp1c; Fri, 6 May 2022 08:11:08 +0000 (GMT) X-AuditID: cbfec7f4-471ff7000000269f-2b-6274d81c9af8 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id CA.E2.09522.C18D4726; Fri, 6 May 2022 09:11:08 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220506081108eusmtip19260a40a3b2603466a9a3224b90303cb~sdcip8bxI0384703847eusmtip1X; Fri, 6 May 2022 08:11:08 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 02/11] block: allow blk-zoned devices to have non-power-of-2 zone size Date: Fri, 6 May 2022 10:10:56 +0200 Message-Id: <20220506081105.29134-3-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Se0xbZRzdd+/tvRe03V1p0o+BI5AtmzPAwCV+AkGNmNzEOJ3JYpyiK3DX kfFY+pggTjte4yWUsol0RLc5BcrL0YqWwRiNQBEGhFItJIBlsAyUR6VMeQhSLov775zvd853 zi/50bi4gdxLJ6aoOEWKLCmI9Caau1b6g/0dqrgjlnWEGn/pwtFmaxeJasdKSPTF4gqOdCVf Umjt3gCO2uavCtDgPxcxNHLXjKHWGzoM1dR2YmiqUY+joruLBKrJduJo3RmGnO5RAuksvwI0 bddjqG30OTR0v5pCrW09BLK1VJLo6++mKaTNXcaRQzsNUGm3UYCWvs2mUMMfCwSyjvq9/Axr G36d3bDWkWxp1jzFDozfIljbPTXbZMgn2euaKzhrvPkZe3tEQ7KfZ82TrDlnQsAu3LGTbLHJ ANhGk51gjb0ZrNZ4S/CW+KR3VAKXlHieU4RGn/I+Y6+Zos4tH0i7X24HGjC0rwB40ZA5Cq+v asgC4E2LmWoAb9qyd4gbwMrZhzhPlgB0OnXkY0uWPY/iB1UADufUYjyZAdBkHdkiNE0yh+HF /G2RhCkEsGTiEuVx44xRAAfrT3uwD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rx/t9V9k8+rasYvRYv+Uqi8fm 09UeEzZvZA0QitKzKcovLUlVyMgvLrFVija0MNIztLTQMzKx1DM0No+1MjJV0rezSUnNySxL LdK3S9DLuLryCXvBV9WKx9OvMjYwXpLrYuTkkBAwkWi+2sHexcjFISSwlFHix9QLLBAJCYnb C5sYIWxhiT/Xutggip4zSiyacZG1i5GDg01AS6KxE6xZRGAqo8SldSdZQBxmgdOsEls3HWAC 6RYWiJTo7r0MNolFQFXiQ+tHZpBmXgFLiTVXeCEWyEvMvPSdHcTmFLCSaJr8kg3EFgIqmb9k DyuIzSsgKHFy5hOw45iB6pu3zmaewCgwC0lqFpLUAkamVYwiqaXFuem5xYZ6xYm5xaV56XrJ +bmbGIEpZduxn5t3MM579VHvECMTB+MhRgkOZiURXuFZJUlCvCmJlVWpRfnxRaU5qcWHGE2B zp7ILCWanA9Mankl8YZmBqaGJmaWBqaWZsZK4ryeBR2JQgLpiSWp2ampBalFMH1MHJxSDUxr FV9/kDLRu+sVyHzK9t4+hUXFJc/08xr3zTp29lCdmA1H9r8z8ZuvfPVZ05df6mk/p4x/thnX XpHXT1+5fJ5iWGz+7Ejjr5My6WG7z+799r9PurructaXfT7916SEG5/x3duY9z4uvCUgdvLt QyUXzy02vql9Rf3yu0lXzf8rm+Tlf/Xe+qZvGhN/snFhQqDq8n13ru4VCVN++qH20b3/ien7 Nlo4GJ7QszV5oNRxxLp5hdiCxqdKP5x752XOqpE3ZKt88SBcgY+NJUtrD1N/xMPSj9vCzHlN zXSDH/16qCfXfZPbw6z7wla19yx7EzaHiR8pZjzyjuWh3iT7ygT3Kf//bLH4WCGha/0wqEmJ pTgj0VCLuag4EQASMj+OsgMAAA== X-CMS-MailID: 20220506081108eucas1p2ca72ccafb05dfdcc5b8ba9393da1ce60 X-Msg-Generator: CA X-RootMTR: 20220506081108eucas1p2ca72ccafb05dfdcc5b8ba9393da1ce60 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081108eucas1p2ca72ccafb05dfdcc5b8ba9393da1ce60 References: <20220506081105.29134-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 140230134..cfc2fb804 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -289,10 +289,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; /* @@ -490,14 +490,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 Fri May 6 08:10:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12840710 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 07E59C43219 for ; Fri, 6 May 2022 08:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389861AbiEFIPO (ORCPT ); Fri, 6 May 2022 04:15:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389835AbiEFIPG (ORCPT ); Fri, 6 May 2022 04:15:06 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 367D967D28 for ; Fri, 6 May 2022 01:11:18 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081111euoutp01665c812a21806f6dcf5d921ea5c8ae3a~sdcmJwYRA2197721977euoutp01O for ; Fri, 6 May 2022 08:11:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220506081111euoutp01665c812a21806f6dcf5d921ea5c8ae3a~sdcmJwYRA2197721977euoutp01O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824671; bh=IJFvu7Txlqq4QbkiUAdYp5LUxrFDgYD73zO+DTftg+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ti0TDsRWtQcoTqksGh7F0d3wO/5pt9G3DViOyIP1msJDOgSCY2kWwcLms0a9JMkyf rz950fE0dgAHycnefUHeiPdOibwkV3cHYwxuu1ytDz0aNeOL79BCwHzK9HuyIb0bHq Wc6PYMKdep578eJIilYCXMW2mJRCRs/8HqVm26t8= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220506081110eucas1p2cfc43e30c9c38c97e466527376ef9f90~sdckiaQVi1314813148eucas1p2Z; Fri, 6 May 2022 08:11:10 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 96.05.09887.D18D4726; Fri, 6 May 2022 09:11:09 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220506081109eucas1p26bbb68a1740b1af923ed862a93112780~sdcj-rG7n1919419194eucas1p2Q; Fri, 6 May 2022 08:11:09 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220506081109eusmtrp2db398a0a3f09537f71805983a29bb2c9~sdcj_iEtg2593625936eusmtrp2V; Fri, 6 May 2022 08:11:09 +0000 (GMT) X-AuditID: cbfec7f4-471ff7000000269f-2d-6274d81df581 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 9D.E9.09404.D18D4726; Fri, 6 May 2022 09:11:09 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220506081109eusmtip22afa82e359d99dbc946388ce73357abc~sdcjmtyWb1925719257eusmtip28; Fri, 6 May 2022 08:11:09 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 03/11] nvme: zns: Allow ZNS drives that have non-power_of_2 zone size Date: Fri, 6 May 2022 10:10:57 +0200 Message-Id: <20220506081105.29134-4-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01SbUxTVxjeuff29lKtu7RGDiox6z4SIYAYNQdcHG5k3m3qdMk+QqZb0Tsg FjAtzDl+WIGBgCsFYYwWpDD5BosUyLCwkW7jGwUqs3YDSgdxYFZorDIsgVluzfz3PO/7POd9 nzeHwkXN5FYqPjGZlSdKZRJSQLT3LN8KDrAkx+yaHYpA+oEeHK119pCoYSKPRN8tLuOoIO97 PnIP38ZRl0PLQyP/XsTQve4ODHVWFmCoruE3DM3oNTi63L1IoLqMaRytTIehaZeVQAWm3wGa HddgqMsahMb+quWjzq5+AplvlpKovHqWj9SZj3BkUc8ClN9r4KGHVRl8dP3BAoH6rNsiAxjz nfeY1b5GkslPd/CZ25M3CMY8nMK01GeTTIWyCGcM1y4wxntKkvk23UEyHd9M8ZiFn8ZJRtVa Dxh96zjBGAZTGbXhBu+YKFrw+mlWFv8lKw898Lkgrk1XiJ1t3fKV09pNKEGTKAf4UJDeA92P ikAOEFAiuhZAq82Ic8QFYPr1uzyOPASw26HkP7MUXs73NmoAbG4ZwjgyB+DAip3MARRF0oHw YjbfU99M5wKYN5W17sZpAw+ONH3hwWI6Gg45npAeTNC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V9k8+rasYvRYv+Uqi8fm 09UeEzZvZA0QitKzKcovLUlVyMgvLrFVija0MNIztLTQMzKx1DM0No+1MjJV0rezSUnNySxL LdK3S9DL2LpgClPBFrGKj7cOsDQwrhXqYuTkkBAwkZjSM5G1i5GLQ0hgKaPEk5cfGSESEhK3 FzZB2cISf651sUEUPWeU+HX9IFMXIwcHm4CWRGMnO0hcRGAqo8SldSdZQBxmgdOsEls3HWAC 6RYWiJDoO3UWzGYRUJU41HADzOYVsJTY9v0dC8QGeYmZl76zg9icAlYSTZNfsoHYQkA185fs YYWoF5Q4OfMJWD0zUH3z1tnMExgFZiFJzUKSWsDItIpRJLW0ODc9t9hIrzgxt7g0L10vOT93 EyMwqWw79nPLDsaVrz7qHWJk4mA8xCjBwawkwis8qyRJiDclsbIqtSg/vqg0J7X4EKMp0N0T maVEk/OBaS2vJN7QzMDU0MTM0sDU0sxYSZzXs6AjUUggPbEkNTs1tSC1CKaPiYNTqoGJYZaH oMzujjB13YSji04LiYfp7lthlhT+O1X7+ekjgseaumLvrX8l/79ad+f3PXdkDvwT6Hu7sosz iuPlCo7cK1LMCa33/8pKeZrNmC+9oOXLF7ZA5+sRfHMr8kK35UyccUNHQ3D3Xu35k2WjH8st 6aiLSpn13HOVjsIB39Apz0LedrLUzOc8x/XY5HZFYrV9uxX35lsLb7w+6/SjMcLW6v7TSzlZ s7bkTp0lHF4dvO3o/oNqx99qtiyUYEw7Lv+o3/ju0XqrH7Hsa63vrC//cjLgupHL9tv3J2+d lPR5zgGf830h6geOLKsrtl5nPKPQ1P7m1R69a8tzzrAkZEUd1f1b9qaMZ03noT32BkcalFiK MxINtZiLihMBVhMFw7MDAAA= X-CMS-MailID: 20220506081109eucas1p26bbb68a1740b1af923ed862a93112780 X-Msg-Generator: CA X-RootMTR: 20220506081109eucas1p26bbb68a1740b1af923ed862a93112780 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081109eucas1p26bbb68a1740b1af923ed862a93112780 References: <20220506081105.29134-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Remove the condition which disallows non-power_of_2 zone size ZNS drive to be updated and use generic method to calculate number of zones instead of relying on log and shift based calculation on zone size. The power_of_2 calculation has been replaced directly with generic calculation without special handling. Both modified functions are not used in hot paths, they are only used during initialization & revalidation of the ZNS device. Reviewed-by: Luis Chamberlain Reviewed by: Adam Manzanares Signed-off-by: Pankaj Raghav --- drivers/nvme/host/zns.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index 9f81beb4d..65d2aa68a 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -101,13 +101,6 @@ int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf) } ns->zsze = nvme_lba_to_sect(ns, le64_to_cpu(id->lbafe[lbaf].zsze)); - if (!is_power_of_2(ns->zsze)) { - dev_warn(ns->ctrl->device, - "invalid zone size:%llu for namespace:%u\n", - ns->zsze, ns->head->ns_id); - status = -ENODEV; - goto free_data; - } blk_queue_set_zoned(ns->disk, BLK_ZONED_HM); blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); @@ -128,8 +121,13 @@ static void *nvme_zns_alloc_report_buffer(struct nvme_ns *ns, const size_t min_bufsize = sizeof(struct nvme_zone_report) + sizeof(struct nvme_zone_descriptor); + /* + * Division is used to calculate nr_zones with no special handling + * for power of 2 zone sizes as this function is not invoked in a + * hot path + */ nr_zones = min_t(unsigned int, nr_zones, - get_capacity(ns->disk) >> ilog2(ns->zsze)); + div64_u64(get_capacity(ns->disk), ns->zsze)); bufsize = sizeof(struct nvme_zone_report) + nr_zones * sizeof(struct nvme_zone_descriptor); @@ -182,6 +180,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector, int ret, zone_idx = 0; unsigned int nz, i; size_t buflen; + u64 remainder = 0; if (ns->head->ids.csi != NVME_CSI_ZNS) return -EINVAL; @@ -197,7 +196,14 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector, c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL; c.zmr.pr = NVME_REPORT_ZONE_PARTIAL; - sector &= ~(ns->zsze - 1); + /* + * rounddown the sector value to the nearest zone size. roundown macro + * provided in math.h will not work for 32 bit architectures. + * Division is used here with no special handling for power of 2 + * zone sizes as this function is not invoked in a hot path + */ + div64_u64_rem(sector, ns->zsze, &remainder); + sector -= remainder; while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) { memset(report, 0, buflen); From patchwork Fri May 6 08:10:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12840708 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 8F690C433F5 for ; Fri, 6 May 2022 08:11:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389884AbiEFIPI (ORCPT ); Fri, 6 May 2022 04:15:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389827AbiEFIO7 (ORCPT ); Fri, 6 May 2022 04:14:59 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46BE567D1C for ; Fri, 6 May 2022 01:11:17 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081112euoutp021c27ef3d3cb3919d34de889459ae50c5~sdcnPxdeI2355923559euoutp02t for ; Fri, 6 May 2022 08:11:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220506081112euoutp021c27ef3d3cb3919d34de889459ae50c5~sdcnPxdeI2355923559euoutp02t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824673; bh=vrYMM/cTOrW0/UYYWyRRUQC9LsDHx9p6dz/qEYyG7Ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mmTePLGw4WStsyva52M2FKpil6omiccqCPYZ4GIQEsZ//VNJXoXEYLaOqeWV10nuU H1KB/2RLGV3AAL91mXIlKUu1yvrmAsSoKUK3i9resOCgmy5mYJoxFff3E0dVac7DiF zuJl0kHbOaDAUn2cOtbKeKzSTj1SPHrWhq/K78Zk= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220506081110eucas1p29f4ec4b6163302f91ffd1654e9132bc4~sdclV3MUy0616806168eucas1p2n; Fri, 6 May 2022 08:11:10 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id C8.05.09887.E18D4726; Fri, 6 May 2022 09:11:10 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220506081110eucas1p1b6c624ddca1c41b9838bb5b85f8ca5ff~sdck9wLVm1797017970eucas1p1B; Fri, 6 May 2022 08:11:10 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220506081110eusmtrp222f0eafc663deb2c7f6b2252e5b9e61c~sdck8jKjJ2593625936eusmtrp2X; Fri, 6 May 2022 08:11:10 +0000 (GMT) X-AuditID: cbfec7f4-471ff7000000269f-31-6274d81ece15 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 82.F2.09522.E18D4726; Fri, 6 May 2022 09:11:10 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220506081110eusmtip15b4e6a476e2eada8a56f7f54296837f1~sdckpd6-70578205782eusmtip1b; Fri, 6 May 2022 08:11:10 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 04/11] nvmet: Allow ZNS target to support non-power_of_2 zone sizes Date: Fri, 6 May 2022 10:10:58 +0200 Message-Id: <20220506081105.29134-5-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SfUxTZxTGee+9vf2IhUsx8I6KbE38A9AqCyHv3MJcYrYbF3XZ5sY+xBW5 KwQorB8ONZlFEAU2Cjj5KCwwMq1QRylldYWiWGOBOQZrh2mZwxFoNqlUhmWTyGSUi5n//d5z nuc950kODxeZyFhejkLNKBWyPAkpIKzOpZ+2bfaoM3fYXCnI9IMTRyt2J4mMv+lIVDe/hKNa XQMXPRoZxVF/oImDxh4WY8g7YMOQva0WQ+3GGxiaMelx9PnAPIHaS6dwtDyVjKaCEwSqddwC yDeux1D/RBJyTV/kInv/MIHcvc0karng46LqskUceap9ANUMWjjowflSL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hsdnHJoh5h 7dYHL263X50gX3L35OwdMS6Cyfe+rkl3es9nxT01UfnC57jEt9zbeqQicg7bPU+w2b0oSoml OCPRUIu5qDgRABxkWpSzAwAA X-CMS-MailID: 20220506081110eucas1p1b6c624ddca1c41b9838bb5b85f8ca5ff X-Msg-Generator: CA X-RootMTR: 20220506081110eucas1p1b6c624ddca1c41b9838bb5b85f8ca5ff X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081110eucas1p1b6c624ddca1c41b9838bb5b85f8ca5ff References: <20220506081105.29134-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 Fri May 6 08:10:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12840709 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 641D9C433FE for ; Fri, 6 May 2022 08:11:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389828AbiEFIPJ (ORCPT ); Fri, 6 May 2022 04:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389857AbiEFIPH (ORCPT ); Fri, 6 May 2022 04:15:07 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCA5367D38 for ; Fri, 6 May 2022 01:11:18 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081113euoutp01f0be0c732a2bf1870b959c9fa4f1faef~sdcoBMvgT2557725577euoutp01E for ; Fri, 6 May 2022 08:11:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220506081113euoutp01f0be0c732a2bf1870b959c9fa4f1faef~sdcoBMvgT2557725577euoutp01E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824673; bh=U9RzqUijJL5PmqUeIybgHDju5FpS85GPewMJfUjtd+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qs9qCW4Y+Q4e1UAU6M5BIUHoXT8MIfMhJ2DBWVtW4vVEY2S8YQH+65jRanPBEphrv Na1AuMYhagAXS8p8wH9MRi1f1rwD92KL8F6JVj1hSDKfcw6B7UxVUWtBk/fM88hSZg 5yoPm0/N0KfIvoNeTWIdS2ZjHDo4d+2tzBbOOBOE= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220506081112eucas1p1ccb815812e215df7e24c0a5b2fcb0ef2~sdcmW62-Z2880428804eucas1p1w; Fri, 6 May 2022 08:11:12 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id D7.3C.10260.F18D4726; Fri, 6 May 2022 09:11:11 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220506081111eucas1p11e4dd5a89ce49939bbea57433cea046f~sdcl8BE8U1786517865eucas1p1-; Fri, 6 May 2022 08:11:11 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220506081111eusmtrp23682ed30504d4143db35d09c66da86b3~sdcl60V3e2793127931eusmtrp2I; Fri, 6 May 2022 08:11:11 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-dd-6274d81f318e Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id A4.F2.09522.F18D4726; Fri, 6 May 2022 09:11:11 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220506081111eusmtip1db96962bcd6db0befbdd9570f5dd4da6~sdcllH23g2776127761eusmtip1Q; Fri, 6 May 2022 08:11:11 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 05/11] btrfs: zoned: Cache superblock location in btrfs_zoned_device_info Date: Fri, 6 May 2022 10:10:59 +0200 Message-Id: <20220506081105.29134-6-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SbUxTZxTH99x7e1u6lV1aSZ+gjlgz3NikYy7xUZdlGD/cDLZgFj4MCK7A FdhKwZbOF5ZJoTrlnS4yKIjiUF5a6aQoFighdVAUGYQXV9kKEmhEDMVN2CywMsvFzG+/c57/ /5z/SR4eLmwmg3hpiixGqZDJJSSfuNHrGdwZ7MhKfO+Bdg8y3enF0VpnL4kMzhISlT/x4EhX UsFFKwODOLK6qzho6JkGQ/e7LRjqvKTDUKOhB0MzJj2OCrufEKhRO4Wj1alwNLU4TiCd7R5A rjE9hqzj76Dh6QYu6rTeJtBIezWJLlxxcVHp6SUcOUpdAJXZzRz09LKWi5ofLxCob3zzx1vp kdFI2ttnJOmyPDeXHpy4RtAjA2q6peksSdfmnMNpc91JuuN+DkkX5blJ2nJqkkMvdI2RdHFr E6BNrWMEbe7PpkvN1zjRwlj+h8mMPO0bRin96Et+6rOJQSKzW3zM5M4nc8BPonzgx4PUB9B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Msg-Generator: CA X-RootMTR: 20220506081111eucas1p11e4dd5a89ce49939bbea57433cea046f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081111eucas1p11e4dd5a89ce49939bbea57433cea046f References: <20220506081105.29134-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Instead of calculating the superblock location every time, cache the superblock zone location in btrfs_zoned_device_info struct and use it to locate the zone index. The functions such as btrfs_sb_log_location_bdev() and btrfs_reset_sb_log_zones() which work directly on block_device shall continue to use the sb_zone_number because btrfs_zoned_device_info struct might not have been initialized at that point. This patch will enable non power-of-2 zoned devices to not perform division to lookup superblock and its mirror location. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 13 +++++++++---- fs/btrfs/zoned.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 06f22c021..e8c7cebb2 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -511,6 +511,11 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) max_active_zones - nactive); } + /* Cache the sb zone number */ + for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; ++i) { + zone_info->sb_zone_location[i] = + sb_zone_number(zone_info->zone_size_shift, i); + } /* Validate superblock log */ nr_zones = BTRFS_NR_SB_LOG_ZONES; for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { @@ -518,7 +523,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) u64 sb_wp; int sb_pos = BTRFS_NR_SB_LOG_ZONES * i; - sb_zone = sb_zone_number(zone_info->zone_size_shift, i); + sb_zone = zone_info->sb_zone_location[i]; if (sb_zone + 1 >= zone_info->nr_zones) continue; @@ -866,7 +871,7 @@ int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw, return 0; } - zone_num = sb_zone_number(zinfo->zone_size_shift, mirror); + zone_num = zinfo->sb_zone_location[mirror]; if (zone_num + 1 >= zinfo->nr_zones) return -ENOENT; @@ -883,7 +888,7 @@ static inline bool is_sb_log_zone(struct btrfs_zoned_device_info *zinfo, if (!zinfo) return false; - zone_num = sb_zone_number(zinfo->zone_size_shift, mirror); + zone_num = zinfo->sb_zone_location[mirror]; if (zone_num + 1 >= zinfo->nr_zones) return false; @@ -1011,7 +1016,7 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, u32 sb_zone; u64 sb_pos; - sb_zone = sb_zone_number(shift, i); + sb_zone = zinfo->sb_zone_location[i]; if (!(end <= sb_zone || sb_zone + BTRFS_NR_SB_LOG_ZONES <= begin)) { have_sb = true; diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 10f31d1c8..694ab6d1e 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -27,6 +27,7 @@ struct btrfs_zoned_device_info { unsigned long *active_zones; struct blk_zone *zone_cache; struct blk_zone sb_zones[2 * BTRFS_SUPER_MIRROR_MAX]; + u32 sb_zone_location[BTRFS_SUPER_MIRROR_MAX]; }; #ifdef CONFIG_BLK_DEV_ZONED From patchwork Fri May 6 08:11:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12840712 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 33C4FC4332F for ; Fri, 6 May 2022 08:11:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389858AbiEFIPS (ORCPT ); Fri, 6 May 2022 04:15:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389848AbiEFIPA (ORCPT ); Fri, 6 May 2022 04:15:00 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEB2467D24 for ; Fri, 6 May 2022 01:11:17 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081115euoutp02ac6e04461aef7f252a16bdcedef7ea1e~sdcpLbQIm2384423844euoutp02s for ; Fri, 6 May 2022 08:11:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220506081115euoutp02ac6e04461aef7f252a16bdcedef7ea1e~sdcpLbQIm2384423844euoutp02s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824675; bh=LMzILViEYGl7DXa37dpeTA+tqVrqwK5EcVpc6Ix2yY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=obP4nF7chR4bizNpPP4tT3YwhWmITRtJcuxwOUr1oUk/UX96RZoauA4G8l4G0zeIg mC049hre2KQPq/WQ4sKYBy3KQLdG6UMHBMbsAvfwBFJfyfAozDaHXrKVPhFp/nnKGK mtmkm7jfAOQY1orlMwE7h4KflOFV9GruFyN1sjTs= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220506081113eucas1p2f26a6d8f18f7cbb7ff59652198904281~sdcneF8rQ1186311863eucas1p2N; Fri, 6 May 2022 08:11:13 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id C3.17.10009.128D4726; Fri, 6 May 2022 09:11:13 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220506081112eucas1p2f6116cb713749c259a6da533df9c2505~sdcm-zlTq0616806168eucas1p2r; Fri, 6 May 2022 08:11:12 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220506081112eusmtrp1cb2b5b25d973a47abc875150c38a6a35~sdcm_v8_A3089330893eusmtrp1R; Fri, 6 May 2022 08:11:12 +0000 (GMT) X-AuditID: cbfec7f2-e7fff70000002719-96-6274d8216386 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id F4.F9.09404.028D4726; Fri, 6 May 2022 09:11:12 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220506081112eusmtip29939a1aabce6a042ae1abb239d666502~sdcmlVHIw2136621366eusmtip2V; Fri, 6 May 2022 08:11:12 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 06/11] btrfs: zoned: Make sb_zone_number function non power of 2 compatible Date: Fri, 6 May 2022 10:11:00 +0200 Message-Id: <20220506081105.29134-7-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0xTZxjG9/Wcnh6aQQ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wenVAPTaru7 fqkiB7Z/3z5HteR47P51U/ZdY+n3yMv8+8JY4PdZ72Ml8am+T+b/nthqoLU87bHUqT1OtSxc wufWGRsUy33KY4g/UZZeqNU1wS7I0rx99mHnz9KyF1r2VG/o+uJ/JNvn1rkyj+TEQ3uYns7O e3TwjEJKdsVMz9RnIZOt5vWWBzVfWi50Sq0mOvRtndrlmTziddzvw31l/n4LuVMR/PvaLfFr AV0vnB9NK2Oa6r908aLU8/H7Eq8meIuwXbt+s8nG7GrTm5LrPAH3f3WXHGZWm5XZdmrKhOlF k5aa5O+YFCNZIPzSYrsUw+ovj9y5HXRWuZ7j3X1la5bOjbf3fjfG9Sf67unRFTx9obReiaU4 I9FQi7moOBEAETYNDLMDAAA= X-CMS-MailID: 20220506081112eucas1p2f6116cb713749c259a6da533df9c2505 X-Msg-Generator: CA X-RootMTR: 20220506081112eucas1p2f6116cb713749c259a6da533df9c2505 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081112eucas1p2f6116cb713749c259a6da533df9c2505 References: <20220506081105.29134-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Make the calculation in sb_zone_number function to be generic and work for both power-of-2 and non power-of-2 zone sizes. The function signature has been modified to take block device and mirror as input as this function is only invoked from callers that have access to the block device. This enables to use the generic bdev_zone_no function provided by the block layer to calculate the zone number. Even though division is used to calculate the zone index for non power-of-2 zone sizes, this function will not be used in the fast path as the sb_zone_location cache is used for the superblock zone location. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index e8c7cebb2..5be2ef7bb 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -34,9 +34,6 @@ #define BTRFS_SB_LOG_FIRST_OFFSET (512ULL * SZ_1G) #define BTRFS_SB_LOG_SECOND_OFFSET (4096ULL * SZ_1G) -#define BTRFS_SB_LOG_FIRST_SHIFT const_ilog2(BTRFS_SB_LOG_FIRST_OFFSET) -#define BTRFS_SB_LOG_SECOND_SHIFT const_ilog2(BTRFS_SB_LOG_SECOND_OFFSET) - /* Number of superblock log zones */ #define BTRFS_NR_SB_LOG_ZONES 2 @@ -153,15 +150,23 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones, /* * Get the first zone number of the superblock mirror */ -static inline u32 sb_zone_number(int shift, int mirror) +static inline u32 sb_zone_number(struct block_device *bdev, int mirror) { u64 zone; ASSERT(mirror < BTRFS_SUPER_MIRROR_MAX); switch (mirror) { - case 0: zone = 0; break; - case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break; - case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break; + case 0: + zone = 0; + break; + case 1: + zone = bdev_zone_no(bdev, + BTRFS_SB_LOG_FIRST_OFFSET >> SECTOR_SHIFT); + break; + case 2: + zone = bdev_zone_no(bdev, + BTRFS_SB_LOG_SECOND_OFFSET >> SECTOR_SHIFT); + break; } ASSERT(zone <= U32_MAX); @@ -514,7 +519,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) /* Cache the sb zone number */ for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; ++i) { zone_info->sb_zone_location[i] = - sb_zone_number(zone_info->zone_size_shift, i); + sb_zone_number(bdev, i); } /* Validate superblock log */ nr_zones = BTRFS_NR_SB_LOG_ZONES; @@ -839,7 +844,7 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, nr_sectors = bdev_nr_sectors(bdev); nr_zones = nr_sectors >> zone_sectors_shift; - sb_zone = sb_zone_number(zone_sectors_shift + SECTOR_SHIFT, mirror); + sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) return -ENOENT; @@ -963,7 +968,7 @@ int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) nr_sectors = bdev_nr_sectors(bdev); nr_zones = nr_sectors >> zone_sectors_shift; - sb_zone = sb_zone_number(zone_sectors_shift + SECTOR_SHIFT, mirror); + sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) return -ENOENT; From patchwork Fri May 6 08:11: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: 12840715 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 E4054C433FE for ; Fri, 6 May 2022 08:11:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389925AbiEFIPg (ORCPT ); Fri, 6 May 2022 04:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389875AbiEFIPH (ORCPT ); Fri, 6 May 2022 04:15:07 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E43668308 for ; Fri, 6 May 2022 01:11:20 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081116euoutp0123be093df664f9fc023301d5e5bcd34c~sdcqpeRSs2306323063euoutp01M for ; Fri, 6 May 2022 08:11:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220506081116euoutp0123be093df664f9fc023301d5e5bcd34c~sdcqpeRSs2306323063euoutp01M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824676; bh=v9pKtSXVKfv3MO12A+XlAy96VR3If9OGCSyPe0WYtqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZZpQdu7I5Dj+Gvu7ipz7mird5XArKeGlLyUJ0b4gDJuDWCwrVSjlsyF3IAfo4U6ET LC7Be09UcZO2AG1PhYh8GQvGY5jhWPoBP0F7iXJAJ1zebrsJl6VyBAtjpVqMGoFdfI /R57hcOpJ+cydSVC7jUC2z0k52tz3M5o98PcoYhE= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220506081114eucas1p2fae0d6fb327ff4fe7df4a6414ca0e9bd~sdcpBaB1r3246832468eucas1p23; Fri, 6 May 2022 08:11:14 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 77.17.10009.228D4726; Fri, 6 May 2022 09:11:14 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220506081113eucas1p25deb73a4b7898476d2e8e3d35b16f879~sdcn8-y9B0618006180eucas1p2s; Fri, 6 May 2022 08:11:13 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220506081113eusmtrp1b5db27a25fcac68d11b1f47ce6818390~sdcn7hajT3086630866eusmtrp1i; Fri, 6 May 2022 08:11:13 +0000 (GMT) X-AuditID: cbfec7f2-e95ff70000002719-9c-6274d822f266 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 27.F9.09404.128D4726; Fri, 6 May 2022 09:11:13 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220506081113eusmtip2682f5d9b44087e088f8fb8f24972b738~sdcnlsbKK2098320983eusmtip2A; Fri, 6 May 2022 08:11:13 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 07/11] btrfs: zoned: use generic btrfs zone helpers to support npo2 zoned devices Date: Fri, 6 May 2022 10:11:01 +0200 Message-Id: <20220506081105.29134-8-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Se0xTVxz29N7ee1tXcylsHBEkdo4I23johkcxjk3D7jRbWJYt0cRHxSsw SjUtMBhZqIC8FGhBBEqnYzJGK1h5iILgsBkvOwexYyIDHY4GwVhkUBCqbJbbZf73/c7ve/y+ 5FCYuI7womLlCaxCLpVJCCHe3LXw69uSwYRDwYv1wch4swtD/7R1EejCSCGBzjxZwFBRYRmJ HLf6MNRuq+Cj/qfHeehuRwsPtX1fxEP6C508NGbUYuhUxxMc6TNHMfRsNASNzg7hqMj0O0DW AS0PtQ+9iW7/VUOitvZeHFladQQ6V20lkTrLjqFBtRUgTXcjH838kEmii4+mcNQztCbch7H8 tptZ6qklGE2GjWT67tXjjOVWItNgyCWYSlUJxjRWpTHX7qoIJj/DRjAtJ+7zmanrAwRT0GQA jLFpAGcazamMurGeHyneK9x2mJXFJrGKoO0HhTGlVbnYsc7k5JmJOVIFBqLyAEVB+h04UCDL A0JKTNcAqM6cJ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CA X-RootMTR: 20220506081113eucas1p25deb73a4b7898476d2e8e3d35b16f879 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081113eucas1p25deb73a4b7898476d2e8e3d35b16f879 References: <20220506081105.29134-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add helpers to calculate alignment, round up and round down for zoned devices. These helpers encapsulates the necessary handling for power_of_2 and non-power_of_2 zone sizes. Optimized calculations are performed for zone sizes that are power_of_2 with log and shifts. btrfs_zoned_is_aligned() is added instead of reusing bdev_zone_aligned() helper due to some use cases in btrfs where zone alignment is checked before having access to the underlying block device such as in this function: btrfs_load_block_group_zone_info(). Use the generic btrfs zone helpers to calculate zone index, check zone alignment, round up and round down operations. The zone_size_shift field is not needed anymore as generic helpers are used for calculation. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/volumes.c | 24 +++++++++------- fs/btrfs/zoned.c | 72 ++++++++++++++++++++++------------------------ fs/btrfs/zoned.h | 43 +++++++++++++++++++++++---- 3 files changed, 85 insertions(+), 54 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 94f851592..3d6b9a25a 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1408,7 +1408,7 @@ static u64 dev_extent_search_start(struct btrfs_device *device, u64 start) * allocator, because we anyway use/reserve the first two zones * for superblock logging. */ - return ALIGN(start, device->zone_info->zone_size); + return btrfs_zoned_roundup(start, device->zone_info->zone_size); default: BUG(); } @@ -1423,7 +1423,7 @@ static bool dev_extent_hole_check_zoned(struct btrfs_device *device, int ret; bool changed = false; - ASSERT(IS_ALIGNED(*hole_start, zone_size)); + ASSERT(btrfs_zoned_is_aligned(*hole_start, zone_size)); while (*hole_size > 0) { pos = btrfs_find_allocatable_zones(device, *hole_start, @@ -1560,7 +1560,7 @@ static int find_free_dev_extent_start(struct btrfs_device *device, search_start = dev_extent_search_start(device, search_start); WARN_ON(device->zone_info && - !IS_ALIGNED(num_bytes, device->zone_info->zone_size)); + !btrfs_zoned_is_aligned(num_bytes, device->zone_info->zone_size)); path = btrfs_alloc_path(); if (!path) @@ -5111,8 +5111,8 @@ static void init_alloc_chunk_ctl_policy_zoned( ctl->max_stripe_size = zone_size; if (type & BTRFS_BLOCK_GROUP_DATA) { - ctl->max_chunk_size = round_down(BTRFS_MAX_DATA_CHUNK_SIZE, - zone_size); + ctl->max_chunk_size = btrfs_zoned_rounddown( + BTRFS_MAX_DATA_CHUNK_SIZE, zone_size); } else if (type & BTRFS_BLOCK_GROUP_METADATA) { ctl->max_chunk_size = ctl->max_stripe_size; } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) { @@ -5124,9 +5124,10 @@ static void init_alloc_chunk_ctl_policy_zoned( } /* We don't want a chunk larger than 10% of writable space */ - limit = max(round_down(div_factor(fs_devices->total_rw_bytes, 1), - zone_size), - min_chunk_size); + limit = max( + btrfs_zoned_rounddown(div_factor(fs_devices->total_rw_bytes, 1), + zone_size), + min_chunk_size); ctl->max_chunk_size = min(limit, ctl->max_chunk_size); ctl->dev_extent_min = zone_size * ctl->dev_stripes; } @@ -6729,7 +6730,8 @@ static void submit_stripe_bio(struct btrfs_io_context *bioc, */ if (bio_op(bio) == REQ_OP_ZONE_APPEND) { if (btrfs_dev_is_sequential(dev, physical)) { - u64 zone_start = round_down(physical, fs_info->zone_size); + u64 zone_start = btrfs_zoned_rounddown(physical, + fs_info->zone_size); bio->bi_iter.bi_sector = zone_start >> SECTOR_SHIFT; } else { @@ -8051,8 +8053,8 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info, if (dev->zone_info) { u64 zone_size = dev->zone_info->zone_size; - if (!IS_ALIGNED(physical_offset, zone_size) || - !IS_ALIGNED(physical_len, zone_size)) { + if (!btrfs_zoned_is_aligned(physical_offset, zone_size) || + !btrfs_zoned_is_aligned(physical_len, zone_size)) { btrfs_err(fs_info, "zoned: dev extent devid %llu physical offset %llu len %llu is not aligned to device zone", devid, physical_offset, physical_len); diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 5be2ef7bb..3023c871e 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -177,13 +177,13 @@ static inline u32 sb_zone_number(struct block_device *bdev, int mirror) static inline sector_t zone_start_sector(u32 zone_number, struct block_device *bdev) { - return (sector_t)zone_number << ilog2(bdev_zone_sectors(bdev)); + return zone_number * bdev_zone_sectors(bdev); } static inline u64 zone_start_physical(u32 zone_number, struct btrfs_zoned_device_info *zone_info) { - return (u64)zone_number << zone_info->zone_size_shift; + return zone_number * zone_info->zone_size; } /* @@ -236,8 +236,8 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos, if (zinfo->zone_cache) { unsigned int i; - ASSERT(IS_ALIGNED(pos, zinfo->zone_size)); - zno = pos >> zinfo->zone_size_shift; + ASSERT(btrfs_zoned_is_aligned(pos, zinfo->zone_size)); + zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); /* * We cannot report zones beyond the zone end. So, it is OK to * cap *nr_zones to at the end. @@ -409,9 +409,8 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) } nr_sectors = bdev_nr_sectors(bdev); - zone_info->zone_size_shift = ilog2(zone_info->zone_size); - zone_info->nr_zones = nr_sectors >> ilog2(zone_sectors); - if (!IS_ALIGNED(nr_sectors, zone_sectors)) + zone_info->nr_zones = bdev_zone_no(bdev, nr_sectors); + if (!btrfs_zoned_is_aligned(nr_sectors, zone_sectors)) zone_info->nr_zones++; max_active_zones = bdev_max_active_zones(bdev); @@ -823,10 +822,8 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, u64 *bytenr_ret) { struct blk_zone zones[BTRFS_NR_SB_LOG_ZONES]; - sector_t zone_sectors; u32 sb_zone; int ret; - u8 zone_sectors_shift; sector_t nr_sectors; u32 nr_zones; @@ -837,12 +834,10 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, ASSERT(rw == READ || rw == WRITE); - zone_sectors = bdev_zone_sectors(bdev); - if (!is_power_of_2(zone_sectors)) + if (!is_power_of_2(bdev_zone_sectors(bdev))) return -EINVAL; - zone_sectors_shift = ilog2(zone_sectors); nr_sectors = bdev_nr_sectors(bdev); - nr_zones = nr_sectors >> zone_sectors_shift; + nr_zones = bdev_zone_no(bdev, nr_sectors); sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) @@ -959,14 +954,12 @@ int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) { sector_t zone_sectors; sector_t nr_sectors; - u8 zone_sectors_shift; u32 sb_zone; u32 nr_zones; zone_sectors = bdev_zone_sectors(bdev); - zone_sectors_shift = ilog2(zone_sectors); nr_sectors = bdev_nr_sectors(bdev); - nr_zones = nr_sectors >> zone_sectors_shift; + nr_zones = bdev_zone_no(bdev, nr_sectors); sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) @@ -992,18 +985,17 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, u64 hole_end, u64 num_bytes) { struct btrfs_zoned_device_info *zinfo = device->zone_info; - const u8 shift = zinfo->zone_size_shift; - u64 nzones = num_bytes >> shift; + u64 nzones = bdev_zone_no(device->bdev, num_bytes >> SECTOR_SHIFT); u64 pos = hole_start; u64 begin, end; bool have_sb; int i; - ASSERT(IS_ALIGNED(hole_start, zinfo->zone_size)); - ASSERT(IS_ALIGNED(num_bytes, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(hole_start, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(num_bytes, zinfo->zone_size)); while (pos < hole_end) { - begin = pos >> shift; + begin = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); end = begin + nzones; if (end > zinfo->nr_zones) @@ -1035,8 +1027,9 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, if (!(pos + num_bytes <= sb_pos || sb_pos + BTRFS_SUPER_INFO_SIZE <= pos)) { have_sb = true; - pos = ALIGN(sb_pos + BTRFS_SUPER_INFO_SIZE, - zinfo->zone_size); + pos = btrfs_zoned_roundup( + sb_pos + BTRFS_SUPER_INFO_SIZE, + zinfo->zone_size); break; } } @@ -1050,7 +1043,7 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos) { struct btrfs_zoned_device_info *zone_info = device->zone_info; - unsigned int zno = (pos >> zone_info->zone_size_shift); + unsigned int zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); /* We can use any number of zones */ if (zone_info->max_active_zones == 0) @@ -1072,7 +1065,7 @@ static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos) static void btrfs_dev_clear_active_zone(struct btrfs_device *device, u64 pos) { struct btrfs_zoned_device_info *zone_info = device->zone_info; - unsigned int zno = (pos >> zone_info->zone_size_shift); + unsigned int zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); /* We can use any number of zones */ if (zone_info->max_active_zones == 0) @@ -1108,14 +1101,14 @@ int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size) { struct btrfs_zoned_device_info *zinfo = device->zone_info; - const u8 shift = zinfo->zone_size_shift; - unsigned long begin = start >> shift; - unsigned long end = (start + size) >> shift; + unsigned long begin = bdev_zone_no(device->bdev, start >> SECTOR_SHIFT); + unsigned long end = + bdev_zone_no(device->bdev, (start + size) >> SECTOR_SHIFT); u64 pos; int ret; - ASSERT(IS_ALIGNED(start, zinfo->zone_size)); - ASSERT(IS_ALIGNED(size, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(start, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(size, zinfo->zone_size)); if (end > zinfo->nr_zones) return -ERANGE; @@ -1139,8 +1132,9 @@ int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size) /* Free regions should be empty */ btrfs_warn_in_rcu( device->fs_info, - "zoned: resetting device %s (devid %llu) zone %llu for allocation", - rcu_str_deref(device->name), device->devid, pos >> shift); + "zoned: resetting device %s (devid %llu) zone %u for allocation", + rcu_str_deref(device->name), device->devid, + bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT)); WARN_ON_ONCE(1); ret = btrfs_reset_device_zone(device, pos, zinfo->zone_size, @@ -1237,7 +1231,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) return 0; /* Sanity check */ - if (!IS_ALIGNED(length, fs_info->zone_size)) { + if (!btrfs_zoned_is_aligned(length, fs_info->zone_size)) { btrfs_err(fs_info, "zoned: block group %llu len %llu unaligned to zone size %llu", logical, length, fs_info->zone_size); @@ -1325,7 +1319,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) * The group is mapped to a sequential zone. Get the zone write * pointer to determine the allocation offset within the zone. */ - WARN_ON(!IS_ALIGNED(physical[i], fs_info->zone_size)); + WARN_ON(!btrfs_zoned_is_aligned(physical[i], fs_info->zone_size)); nofs_flag = memalloc_nofs_save(); ret = btrfs_get_dev_zone(device, physical[i], &zone); memalloc_nofs_restore(nofs_flag); @@ -1351,10 +1345,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) switch (zone.cond) { case BLK_ZONE_COND_OFFLINE: case BLK_ZONE_COND_READONLY: - btrfs_err(fs_info, - "zoned: offline/readonly zone %llu on device %s (devid %llu)", - physical[i] >> device->zone_info->zone_size_shift, - rcu_str_deref(device->name), device->devid); + btrfs_err( + fs_info, + "zoned: offline/readonly zone %u on device %s (devid %llu)", + bdev_zone_no(device->bdev, + physical[i] >> SECTOR_SHIFT), + rcu_str_deref(device->name), device->devid); alloc_offsets[i] = WP_MISSING_DEV; break; case BLK_ZONE_COND_EMPTY: diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 694ab6d1e..b94ce4d1f 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -9,6 +9,7 @@ #include "disk-io.h" #include "block-group.h" #include "btrfs_inode.h" +#include "misc.h" #define BTRFS_DEFAULT_RECLAIM_THRESH (75) @@ -18,7 +19,6 @@ struct btrfs_zoned_device_info { * zoned block device. */ u64 zone_size; - u8 zone_size_shift; u32 nr_zones; unsigned int max_active_zones; atomic_t active_zones_left; @@ -30,6 +30,36 @@ struct btrfs_zoned_device_info { u32 sb_zone_location[BTRFS_SUPER_MIRROR_MAX]; }; +static inline bool btrfs_zoned_is_aligned(u64 pos, u64 zone_size) +{ + u64 remainder = 0; + + if (is_power_of_two_u64(zone_size)) + return IS_ALIGNED(pos, zone_size); + + div64_u64_rem(pos, zone_size, &remainder); + return remainder == 0; +} + +static inline u64 btrfs_zoned_roundup(u64 pos, u64 zone_size) +{ + if (is_power_of_two_u64(zone_size)) + return ALIGN(pos, zone_size); + + return div64_u64(pos + zone_size - 1, zone_size) * zone_size; +} + +static inline u64 btrfs_zoned_rounddown(u64 pos, u64 zone_size) +{ + u64 remainder = 0; + if (is_power_of_two_u64(zone_size)) + return round_down(pos, zone_size); + + div64_u64_rem(pos, zone_size, &remainder); + pos -= remainder; + return pos; +} + #ifdef CONFIG_BLK_DEV_ZONED int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone); @@ -253,7 +283,8 @@ static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) if (!zone_info) return false; - return test_bit(pos >> zone_info->zone_size_shift, zone_info->seq_zones); + return test_bit(bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT), + zone_info->seq_zones); } static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos) @@ -263,7 +294,8 @@ static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos) if (!zone_info) return true; - return test_bit(pos >> zone_info->zone_size_shift, zone_info->empty_zones); + return test_bit(bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT), + zone_info->empty_zones); } static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device, @@ -275,7 +307,7 @@ static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device, if (!zone_info) return; - zno = pos >> zone_info->zone_size_shift; + zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); if (set) set_bit(zno, zone_info->empty_zones); else @@ -329,7 +361,8 @@ static inline bool btrfs_can_zone_reset(struct btrfs_device *device, return false; zone_size = device->zone_info->zone_size; - if (!IS_ALIGNED(physical, zone_size) || !IS_ALIGNED(length, zone_size)) + if (!btrfs_zoned_is_aligned(physical, zone_size) || + !btrfs_zoned_is_aligned(length, zone_size)) return false; return true; From patchwork Fri May 6 08:11: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: 12840714 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 F32BCC433F5 for ; Fri, 6 May 2022 08:11:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389914AbiEFIPX (ORCPT ); Fri, 6 May 2022 04:15:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389866AbiEFIPH (ORCPT ); Fri, 6 May 2022 04:15:07 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89C9C67D3D for ; Fri, 6 May 2022 01:11:19 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081117euoutp0278501d01e3655ca3ecb88bf96491e7d7~sdcrIoMNJ2349023490euoutp022 for ; Fri, 6 May 2022 08:11:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220506081117euoutp0278501d01e3655ca3ecb88bf96491e7d7~sdcrIoMNJ2349023490euoutp022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824677; bh=OUOs5yoREFPm133MftqN/52v0OJCiB1b6vGYcsnZpfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ox2fxTOQi0JUjHEBmT3xShiTOMD2IrUcliRLqN4hpmQe0qP3cZT9cVMr7twwEwBhf X4VCDMst7t0sqEpLYa+bvvpY21brNNwnyAHEl+YeXso/Sll5qFA2GXWLRCQOqMfvOx qkZZpBomnfOtaPPgbSilhvbUDKYghi7x2wUNTaoA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220506081115eucas1p149ff9d68b993fc4a5063dd222afc58ef~sdcpXq2fr1708917089eucas1p1E; Fri, 6 May 2022 08:11:15 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 3C.3C.10260.328D4726; Fri, 6 May 2022 09:11:15 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220506081114eucas1p1a9d86eb429a6f68c29d1980891f49786~sdco8BQZr1692416924eucas1p1y; Fri, 6 May 2022 08:11:14 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220506081114eusmtrp1042f84b3b164a08add28bf24c817eece~sdco6cXhB3089330893eusmtrp1U; Fri, 6 May 2022 08:11:14 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-eb-6274d823e841 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 69.F2.09522.228D4726; Fri, 6 May 2022 09:11:14 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220506081114eusmtip2ca889afa28846abc5660f97364a054cd~sdcolMwDn2098320983eusmtip2B; Fri, 6 May 2022 08:11:14 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 08/11] btrfs: zoned: relax the alignment constraint for zoned devices Date: Fri, 6 May 2022 10:11:02 +0200 Message-Id: <20220506081105.29134-9-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SfUxTVxjGd3pvby/direF4Qk4dXWE4DIciOZsyGYXEq/ZZiRmGXOTWfAK ZKW6ls4PllgpdIUxWiCCFhKHVFY+uoKtzAp0pmZ8DFiBggE6JYSyhQ+RAc4xJhv1YuZ/z3nP 7znP8yaHxEQWIpTMkGcxCrlUJib4eHP7svu1bcNZKa8PGfjI+nM7hv5tbSdQ/V09gcrmlzFU or/IQyu9bgy1zVVwUd9f5zlo5JaDg1qvlHBQbf1PHOSzGjFUeGseR7W54xj6ZzwajS+N4qjE dQegySEjB7WNvooGJsw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//cvHD26JZ7ludgmPMPrx5+sPEXEf/ktz3Q5ODJ/+5tTm/0yrw7vZUTakkZuW1Ua/OPxG9 LdtbdljKd9Ka1w49/fOOafMWrCzs/G8bUa2TpfUxbG/HHuULB+aeW71LqXv+oYdxQS4dmzcq sRRnJBpqMRcVJwIAVe6YGbIDAAA= X-CMS-MailID: 20220506081114eucas1p1a9d86eb429a6f68c29d1980891f49786 X-Msg-Generator: CA X-RootMTR: 20220506081114eucas1p1a9d86eb429a6f68c29d1980891f49786 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081114eucas1p1a9d86eb429a6f68c29d1980891f49786 References: <20220506081105.29134-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Checks were in place to return error when a non power-of-2 zoned devices is detected. Remove those checks as non power-of-2 zoned devices are now supported. Relax the zone size constraint to align with a sane default of 1MB. This 1M default has been chosen as the minimum alignment requirement for zone sizes to make sure zones align with sectorsize in different architectures. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 3023c871e..a6b15fbe1 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -54,6 +54,13 @@ */ #define BTRFS_MAX_ZONE_SIZE SZ_8G +/* + * A minimum alignment of 1MB is chosen for zoned devices as their zone sizes + * can be non power of 2. This is to make sure the zones correctly align to the + * sectorsize. + */ +#define BTRFS_ZONED_MIN_ALIGN_SECTORS ((u64)SZ_1M >> SECTOR_SHIFT) + #define SUPER_INFO_SECTORS ((u64)BTRFS_SUPER_INFO_SIZE >> SECTOR_SHIFT) static inline bool sb_zone_is_full(const struct blk_zone *zone) @@ -394,8 +401,8 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) zone_sectors = bdev_zone_sectors(bdev); } - /* Check if it's power of 2 (see is_power_of_2) */ - ASSERT(zone_sectors != 0 && (zone_sectors & (zone_sectors - 1)) == 0); + ASSERT(zone_sectors != 0 && + IS_ALIGNED(zone_sectors, BTRFS_ZONED_MIN_ALIGN_SECTORS)); zone_info->zone_size = zone_sectors << SECTOR_SHIFT; /* We reject devices with a zone size larger than 8GB */ @@ -834,9 +841,11 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, ASSERT(rw == READ || rw == WRITE); - if (!is_power_of_2(bdev_zone_sectors(bdev))) - return -EINVAL; nr_sectors = bdev_nr_sectors(bdev); + + if (!IS_ALIGNED(nr_sectors, BTRFS_ZONED_MIN_ALIGN_SECTORS)) + return -EINVAL; + nr_zones = bdev_zone_no(bdev, nr_sectors); sb_zone = sb_zone_number(bdev, mirror); From patchwork Fri May 6 08:11:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12840713 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 0A77AC433EF for ; Fri, 6 May 2022 08:11:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389911AbiEFIPW (ORCPT ); Fri, 6 May 2022 04:15:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389864AbiEFIPH (ORCPT ); Fri, 6 May 2022 04:15:07 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8C3868304 for ; Fri, 6 May 2022 01:11:19 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081118euoutp02d56c6f307de6cfe61ca448f2a6bcf9b3~sdcsECvr02333723337euoutp028 for ; Fri, 6 May 2022 08:11:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220506081118euoutp02d56c6f307de6cfe61ca448f2a6bcf9b3~sdcsECvr02333723337euoutp028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824678; bh=I6AyG+zKNeMaILZF7R/I3A5VoGI+O7z0EZ5WLMlZFWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sTTVlEidW0f3AlZRQvh1llqBy84jhU4rVKsIosds+oN2+s4YJS4eJmN9OFLCXRhy0 KR8J6IAMJ6y3bzwUi+Ujk8sxdGlcDKyznoSBpdAjZAkmMzm6To+enhf/iKIRcYCcpO 834ncQQFyJtakdpuJbSNdPHZzIj6Za3FmeXNjqgs= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220506081116eucas1p19eb3fac87a4cf0dada0eaf469eeb58b7~sdcqUrLha1756417564eucas1p19; Fri, 6 May 2022 08:11:16 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 24.4C.10260.428D4726; Fri, 6 May 2022 09:11:16 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220506081115eucas1p2e7bed137c74be42a702732027581330e~sdcp30_v_0618806188eucas1p2m; Fri, 6 May 2022 08:11:15 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220506081115eusmtrp2bc23f57f1bf98bef55c841a5817639d5~sdcp18RxM2593625936eusmtrp2f; Fri, 6 May 2022 08:11:15 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-ef-6274d82460ce Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 1D.F2.09522.328D4726; Fri, 6 May 2022 09:11:15 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220506081115eusmtip299ffc807d988a4202c28888f957b97ea~sdcpgytSF2136221362eusmtip2I; Fri, 6 May 2022 08:11:15 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 09/11] zonefs: allow non power of 2 zoned devices Date: Fri, 6 May 2022 10:11:03 +0200 Message-Id: <20220506081105.29134-10-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01SbUxTVxjO6b29/djqLqXSM9xi1ukyMFDJWHami5ubk5vMH4S4LWPLXAt3 QGjRtBQ/WGZLC4x2K4ggtrIh0xVaYBXKh1VqGK5AUQYRKojZlAmb4spHBBliYJRbM/897/M+ z3mf983hYkInEcnNyMqmVVkyhYTg461di7/FbBrJlm81TT2LnL1dGFpp7yJQ3e/FBDoxs4ih 0uKTHLTU148hz9QpNhr4V8dCNzrcLNT+YykL2eu8LD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LvcjDw5FvzA2ruFpPtL/jJO5qsvvYIfKSnaf s2yL1xzUXqcutNWhLuDwV/uJ0ixzhOeZf+pLEbjdMWv6C6MSs9e1Hf43Gx+vzeHddTLUfLv4 B7byOV8iNEUPJe3j2fQnw5I75NSjrUuMMmfyvg3/WH5nb6Rjb9r6/xOETRdssZAyePFS31OJ pTgj0VCLuag4EQBvUJ6csgMAAA== X-CMS-MailID: 20220506081115eucas1p2e7bed137c74be42a702732027581330e X-Msg-Generator: CA X-RootMTR: 20220506081115eucas1p2e7bed137c74be42a702732027581330e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081115eucas1p2e7bed137c74be42a702732027581330e References: <20220506081105.29134-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The zone size shift variable is useful only if the zone sizes are known to be power of 2. Remove that variable and use generic helpers from block layer to calculate zone index in zonefs. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/zonefs/super.c | 6 ++---- fs/zonefs/zonefs.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index 978a35c45..50a1e000c 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -451,10 +451,9 @@ static void __zonefs_io_error(struct inode *inode, bool write) { struct zonefs_inode_info *zi = ZONEFS_I(inode); struct super_block *sb = inode->i_sb; - struct zonefs_sb_info *sbi = ZONEFS_SB(sb); unsigned int noio_flag; unsigned int nr_zones = - zi->i_zone_size >> (sbi->s_zone_sectors_shift + SECTOR_SHIFT); + bdev_zone_no(sb->s_bdev, zi->i_zone_size >> SECTOR_SHIFT); struct zonefs_ioerr_data err = { .inode = inode, .write = write, @@ -1375,7 +1374,7 @@ static int zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone, struct zonefs_inode_info *zi = ZONEFS_I(inode); int ret; - inode->i_ino = zone->start >> sbi->s_zone_sectors_shift; + inode->i_ino = bdev_zone_no(sb->s_bdev, zone->start); inode->i_mode = S_IFREG | sbi->s_perm; zi->i_ztype = type; @@ -1752,7 +1751,6 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent) * interface constraints. */ sb_set_blocksize(sb, bdev_zone_write_granularity(sb->s_bdev)); - sbi->s_zone_sectors_shift = ilog2(bdev_zone_sectors(sb->s_bdev)); sbi->s_uid = GLOBAL_ROOT_UID; sbi->s_gid = GLOBAL_ROOT_GID; sbi->s_perm = 0640; diff --git a/fs/zonefs/zonefs.h b/fs/zonefs/zonefs.h index 4b3de66c3..39895195c 100644 --- a/fs/zonefs/zonefs.h +++ b/fs/zonefs/zonefs.h @@ -177,7 +177,6 @@ struct zonefs_sb_info { kgid_t s_gid; umode_t s_perm; uuid_t s_uuid; - unsigned int s_zone_sectors_shift; unsigned int s_nr_files[ZONEFS_ZTYPE_MAX]; From patchwork Fri May 6 08:11: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: 12840716 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 D349EC4332F for ; Fri, 6 May 2022 08:12:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389875AbiEFIPi (ORCPT ); Fri, 6 May 2022 04:15:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389879AbiEFIPH (ORCPT ); Fri, 6 May 2022 04:15:07 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38BA76830C for ; Fri, 6 May 2022 01:11:21 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081119euoutp01f74feed3bc78fdeeec0e490250f8f3cc~sdcta2JWN2375523755euoutp01u for ; Fri, 6 May 2022 08:11:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220506081119euoutp01f74feed3bc78fdeeec0e490250f8f3cc~sdcta2JWN2375523755euoutp01u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824679; bh=D05Y2RArrxR/ZcNMh/RJzrqiPuoU2BIWW0WuxZX2YSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VsAfUpBLmXf2/ajLCRPa76Vk/2BChVoQIYsSXcpJuSuPLyMUhp8hcWAW4jkkfKZbh vGjh0KiKcK3oLhnpxRRf/1ITtWIz+5/6LMNebgKQRGeza/3Ks/T+0FM5skdon58rcf SSIl0T9N0hXie/AAEoJ0JbKZ6RWe/b8VhQPPOQDs= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220506081117eucas1p18560a75e4c11c411a21dbd469ad119e1~sdcrdIYrQ1150211502eucas1p1S; Fri, 6 May 2022 08:11:17 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 7B.17.10009.528D4726; Fri, 6 May 2022 09:11:17 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220506081116eucas1p2cce67bbf30f4c9c4e6854965be41b098~sdcq5Y3zG1330813308eucas1p2T; Fri, 6 May 2022 08:11:16 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220506081116eusmtrp2b8dd7ad2a8ccfb56457e86d224868712~sdcq4cJxT2593625936eusmtrp2h; Fri, 6 May 2022 08:11:16 +0000 (GMT) X-AuditID: cbfec7f2-e95ff70000002719-a6-6274d825056e Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 42.03.09522.428D4726; Fri, 6 May 2022 09:11:16 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220506081116eusmtip2afe9c6ce26251602c1ec15efeec5e217~sdcqkJr1p2097920979eusmtip2b; Fri, 6 May 2022 08:11:16 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 10/11] null_blk: allow non power of 2 zoned devices Date: Fri, 6 May 2022 10:11:04 +0200 Message-Id: <20220506081105.29134-11-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0xTZxjG8/U7PT00KR4KCV8ARTqZDlcciRlfpuJ0GxwyXWYyNqJZpMrh ErmYFjYufwwBQcBJxSnSiiBhykWtUgTLpdEayn2aclmp2QhCycBC3QChMnGUg5n//d73e973 ed7ko6D4FulFxSelsPIkWYKEFBJNRsdvUn9zyrGPSqs8sabHCPGbNiOJ6/8oJvGl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9 f+/kTq6yiPrWI6e3fVw5LTP1zAXlUuZ2bb6Lp7WZdITeiR65zd2+4/mS4pfsu/buv/GQrXDP lHylFc6T+zdsT1vwXUOm3TQu58isGOWcZZ/OSGXqrL11OeKtkVoDj+x1Wal81Y5vJyW2zvCc tmrpe96rSXvarJID76mYPm5j336Iec8Wtb57uldu7t7ZapcsMlXg3RZWucUrD2vz/Ph8WIml OCPRUIu5qDgRAJTyJ6yzAwAA X-CMS-MailID: 20220506081116eucas1p2cce67bbf30f4c9c4e6854965be41b098 X-Msg-Generator: CA X-RootMTR: 20220506081116eucas1p2cce67bbf30f4c9c4e6854965be41b098 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081116eucas1p2cce67bbf30f4c9c4e6854965be41b098 References: <20220506081105.29134-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); From patchwork Fri May 6 08:11:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12840717 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 C9BA0C433FE for ; Fri, 6 May 2022 08:12:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389905AbiEFIPv (ORCPT ); Fri, 6 May 2022 04:15:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389883AbiEFIPI (ORCPT ); Fri, 6 May 2022 04:15:08 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 071386830D for ; Fri, 6 May 2022 01:11:21 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081120euoutp0255f6c244a13bbd826c273827973747a3~sdcubQzV92422724227euoutp02y for ; Fri, 6 May 2022 08:11:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220506081120euoutp0255f6c244a13bbd826c273827973747a3~sdcubQzV92422724227euoutp02y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824680; bh=2XMubIyolz4ZLTc9DAEWfdq40b874mLFKF8nTtEYP/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F1dSw+VtkcpEeMiIDVUwkpheUzxNb4HFT/dryBCGIPn4nyAb8PMRi9cDp+Y4Pppp8 2Wd/rOb9FGzGk5TtNBUvQUYffiKQUcITziO/EaTtnRTZxPnjsGuHDwhhZJEot1LQBg ccB6liw0P4iquWO9fecN7mwKfhn38/BylsM+dP6o= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220506081118eucas1p2cfcc398efecd5a38c185c6cd71cf243e~sdcslGTqR0618406184eucas1p2f; Fri, 6 May 2022 08:11:18 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 53.15.09887.628D4726; Fri, 6 May 2022 09:11:18 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220506081118eucas1p17f3c29cc36d748c3b5a3246f069f434a~sdcsEWQBd2880428804eucas1p12; Fri, 6 May 2022 08:11:18 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220506081118eusmtrp26f98e34ad16879dc8bda415db8d5ed37~sdcr-ioOA2593625936eusmtrp2k; Fri, 6 May 2022 08:11:18 +0000 (GMT) X-AuditID: cbfec7f4-471ff7000000269f-55-6274d826672c Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 05.03.09522.528D4726; Fri, 6 May 2022 09:11:17 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220506081117eusmtip1c4f0939db628ec5dc1a8f468ad7710a9~sdcrnO9IP2776127761eusmtip1U; Fri, 6 May 2022 08:11:17 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Luis Chamberlain , Pankaj Raghav Subject: [PATCH v3 11/11] dm-zoned: ensure only power of 2 zone sizes are allowed Date: Fri, 6 May 2022 10:11:05 +0200 Message-Id: <20220506081105.29134-12-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01SbUxTZxjde+/t7aWk5tpieKPOMRZUmIK4TV43wzQScxdCt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Z0JEoJJCeWJKanZpakFoE08fEwSnVwGS+ W+dpG8+s4r36PFsDNybJsRZ3K9n19DxeEsPCINj17Ymq+VfpT1cnXz6x49eN31brPs6U7p8i MaGvam1hmWhp8AvVgjnX+Bze/6611v8Y+FT97oWt1uZLt/cfWcPfrDu7p/XfbbXUw4ZCyTO2 qbm4BeiXtUfeEf+leNHy8hyNf0YnGkSu3FPZx+m8/E39jKZdXYoXxa4Hek8qPFm1zv7emZod c5ax/Wz4tXBLwuSkT0t/mnP3sfCXveQNZX8dvPrSM0P/OHW+A5J/suIdq7N3XOpYYm3We7m/ Q+GAnmiZjMA6q/UybSnfXX9Xz95c8Sv3h+AMc0dvg6zE9pcbLtVNFUx1sHwVHCdz4+k2ESWW 4oxEQy3mouJEAKGoBKayAwAA X-CMS-MailID: 20220506081118eucas1p17f3c29cc36d748c3b5a3246f069f434a X-Msg-Generator: CA X-RootMTR: 20220506081118eucas1p17f3c29cc36d748c3b5a3246f069f434a X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081118eucas1p17f3c29cc36d748c3b5a3246f069f434a References: <20220506081105.29134-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Luis Chamberlain Today dm-zoned relies on the assumption that you have a zone size with a power of 2. Even though the block layer today enforces this requirement, these devices do exist and so provide a stop-gap measure to ensure these devices cannot be used by mistake Reviewed-by: Hannes Reinecke Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- drivers/md/dm-zone.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c index 3e7b1fe15..27dc4ddf2 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -231,6 +231,18 @@ static int dm_revalidate_zones(struct mapped_device *md, struct dm_table *t) struct request_queue *q = md->queue; unsigned int noio_flag; int ret; + struct block_device *bdev = md->disk->part0; + sector_t zone_sectors; + char bname[BDEVNAME_SIZE]; + + zone_sectors = bdev_zone_sectors(bdev); + + if (!is_power_of_2(zone_sectors)) { + DMWARN("%s: %s only power of two zone size supported\n", + dm_device_name(md), + bdevname(bdev, bname)); + return 1; + } /* * Check if something changed. If yes, cleanup the current resources