Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp637517rwb; Thu, 11 Aug 2022 07:33:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR47QdT/P8HDb4XKlviRyig9ydMvLufwcW9ofmGTtDfwRFifYGInLZAVSAfKQfwCW1oUyz3D X-Received: by 2002:a17:90b:4c8c:b0:1f5:2214:a02f with SMTP id my12-20020a17090b4c8c00b001f52214a02fmr9218616pjb.66.1660228397958; Thu, 11 Aug 2022 07:33:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660228397; cv=none; d=google.com; s=arc-20160816; b=JlNVgwiTcu98pwoA3cpmv3SbbKKcE6DWBIFsY5zt1yVuqeM3u1iNGBHIc4Gr9/ahx1 8AMLdMS4fQv+10Mc4PcPYOq7sOOxR+TzqzF4VTuH2KFnNiXo2mnwud2rJ05pyeJuQ/Hy j8Zn2HyqMrrvtG6KixwmngBKFMY6pM31ATMHZ9/iDBX7z9HXlBHOTymfDCmxFkVTmaqb d49rjFxjO9xzlfhrjLut4UL12NRX2VxyTH6zhsn84zOAnymSIn1JrHrGarNW+pQzi3G3 +OPlN+mS0KbjDFvqwMh+pK7kvsVrKuDaG94rRwjVCyFYJHIT5mJGmCX8B7Ei48XAnlie Re9A== 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=AD8v/RK3vFIqsgabYiTtVZbPbcAOQ4zUOz/AmbfbvbE=; b=p9WF7ppzsdXWKjNlcwSvIQ5rToVSvep0xzY6TIh9DPW96baRUlisXqwhYjJxiq1NZj V9++FZV5F502zG1RzjC3EXY7a0fMQsOWkcH/w7gxMk9KnjwR9k2JrnEsPeeP9DllNr3P elabUXWkLJ6Gts71LT45zVTOGpClEeg1PrZWFGA2Z82NG1e6XU5btgP4PBQP8l5VUFZe Hcv30jU3iUAeupXjIBJp3dsmuMwqiEvW7CrENBhbn4NFP+Ui3Oudgv40alejrRAN28Gd pFbHzgQWSjKL/iNgGcrdD3pAzMhvWdoB7+x5jSbJ5lBDcxc6Hv+ZnThUSJJJt95TIzq6 TGZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=SnL2YnjA; 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 q5-20020a631f45000000b0041b7a0b673fsi19391941pgm.449.2022.08.11.07.32.59; Thu, 11 Aug 2022 07:33:17 -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=SnL2YnjA; 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 S235560AbiHKObN (ORCPT + 99 others); Thu, 11 Aug 2022 10:31:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235322AbiHKOaz (ORCPT ); Thu, 11 Aug 2022 10:30:55 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D2E36CD11 for ; Thu, 11 Aug 2022 07:30:51 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220811143048euoutp01b29950f056d86f49435d448e4089cf7e~KUMuqmh_c2261422614euoutp01A for ; Thu, 11 Aug 2022 14:30:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220811143048euoutp01b29950f056d86f49435d448e4089cf7e~KUMuqmh_c2261422614euoutp01A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1660228248; bh=AD8v/RK3vFIqsgabYiTtVZbPbcAOQ4zUOz/AmbfbvbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SnL2YnjAOjY9wL4Wt4C64w9KF1nFRqZdaZW/RDnlmzzKZIiBg8J4TFoE+2N8hsPIG DQOZaXUJGT6OwD2yA6ljG3xTF1AdF/bEc5qPJ3wD7qNQyKXJeVYAHdOY4+lxJ8AJKF HuVER4Y91IZPsdaCukU9YV9lkh8JP5DXOhm2/9Vc= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220811143046eucas1p2aca499e896bb89a154e4a4b1bdf718e2~KUMs082vL1006810068eucas1p2D; Thu, 11 Aug 2022 14:30:46 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 58.8C.09580.69215F26; Thu, 11 Aug 2022 15:30:46 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220811143045eucas1p2773a7e7bbe9f3667d1105cc1465dac42~KUMsXYqvE2328423284eucas1p2G; Thu, 11 Aug 2022 14:30:45 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220811143045eusmtrp2a1accb11028d7272eec67818e141c2aa~KUMsWeF4W0786307863eusmtrp2t; Thu, 11 Aug 2022 14:30:45 +0000 (GMT) X-AuditID: cbfec7f5-9c3ff7000000256c-a0-62f51296b42f Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id FB.00.09038.59215F26; Thu, 11 Aug 2022 15:30:45 +0100 (BST) Received: from localhost (unknown [106.210.248.43]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220811143045eusmtip2ddbb16a5b5589429fc9855578ecfe1d6~KUMsA2dat1262412624eusmtip2w; Thu, 11 Aug 2022 14:30:45 +0000 (GMT) From: Pankaj Raghav To: snitzer@kernel.org, axboe@kernel.dk, hch@lst.de, agk@redhat.com, damien.lemoal@opensource.wdc.com Cc: linux-block@vger.kernel.org, Johannes.Thumshirn@wdc.com, bvanassche@acm.org, matias.bjorling@wdc.com, hare@suse.de, gost.dev@samsung.com, linux-nvme@lists.infradead.org, jaegeuk@kernel.org, pankydev8@gmail.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Pankaj Raghav , Luis Chamberlain , Adam Manzanares Subject: [PATCH v10 01/13] block: make bdev_nr_zones and disk_zone_no generic for npo2 zone size Date: Thu, 11 Aug 2022 16:30:31 +0200 Message-Id: <20220811143043.126029-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220811143043.126029-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrJKsWRmVeSWpSXmKPExsWy7djP87rThL4mGRx8KmAx/bCixfpTx5gt Vt/tZ7OY9uEns8Xvs+eZLfa+m81qcfPATiaLPYsmMVmsXH2UyeLJ+lnMFn+77jFZ7L2lbXF5 1xw2i/nLnrJbTGj7ymxxY8JTRovPS1vYLdbcfMpiceKWtIOwx+Ur3h47Z91l97h8ttRj06pO No/NS+o9dt9sYPPY2Xqf1eP9vqtsHn1bVjF6bD5d7fF5k5xH+4FupgCeKC6blNSczLLUIn27 BK6Mv1Pbm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c1465dac42 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220811143045eucas1p2773a7e7bbe9f3667d1105cc1465dac42 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220811143045eucas1p2773a7e7bbe9f3667d1105cc1465dac42 References: <20220811143043.126029-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, T_SCC_BODY_TEXT_LINE 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 functions so that they can also work for non-power-of-2 zone sizes. As the existing deployments assume that a device zone size is a power of 2 number of sectors, power-of-2 optimized calculation is used for those devices. There are no direct hot paths modified and the changes just introduce one new branch per call. Reviewed-by: Luis Chamberlain 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 84b13fdd34a7..ab82d1ff0cce 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -674,9 +674,15 @@ static inline unsigned int disk_nr_zones(struct gendisk *disk) static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector) { + sector_t zone_sectors = disk->queue->limits.chunk_sectors; + if (!blk_queue_is_zoned(disk->queue)) return 0; - return sector >> ilog2(disk->queue->limits.chunk_sectors); + + if (is_power_of_2(zone_sectors)) + return sector >> ilog2(zone_sectors); + + return div64_u64(sector, zone_sectors); } static inline bool disk_zone_is_seq(struct gendisk *disk, sector_t sector) -- 2.25.1