Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2063512ioo; Mon, 23 May 2022 09:17:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4/MU2iLoWJhpdNHCe5m4Kww0AGw+6EjkFI1WGkoTWG68iCCTslfD4CTfn74zrD2ZAppfa X-Received: by 2002:a63:fb0a:0:b0:3c1:cd4a:4f93 with SMTP id o10-20020a63fb0a000000b003c1cd4a4f93mr20422330pgh.78.1653322628376; Mon, 23 May 2022 09:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653322628; cv=none; d=google.com; s=arc-20160816; b=WAJfDKNIgbckuSFxDyxL99e9snOFfe1LeIowlkmaVUQ1Tm4BU2aPOVM1lMcqA/vg9m hNg7d3HG0oLMiAc/fRjutgncOiz45tBBra+TJkgs9rVyL6vpYFiC8KudF4dD8Hw35z0p KU+fz3nHerEJvwQqZXca+a56RHa33x4msO6bOzuWJ7YKhJIsT4HZQW2Ufj/IJAbLxkSZ Joo6uDexFz6OHoummVT7n7hC3c3wn2Cbi7EvVaD7D7KpDlRTZ7UHkCeNtG9QOJYeFj2G Cxw5qC1xPsfIN1/JkDyKyZxeYlNhbczN6G6PPS+biWfadSEWGv7zzZsN1dhVOz68CSdr 4B3Q== 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=rvHQ6KWAJnN/wTk9uOYb03xRJQdEtVRuH/wx1RtE7HE=; b=hz2G+KJHTVVtzKUXL9LZ6PN/l9dXytZx50HPwlE7lo8nXAES11geebeGHDbZe7zTFR l5aXS5j/NzlV07avq1YdUunYThQR9zpV+aoL7+Zk6fSXnzwTcpLpcWM6pd33kUF03YIA ao2Wq1pybYODKpQTEBREpXNztuxUOOiGS3G7HWvvE8xcXXMziehfop0UVLKvpdfS6OWx H5tpzU0EeaLsUg9Xekl2D4dg4TFuDLu9+hra8fi3NS0a0jAeTZ/qs/dTf3gXqnq3GwKJ St3MXyCZ1LPtTx5Gj6OvkFFMx8u0OEDfpWUmKn7HcS/ixuojkuiPZeO3u7VxFXxNnG9k 12MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=WBsJ86uP; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id l9-20020a170902f68900b0015cf060b23bsi12023179plg.583.2022.05.23.09.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 09:17:08 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=WBsJ86uP; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 63EE65001F; Mon, 23 May 2022 09:16:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238611AbiEWQQQ (ORCPT + 99 others); Mon, 23 May 2022 12:16:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238472AbiEWQQM (ORCPT ); Mon, 23 May 2022 12:16:12 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C840220F63 for ; Mon, 23 May 2022 09:16:09 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220523161606euoutp0213701de3394320e678cf495448f4fd58~xyB1t35kN1803518035euoutp02b for ; Mon, 23 May 2022 16:16:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220523161606euoutp0213701de3394320e678cf495448f4fd58~xyB1t35kN1803518035euoutp02b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653322566; bh=rvHQ6KWAJnN/wTk9uOYb03xRJQdEtVRuH/wx1RtE7HE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WBsJ86uPBgkd1zGBINfTPSluZ/eUp/FPZX/vg3WS/MjB5tLR81q0rHEbBYRLkpLTv dYBunt9svDngg+yn/0YLWEf2uLKQQL97koSOjz2EuWVPEeX1D0JhyD1IEItGYZQ0Z5 AClXkk7/thGcTd9hQGk9+sI6hs1A4G5mUGSj8A+g= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220523161605eucas1p255aa2158f858eacd6ec421d41a1f2849~xyB0MFXqD2258022580eucas1p2u; Mon, 23 May 2022 16:16:05 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id FC.A9.10260.543BB826; Mon, 23 May 2022 17:16:05 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220523161604eucas1p2927e20dbd0602c08b6df4fc41e62dfbe~xyBz1_CQs1186311863eucas1p29; Mon, 23 May 2022 16:16:04 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220523161604eusmtrp21f0d4014a48df01085abb009a150ac3b~xyBz1Gxts0219002190eusmtrp2I; Mon, 23 May 2022 16:16:04 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-fc-628bb345b402 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id C8.92.09522.443BB826; Mon, 23 May 2022 17:16:04 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220523161604eusmtip262af8805d5f532401444730d338bcc3f~xyBzeftlD0812708127eusmtip2K; Mon, 23 May 2022 16:16:04 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, hare@suse.de, Johannes.Thumshirn@wdc.com Cc: linux-nvme@lists.infradead.org, dm-devel@redhat.com, dsterba@suse.com, jiangbo.365@bytedance.com, linux-kernel@vger.kernel.org, gost.dev@samsung.com, linux-block@vger.kernel.org, jaegeuk@kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v5 1/7] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Mon, 23 May 2022 18:15:55 +0200 Message-Id: <20220523161601.58078-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523161601.58078-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDKsWRmVeSWpSXmKPExsWy7djP87qum7uTDDr+8lmsvtvPZvH77Hlm i73vZrNaXPjRyGRx88BOJos9iyYxWaxcfZTJ4sn6WcwWPQc+sFj87brHZLH3lrbF5V1z2Czm L3vKbnFjwlNGi89LW9gt2jZ+ZXQQ8Ph3Yg2bx+WzpR6bVnWyeWxeUu+x+2YDm8fO1vusHu/3 XWXz6Nuyit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XgMAAA== X-CMS-MailID: 20220523161604eucas1p2927e20dbd0602c08b6df4fc41e62dfbe X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220523161604eucas1p2927e20dbd0602c08b6df4fc41e62dfbe X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220523161604eucas1p2927e20dbd0602c08b6df4fc41e62dfbe References: <20220523161601.58078-1-p.raghav@samsung.com> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 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..e7eec513dd42 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 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 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, -- 2.25.1