Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4667585iob; Sun, 8 May 2022 21:15:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEfYuNt3Y1c7zVpwbgxLV70NTUFqJmdye7CwHbgYf4y8F8ehyfLhzc5x/tn87JN0e3iniO X-Received: by 2002:a17:902:b789:b0:15b:5d52:7542 with SMTP id e9-20020a170902b78900b0015b5d527542mr14763318pls.26.1652069730203; Sun, 08 May 2022 21:15:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652069730; cv=none; d=google.com; s=arc-20160816; b=USFp2aaekljf4Cv9E1y92W6aXVUhTGew6EIN6xLpI6K0Eoyr86+etHzkvlq/plEWCc XGZmljw9QTYwwZGvJajQQcRfFejNNlJclAC15UmiwJr1x7Rz9VeTtwcfsxLqrnGsRcPj ZHWiX3pRLI9RuYixIJZMmr1OmlcYMQxUh0XckCcYVLBgIfgz/Xv3fjkU1odw2je5oUJz FYTTHSACSwu4YIUtwRxNnV+r+UbtQZjCKvDctO4mLHruoi9hfPp8Xl/AO58MdNMcufac 6nZHgweCibCJMR0pO2TLGRbbQuDwBFtj+yGiu4zAbLufTQGGeIZBhegxwjRpTkdhbYc/ XADg== 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=lp2K3w6bYU/ZGZyfjOrT9sOG4NQYsIr+x+HLsdgsemk=; b=ZT14vU/4cqRE/Ryd42v290mwCbKJVMLnAph9KxONSpkigvnqH25eHvS1Int7OamVPM Cfm+yUZKTof7ZRkVueAw0VjT+kpMgOHB6kWJXVzrSApfLE7aFewMGVlgxgeu5SCJbxFC n8GWNJwSWZad1llCMlTWfrB5KTIoq6hS86JAGYcZ+ZhunyS6OBGAUZbfm/ncjphzpnhp mB8iXQsmAfrODrf8CXzkAJ6QmtPgu3vSBvJGirNMXlYFlLC/vorELhDsp2K0shXCbO0S 6ieUGqgF3vI+/O4lhvDoqKCdW7DresktAdjtRisIgH1I9/PKHIEG/iwCA65vXoPbXdn7 w1cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="AcGo/loW"; 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 cd11-20020a056a00420b00b0051080c93279si8098826pfb.129.2022.05.08.21.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 21:15:30 -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="AcGo/loW"; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3F088116679; Sun, 8 May 2022 21:14:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389888AbiEFIPI (ORCPT + 99 others); Fri, 6 May 2022 04:15:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389838AbiEFIO6 (ORCPT ); Fri, 6 May 2022 04:14:58 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A70CF67D28 for ; Fri, 6 May 2022 01:11:13 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081110euoutp01d439ea81d5dfe4e1d02d34bbc7077dbf~sdckh3s8g2290722907euoutp012 for ; Fri, 6 May 2022 08:11:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220506081110euoutp01d439ea81d5dfe4e1d02d34bbc7077dbf~sdckh3s8g2290722907euoutp012 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824670; bh=lp2K3w6bYU/ZGZyfjOrT9sOG4NQYsIr+x+HLsdgsemk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AcGo/loWZtX/HhUmelZDOIL72Pc0R5AMpwfSstxXD8NYUkRcC1DptVlRK6AisouRi 4vp32SxkE3HRp2VYokX3yFi2V0A3IQdIY0J02c0xeFI4whIEDyd6G6stCx55/J1pzz /ow+vFK9N8qUZ0bwkJY3AjnFhgFmshGnLT//KyUs= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220506081108eucas1p157bd0b3e2c1c9e95cb15481355714182~sdcioadXK1692416924eucas1p1u; Fri, 6 May 2022 08:11:08 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 93.3C.10260.B18D4726; Fri, 6 May 2022 09:11:07 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220506081107eucas1p1070e00b208e00090c235017435be1593~sdciCeg161979919799eucas1p1f; Fri, 6 May 2022 08:11:07 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220506081107eusmtrp2f9facb08d5d065dc059e123c7ff68edc~sdch_Ke7I2593625936eusmtrp2Q; Fri, 6 May 2022 08:11:07 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-cf-6274d81b13d3 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id AA.E9.09404.B18D4726; Fri, 6 May 2022 09:11:07 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220506081106eusmtip18f256f486b1f42e6f968c5b64f6e9360~sdchn8WJL0467104671eusmtip1n; Fri, 6 May 2022 08:11:06 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 01/11] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Fri, 6 May 2022 10:10:55 +0200 Message-Id: <20220506081105.29134-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Sf1CTdRzH+z7Ps2eDa97j4PR7Ds/akSQeQ6PiW3JBR1cPanfaHxV5V83x hOg2bAOMVsqPheO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pd2j01e94Lmozdn3p+L936yzjWHZ67vwFJ+XjtpdE77ru/NSvqV29leESywQay1Ru3H6b/ih r2fn7Jt0fYbg/G0pq3ucVjvNXXYv9W22trHKU/PYWXO/FywzKdNL9DNfs2K22ROnfRO2Oizs UrN6xa0Y3fKua/an0ILM+C3cn7oXt91It5aZ/Hxyu32s4xmjy22Xdh5LWX930dfclTWWr/60 ylg8a+/f72u9+4PkpIzC4xbPOWbWWP+5xvVffreqc2PY8/ScxR0p86VXCsQuCj2ob/uBeZFY Hut+rmxX1bOlKbNfHLzP4h6/4Gz79SlxJksecT/bdFFvV+qsme+bgl6qme9kni5loxCySIml OCPRUIu5qDgRAH4I+hKxAwAA X-CMS-MailID: 20220506081107eucas1p1070e00b208e00090c235017435be1593 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220506081107eucas1p1070e00b208e00090c235017435be1593 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081107eucas1p1070e00b208e00090c235017435be1593 References: <20220506081105.29134-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 | 13 ++++++++++--- include/linux/blkdev.h | 8 +++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 38cd840d8..140230134 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -111,16 +111,23 @@ 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