From patchwork Wed May 25 15:49:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12861400 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 1BDD7C433EF for ; Wed, 25 May 2022 15:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245301AbiEYPu2 (ORCPT ); Wed, 25 May 2022 11:50:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245363AbiEYPuH (ORCPT ); Wed, 25 May 2022 11:50:07 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CE6FAF32C for ; Wed, 25 May 2022 08:50:05 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220525155002euoutp011b6998e6d46c4b4f13ac76475e859e53~yY9o5LleK0414604146euoutp01B for ; Wed, 25 May 2022 15:50:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220525155002euoutp011b6998e6d46c4b4f13ac76475e859e53~yY9o5LleK0414604146euoutp01B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653493802; bh=2eQZ6kViMFen5Vvv5WDxkU+VSeYRgwNz1guBAQ1Xbgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a4r22eAsBHe0iH2u5aBM3JQS6HB6jwgo0YmhQutxHjmR0UiiixutGSD3ld4doRe9R PhqWlf3u88fSy7EPZ9iDrGHa+lyQ6/wNv2nidmXvUB/rqbKJslfjzCsxyinTbObUbm YpzULJXwsfpNVjOI3Us03oUecMShlROSIAcH65es= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220525155000eucas1p216752d9914ca37a7d223bef39c8fb758~yY9nXTACK0700607006eucas1p2H; Wed, 25 May 2022 15:50:00 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id A9.FF.10260.8205E826; Wed, 25 May 2022 16:50:00 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220525155000eucas1p200ac7e1c844980e728c9e88f51c4590e~yY9m7pDL80700607006eucas1p2G; Wed, 25 May 2022 15:50:00 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220525154959eusmtrp232e421c63a06da32f789c1209bc5a763~yY9m62BF90177001770eusmtrp2W; Wed, 25 May 2022 15:49:59 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-d0-628e502837bc Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DC.8E.09404.7205E826; Wed, 25 May 2022 16:49:59 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220525154959eusmtip1b8cca573c1722645da3df92c140f2a0b~yY9mnZb3k1782817828eusmtip1W; Wed, 25 May 2022 15:49:59 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, snitzer@redhat.com, Johannes.Thumshirn@wdc.com, hch@lst.de, hare@suse.de Cc: dsterba@suse.com, dm-devel@redhat.com, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, jaegeuk@kernel.org, gost.dev@samsung.com, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v6 1/8] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Wed, 25 May 2022 17:49:50 +0200 Message-Id: <20220525154957.393656-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525154957.393656-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFKsWRmVeSWpSXmKPExsWy7djP87oaAX1JBhemSlisvtvPZvH77Hlm i73vZrNaXPjRyGRx88BOJos9iyYxWaxcfZTJ4sn6WcwWPQc+sFj87brHZLH3lrbF5V1z2Czm L3vKbnFjwlNGi89LW9gt2jZ+ZXQQ8Ph3Yg2bx+WzpR6bVnWyeWxeUu+x+2YDm8fO1vusHu/3 XWXz6NuyitFj/ZarLB6bT1d7fN4k59F+oJspgCeKyyYlNSezLLVI3y6BK2PaibnsBZNEKl5N 3sXYwPhQoIuRg0NCwETizJ6MLkYuDiGBFYwSi57sZuxi5ARyvjBK/G1ThUh8ZpRoeTWdFSQB 0jC59QkzRGI5o0TDil42COcFo0TX7AlMIGPZBLQkGjvZQeIiAo2MElNfnmAEcZgFZjNJzPs2 GWyHsECiRG/PHTYQm0VAVeLZm7usIM28AlYS+w5LQmyTl5h56Ts7iM0pYC0xf/9nZhCbV0BQ 4uTMJywgNjNQTfPW2WAXSQis55Q4er+DDaLZRWLpiddQtrDEq+Nb2CFsGYn/O+czQdjVEk9v /IZqbmGU6N+5ng0SMNYSfWdyQExmAU2J9bv0IcodJR4//soOUcEnceOtIMQJfBKTtk1nhgjz SnS0CUFUK0ns/PkEaqmExOWmOSwQJR4SW29bTGBUnIXkl1lIfpmFsHYBI/MqRvHU0uLc9NRi 47zUcr3ixNzi0rx0veT83E2MwOR3+t/xrzsYV7z6qHeIkYmD8RCjBAezkgjvhae9SUK8KYmV ValF+fFFpTmpxYcYpTlYlMR5kz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IQ b0piZVVqUX58UWlOavEhRlOgsycyS4km5wNTRV5JvKGZgamhiZmlgamlmbGSOK9nQUeikEB6 YklqdmpqQWoRTB8TB6dUA1PkhHXz4zKaVu72PXKjsvWD+uuOJKXKq0Z8VmEee9zfvpbiTdKT MpIqvyG85oSV4lW163f2z+ee4FHz7dRsnRbeG18DnZZJSm5R4mZ3K5acdUT7qvjyz+ZL4k5f Zf2qVMb24bXB7Yum2ryBzec3MD1Y2pN2s+8a44XVl0ymhfLqLJzmudjxdMo51szLq0/3t8xa YRTp/Nlgiv65ivc37x1wqZ0rxLyotTIlUDo1yC03XsNRUN9s0orMU3Lzfyq0tVX1r2thvLR6 WvnUR6XP7jd5fmZ9fWw+5x+b+GsebV8PvChsPrxJ/Xf8Jke76u93K+0/Z4c/n9kePvN/8Zc7 N/mzTN9EPQy69f/kx0cGYRuUWIozEg21mIuKEwGfZguQXQMAAA== X-CMS-MailID: 20220525155000eucas1p200ac7e1c844980e728c9e88f51c4590e X-Msg-Generator: CA X-RootMTR: 20220525155000eucas1p200ac7e1c844980e728c9e88f51c4590e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220525155000eucas1p200ac7e1c844980e728c9e88f51c4590e References: <20220525154957.393656-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 | 12 +++++++++--- include/linux/blkdev.h | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 38cd840d8838..8b0615287cd3 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -111,16 +111,22 @@ EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); * blkdev_nr_zones - Get number of zones * @disk: Target gendisk * - * Return the total number of zones of a zoned block device. For a block - * device without zone capabilities, the number of zones is always 0. + * Return the total number of zones of a zoned block device, including the + * eventual small last zone if present. For a block device without zone + * capabilities, the number of zones is always 0. */ unsigned int blkdev_nr_zones(struct gendisk *disk) { sector_t zone_sectors = blk_queue_zone_sectors(disk->queue); + sector_t capacity = get_capacity(disk); if (!blk_queue_is_zoned(disk->queue)) return 0; - return (get_capacity(disk) + zone_sectors - 1) >> ilog2(zone_sectors); + + if (is_power_of_2(zone_sectors)) + return (capacity + zone_sectors - 1) >> ilog2(zone_sectors); + + return DIV_ROUND_UP_SECTOR_T(capacity, zone_sectors); } EXPORT_SYMBOL_GPL(blkdev_nr_zones); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 60d016138997..c4e4c7071b7b 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -665,9 +665,15 @@ static inline unsigned int blk_queue_nr_zones(struct request_queue *q) static inline unsigned int blk_queue_zone_no(struct request_queue *q, sector_t sector) { + sector_t zone_sectors = blk_queue_zone_sectors(q); + if (!blk_queue_is_zoned(q)) return 0; - return sector >> ilog2(q->limits.chunk_sectors); + + if (is_power_of_2(zone_sectors)) + return sector >> ilog2(zone_sectors); + + return div64_u64(sector, zone_sectors); } static inline bool blk_queue_zone_is_seq(struct request_queue *q,