Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4766419iob; Mon, 9 May 2022 00:43:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaU5mDPnZln+zmT9bsFK0Yo/2vtNUN3NBsmvQEXbIaInTFpzgAEDfiYa2VcTtdI2zxdWTy X-Received: by 2002:a65:6657:0:b0:381:1b99:3f04 with SMTP id z23-20020a656657000000b003811b993f04mr11992617pgv.512.1652082204159; Mon, 09 May 2022 00:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652082204; cv=none; d=google.com; s=arc-20160816; b=ZyPcPe+byJAnp/bKbPD4z8JMEAdvjPGiPlRMsCQg31GFjuXp5u+26StaJCnP+qXhin 3T0mS6fjw6zJo6PQ28vppDjjKQ0O33TZT4+9eZOJ7fx98mAhhjt5dc5M3DPhb+H+38xc TyAVv9+iuul1DnJOXYjHorIX7R+zQ4zfjalaI1bpbSw38PSLlEP7/O8VDPD/smaRTf7I xU341g5/m8H8h4qhnIe5kYRUHRBmQ2/K3zObgelpUlJXM1XImI/dyjuo5GLPpnRxBGs6 tn0KisNlZT8f4fpSbf2dyl1n+8ipCAnWNiApr6e6uNbdht94MrmdEBrA2YfTBaiUMKPn v8SA== 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=FgRquCUlTM96nfBunGHxef/LSdqBZ3l0TN68Q/0AcX4=; b=iDIMQSsIUxg5She9Xk2nqtlTZXx95xATB2OvDBo2GXZL2vOmpoNmlWbv3Ab7D4ehdS XjV1MxJ8Kgw5AYS09mQUbl4rhqbWKW3Lz38VroS+yO0z2hLUbEvUs2RL6BR+9POdvx5z H3PVhiFdjIUz+sTzy7W/6upNl49+WOSP2gzT7JlxCJ/LS1qwl0Mq4CoaAhcd3M3ooh0P WQv2QEKTW8ZRRo+rqJlGDf725wpZZqVViQ2isdfT5wgaulPYPqQu4CqKTx6G7XMN1FGv bGCVuG5iIfqKLxkpcj+Rl6OL4epnixihv39AkIz24650jY4ZpBLYmg7+8SllwlUa5MQ+ m31A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=XyR5R4cS; 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 b9-20020a170902bd4900b0015ea137dd51si10098856plx.608.2022.05.09.00.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 00:43:24 -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=XyR5R4cS; 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 90CC19E9E1; Mon, 9 May 2022 00:37:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233303AbiEENxb (ORCPT + 99 others); Thu, 5 May 2022 09:53:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380150AbiEENx0 (ORCPT ); Thu, 5 May 2022 09:53:26 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B78AA59942 for ; Thu, 5 May 2022 06:49:43 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220505134936euoutp01f1242df7c72a958e8ac344523e6afae5~sOayHdtto2733027330euoutp01X for ; Thu, 5 May 2022 13:49:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220505134936euoutp01f1242df7c72a958e8ac344523e6afae5~sOayHdtto2733027330euoutp01X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651758576; bh=FgRquCUlTM96nfBunGHxef/LSdqBZ3l0TN68Q/0AcX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XyR5R4cSgpoUXLDIeuACGrtgFGHgSZLsRBkOm2wd44VD2jLtIN4Cr39xkskECGdna i+pyHUlwkm9ykzBx3RD9u33vlsBT6jdgcPKTzdDqT35Dq4QAZn2+ftoFSMgY+RPIDy 7ooQKNH/CqSKImIaJsSC5y8WcFuomVvzBHGaWVR4= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220505134934eucas1p1b9ba4e2f969ea7b600781ac79335c649~sOawerQ8H2600826008eucas1p1y; Thu, 5 May 2022 13:49:34 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 3B.6C.09887.EE5D3726; Thu, 5 May 2022 14:49:34 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220505134934eucas1p2de726a86c47310171425a17a7ce2858b~sOav3grtd2878928789eucas1p2F; Thu, 5 May 2022 13:49:34 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220505134934eusmtrp22744208461eabef54595df6fbd598287~sOav2mgZr2604426044eusmtrp24; Thu, 5 May 2022 13:49:34 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-b9-6273d5eec455 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 72.2A.09404.DE5D3726; Thu, 5 May 2022 14:49:33 +0100 (BST) Received: from localhost (unknown [106.210.248.170]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220505134933eusmtip2fa887742218995cb0b399247ce86bc53~sOavf3Ojp1531915319eusmtip2N; Thu, 5 May 2022 13:49:33 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, dsterba@suse.com, jaegeuk@kernel.org, bvanassche@acm.org, hare@suse.de Cc: jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, matias.bjorling@wdc.com, gost.dev@samsung.com, pankydev8@gmail.com, Pankaj Raghav , Luis Chamberlain , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/11] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Thu, 5 May 2022 15:47:01 +0200 Message-Id: <20220505134710.132630-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505134710.132630-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrHKsWRmVeSWpSXmKPExsWy7djPc7rvrhYnGcxrULdYfbefzWLah5/M Fr/Pnme2uPCjkcni5oGdTBZ7Fk1isli5+iiTxZP1s5gteg58YLFY2fKQ2WLvLW2Ly7vmsFlM aPvKbHFjwlNGi89LW9gt1tx8yuIg4HH5irfHvxNr2Dx2zrrL7nH5bKnHplWdbB4LG6Yye+y+ 2QAUb73P6tG3ZRWjx/otV1k8Np+u9v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1p2de726a86c47310171425a17a7ce2858b X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220505134934eucas1p2de726a86c47310171425a17a7ce2858b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220505134934eucas1p2de726a86c47310171425a17a7ce2858b References: <20220505134710.132630-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 | 14 +++++++++++--- include/linux/blkdev.h | 8 +++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 38cd840d8..a09a2eef9 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -111,16 +111,24 @@ 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, -- 2.25.1