Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp500918imn; Wed, 27 Jul 2022 11:59:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vDxDnMCQcMIstc1iYE+bPAsNtHGyb56okgTW5V2DhDvalzH0+PZZe58LINnfjgtKbfwsPM X-Received: by 2002:a17:907:1608:b0:72e:e254:7baa with SMTP id hb8-20020a170907160800b0072ee2547baamr19375144ejc.672.1658948363215; Wed, 27 Jul 2022 11:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658948363; cv=none; d=google.com; s=arc-20160816; b=VQf8JFUwFViypsX8xN1n4rXvJmnIHJNNXWG3KexoZUx7fII34+JqGtCoFC/oVZv6Qr TXl8c3cfEnf6PeA+EcRmZ7upQkWva7v6HAv7rXSEEVWx8OOduTNQ4fvOcdO091yVazTn P3kvohaw4j2aB1iqPpz62GgLrqElmuCyPQ14lo7r21YWfgk0tJLTtWNoky+qTeK7bDzc D2yARuouUZ/JPhNF8W2cQ5ayuSo/5pIKDmmQP8+GgI4f6Nn7MFL0AQJWMX8sfwrLGc7Z QBl5HoTVuQwcOOsBK0Tfna+eeKj8yriyphdTXHdRyF5X5OfTyHMEr63depvKrsENiod2 GMtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :mime-version:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=9bdbdbUw6KTK2r5hitLcl/AEOPoWY1dExIREEyMjHGo=; b=g16w2o/H29AnP4AnMnomjkomINclhiVs5VMheyKGlk4W+TDhzaFGXPQwGagcabQ2l7 Z6Tv1QpF/zCUrkg2kuG/p3rAL+UCniwbhKRY8BDl0SVOWw04bVHCNxMX8D2QwJxZjlqx tokXIgn4BSCldpDO5H3pAZiA9Dc/llm4w10nfZLQsFuFNUFqfJCtaKB40x62W6/F0M5Q QzyeKFPq+xVLlkBfAImaNQLzVW3X1y8BnyVuc5vHPBkqfDMOxlTtwz3jlMSQiozZv9KT +t9Zy7cThnBqXIbV5bpO+AoQtCRBu1mYdIe7VwfhNX9TyQTnL8Mg+FYmcglHkJQp0gvR xlww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=pN1vw6nD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho38-20020a1709070ea600b0072b4a163f61si7260501ejc.596.2022.07.27.11.58.58; Wed, 27 Jul 2022 11:59:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=pN1vw6nD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236169AbiG0QYQ (ORCPT + 99 others); Wed, 27 Jul 2022 12:24:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235026AbiG0QXa (ORCPT ); Wed, 27 Jul 2022 12:23:30 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6F444D4F6 for ; Wed, 27 Jul 2022 09:22:53 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220727162250euoutp020afe69a1439bc809b7a0aa053c107a87~FvDQvyexF1245112451euoutp02c for ; Wed, 27 Jul 2022 16:22:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220727162250euoutp020afe69a1439bc809b7a0aa053c107a87~FvDQvyexF1245112451euoutp02c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1658938970; bh=9bdbdbUw6KTK2r5hitLcl/AEOPoWY1dExIREEyMjHGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pN1vw6nDRuYgCIUnwWmU+afmN2lz9zLzoHRNwUhC9wwa3lkjI/uhi80ro+uKo7GtP mjuTCW9HayJHv+dQsoJROxB2AKtKMYq/3o7xGnmjka/Emj9jawUJXBaCKPgVvPZ2br F9zEPiWnCv3Ije/VvcSK1I+lu2WS775a5jcJoc4I= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220727162248eucas1p2754b09a52a4cc967eb7028ff301c7878~FvDPAZvNB0838408384eucas1p2_; Wed, 27 Jul 2022 16:22:48 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 84.E8.09580.85661E26; Wed, 27 Jul 2022 17:22:48 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220727162247eucas1p203fc14aa17ecbcb3e6215d5304bb0c85~FvDOOXpfQ2171521715eucas1p2h; Wed, 27 Jul 2022 16:22:47 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220727162247eusmtrp1e5b1271244a6333800cd425899ce71ee~FvDOH-yMw0298902989eusmtrp1G; Wed, 27 Jul 2022 16:22:47 +0000 (GMT) X-AuditID: cbfec7f5-9adff7000000256c-d9-62e166583e6d Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 05.8D.09038.75661E26; Wed, 27 Jul 2022 17:22:47 +0100 (BST) Received: from localhost (unknown [106.210.248.8]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220727162246eusmtip1a0c727e66078316c43a69fc09227168e~FvDN32e690064100641eusmtip1P; Wed, 27 Jul 2022 16:22:46 +0000 (GMT) From: Pankaj Raghav To: damien.lemoal@opensource.wdc.com, hch@lst.de, axboe@kernel.dk, snitzer@kernel.org, Johannes.Thumshirn@wdc.com Cc: matias.bjorling@wdc.com, gost.dev@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, linux-block@vger.kernel.org, pankydev8@gmail.com, bvanassche@acm.org, jaegeuk@kernel.org, dm-devel@redhat.com, linux-nvme@lists.infradead.org, Pankaj Raghav , Luis Chamberlain , Adam Manzanares Subject: [PATCH v8 01/11] block: make bdev_nr_zones and disk_zone_no generic for npo2 zsze Date: Wed, 27 Jul 2022 18:22:35 +0200 Message-Id: <20220727162245.209794-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220727162245.209794-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEKsWRmVeSWpSXmKPExsWy7djPc7oRaQ+TDKavZrOYfljRYvXdfjaL aR9+Mlv8Pnue2WLvu9msFjcP7GSy2LNoEpPFytVHmSyerJ/FbPG36x6Txd5b2haXd81hs5i/ 7Cm7xYS2r8wWNyY8ZbT4vLSF3WLNzacsFiduSTsIeVy+4u2xc9Zddo/LZ0s9Nq3qZPPYvKTe Y/fNBjaPna33WT3e77vK5tG3ZRWjx+bT1R6fN8l5tB/oZgrgieKySUnNySxLLdK3S+DKaDjw nrFgt0jFhcf32RsYOwW7GDk5JARMJP7N7GUCsYUEVjBKLPjK2sXIBWR/YZ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Hm5lMWixO3pB2EPC5f8fbYOesuu8fls6Uem1Z1snlsXlLv sftmA5vHztb7rB7v911l8+jbsorRY/Ppao/Pm+Q82g90MwXwROnZFOWXlqQqZOQXl9gqRRta GOkZWlroGZlY6hkam8daGZkq6dvZpKTmZJalFunbJehlNBx4z1iwW6TiwuP77A2MnYJdjJwc EgImEu9md7B2MXJxCAksZZQ48fMaC0RCQuL2wiZGCFtY4s+1LjaIoqeMEvNOv2XuYuTgYBPQ kmjsZAcxRQQqJc5+kQUpZxb4wySxdwGYLSwQJTHn6gMmEJtFQFXi6P21bCA2r4CVREPrX2aI 8fISMy99ZwexOQWsJTZPmQdWLwRU8+zBR6h6QYmTM5+wQMyXl2jeOpt5AqPALCSpWUhSCxiZ VjGKpJYW56bnFhvpFSfmFpfmpesl5+duYgTG7bZjP7fsYFz56qPeIUYmDsZDjBIczEoivAnR 95OEeFMSK6tSi/Lji0pzUosPMZoC3T2RWUo0OR+YOPJK4g3NDEwNTcwsDUwtzYyVxHk9CzoS hQTSE0tSs1NTC1KLYPqYODilGpimx7zbf4bR4JLesn0axrX7nh7J+dC0afd8OWbG7C77c3HC 669NU9l9Qlxm399FG39FvavcekrEvPSeyOZVOY+4fn7jdH+zyci6NHXOsW1N1pcXf1J6Jvpi 35S+S1mRT4VPRbZ+tN+1xHWKm+oSs8C3lV2vzs2bvO3fyV86DcKSH9wSA4+H2p8Rqtv9Omg2 q/yKYuP8es1nCjmBLcXGf4yjLm8WKfP1UDikp2/+81TCvZYf7XsTNtmuvCmSOk+3y+Zqq/3J y1982SaXN9wP0VT9ZFM5Q8P5o6NTUONVvXUW7xZo1b654+2VNCWfiSX9UO9GkY0Lp1cbm208 1ePXv0hl2a0nO2RvyFxhr8ztXdWjxFKckWioxVxUnAgAwdXUPmQDAAA= X-CMS-MailID: 20220727162247eucas1p203fc14aa17ecbcb3e6215d5304bb0c85 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220727162247eucas1p203fc14aa17ecbcb3e6215d5304bb0c85 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220727162247eucas1p203fc14aa17ecbcb3e6215d5304bb0c85 References: <20220727162245.209794-1-p.raghav@samsung.com> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adapt bdev_nr_zones and disk_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 Reviewed-by: Bart Van Assche --- block/blk-zoned.c | 13 +++++++++---- include/linux/blkdev.h | 8 +++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index a264621d4905..dce9c95b4bcd 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -111,17 +111,22 @@ EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); * bdev_nr_zones - Get number of zones * @bdev: Target device * - * Return the total number of zones of a zoned block device. For a block - * device without zone capabilities, the number of zones is always 0. + * Return the total number of zones of a zoned block device, including the + * eventual small last zone if present. For a block device without zone + * capabilities, the number of zones is always 0. */ unsigned int bdev_nr_zones(struct block_device *bdev) { sector_t zone_sectors = bdev_zone_sectors(bdev); + sector_t capacity = bdev_nr_sectors(bdev); if (!bdev_is_zoned(bdev)) return 0; - return (bdev_nr_sectors(bdev) + zone_sectors - 1) >> - ilog2(zone_sectors); + + if (is_power_of_2(zone_sectors)) + return (capacity + zone_sectors - 1) >> ilog2(zone_sectors); + + return DIV_ROUND_UP_SECTOR_T(capacity, zone_sectors); } EXPORT_SYMBOL_GPL(bdev_nr_zones); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index dccdf1551c62..85b832908f28 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -673,9 +673,15 @@ static inline unsigned int disk_nr_zones(struct gendisk *disk) static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector) { + sector_t zone_sectors = disk->queue->limits.chunk_sectors; + if (!blk_queue_is_zoned(disk->queue)) return 0; - return sector >> ilog2(disk->queue->limits.chunk_sectors); + + if (is_power_of_2(zone_sectors)) + return sector >> ilog2(zone_sectors); + + return div64_u64(sector, zone_sectors); } static inline bool disk_zone_is_seq(struct gendisk *disk, sector_t sector) -- 2.25.1