Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3265171iob; Mon, 16 May 2022 17:34:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKuywO8I2WIVUxs7Vcbo/Y8kec4U8D5NGtrNVDufG6Xq55zMt1BExd7X/WTqZf/nUfeaqH X-Received: by 2002:a17:902:bb94:b0:161:60b3:3300 with SMTP id m20-20020a170902bb9400b0016160b33300mr11205709pls.97.1652747669215; Mon, 16 May 2022 17:34:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652747669; cv=none; d=google.com; s=arc-20160816; b=Q7uOxaYACd7WNsIFkT4xe9QOOyldQEOGyncbC/52YTrYSYodnLf5e1GkI7z0BfR9sc J4Sp6gwqxmbPz/W6uAdxy8cNwX6zex7WYEfh1BaXasgJsGeUu9+XBGIEh7th04jyMfu+ CpZakcr4eLgcpD9g2cKoZjBnRz3cTThLDxEXaYH9DD0IAN2Gy4x1Mv0L5Hhk8iADvFyl zPJNex7sDKj1+1KCwJszNPWN8mw0gVN7ragxzSUKoHZ520i05St6YXLaexWrkkB3vgQ4 XnhqsuTvm4BmefPBXyCBEoaxa0TcAI2P2Q1oTAi2nMnyszeOxz03hpMV7fvMahFu6yiC ePSA== 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=WvEJ+uCFY6497z9l0ql0dZiyKMFRvedc/xS7v8sN1PjjwXKOLDdQieqwp6zBc1g184 2d2SEC4R40WhR8RnMJE7X5JA6I24ClkI5jsJT1AsIuWCLaHFtTAWOF+7rXIynO3oI8GL cV0qAb1kgYp9ddt4hj9PFem8Cz2s1WMtIPiooiqTphPi13iiIrCjLn+PrmbKDHsbC87k IToTGVQMje2XyeL5nFp59GZwcVkdHYoAGmDM2qXcprcV3ncTF0MJZdSLVMvCHrAq0S23 QZxwxkCEYWjsWOiAAq3UyxKQGjz7tkMswJbFhCPgNBLMwtwcG3wZnGsL99BLA8StiqOY ZnAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=gao6kZNX; 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 s21-20020a639255000000b003c17c1b8bedsi14827438pgn.343.2022.05.16.17.34.18; Mon, 16 May 2022 17:34:29 -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=gao6kZNX; 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 S1343948AbiEPQyg (ORCPT + 99 others); Mon, 16 May 2022 12:54:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241874AbiEPQy2 (ORCPT ); Mon, 16 May 2022 12:54:28 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E411127B34 for ; Mon, 16 May 2022 09:54:23 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220516165422euoutp01a97bef964e335cececa6adf8c2222f23~vpCPfPVwk2241322413euoutp01y for ; Mon, 16 May 2022 16:54:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220516165422euoutp01a97bef964e335cececa6adf8c2222f23~vpCPfPVwk2241322413euoutp01y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652720062; bh=lp2K3w6bYU/ZGZyfjOrT9sOG4NQYsIr+x+HLsdgsemk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gao6kZNXJCA2SyuQGlCnltENjf2JuoRrXfzpZ9zap0nqz68eWU+dTIb+g2u01N8Dq 5kR+8EWzwRKgRheByVLoD4sTh+/BxZ2nLbvBWq3GPJc4zTkNw297OMLUBxLNe+btal y7ay2+cWGrzwAWUPcZWIjgvIO7TF+1jqqXS1ZTe8= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220516165420eucas1p1bcc0f0bd3a9d48f46d084febc883e0cc~vpCNyNJtW3183531835eucas1p1K; Mon, 16 May 2022 16:54:20 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 9E.D6.10260.CB182826; Mon, 16 May 2022 17:54:20 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220516165419eucas1p104aadda60df323e6154bfc3b92103b7b~vpCNYo_z33185231852eucas1p1L; Mon, 16 May 2022 16:54:19 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220516165419eusmtrp1da80ad51c871b452d6f5500bc402eb7f~vpCNXvW_c2961829618eusmtrp1E; Mon, 16 May 2022 16:54:19 +0000 (GMT) X-AuditID: cbfec7f5-bf3ff70000002814-3e-628281bc9a2c Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 4B.89.09522.BB182826; Mon, 16 May 2022 17:54:19 +0100 (BST) Received: from localhost (unknown [106.210.248.7]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220516165419eusmtip17f050be3da427ead4fb6b476c789280b~vpCNDBYCX2383023830eusmtip1X; Mon, 16 May 2022 16:54:19 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, pankydev8@gmail.com, dsterba@suse.com, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, Luis Chamberlain , Hannes Reinecke Subject: [PATCH v4 01/13] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Mon, 16 May 2022 18:54:04 +0200 Message-Id: <20220516165416.171196-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220516165416.171196-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBKsWRmVeSWpSXmKPExsWy7djP87p7GpuSDK53CFqsvtvPZvH77Hlm i73vZrNaXPjRyGRx88BOJos9iyYxWaxcfZTJoufABxaLvbe0LS49XsFusWfvSRaLy7vmsFnM X/aU3eLGhKeMFp+XtrBbrLn5lMVBwOPfiTVsHjtn3WX3uHy21GPTqk42j81L6j1232wACrfe Z/V4v+8qm0ffllWMHuu3XGXx2Hy62uPzJrkAnigum5TUnMyy1CJ9uwSujL7FixgLZopUHPg8 mamB8ZZAFyMnh4SAicSN7uusXYxcHEICKxgl/l3YxwSSEBL4wihxvF8dwv7MKHFwlitMw9KZ v1kg4ssZJWb0u0A0P2eUWPbqBG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vucrisfl0tcfnTXIBPFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYm lnqGxuaxVkamSvp2NimpOZllqUX6dgl6GX2LFzEWzBSpOPB5MlMD4y2BLkZODgkBE4mlM3+z dDFycQgJLGWUWNb/hQkiISFxe2ETI4QtLPHnWhcbRNFTRolNTe1ARRwcbAJaEo2d7CA1IgIF EnP6t7CA2MwC55kk9q93B7GFBRIlZv14D1bDIqAqsXt2IxuIzStgJfFi83R2iPnyEjMvfWcH GckpYC2xuosbJCwEVPL1yS12iHJBiZMzn0CNl5do3jqbeQKjwCwkqVlIUgsYmVYxiqSWFuem 5xYb6hUn5haX5qXrJefnbmIERuq2Yz8372Cc9+qj3iFGJg7GQ4wSHMxKIrwGFQ1JQrwpiZVV qUX58UWlOanFhxhNgc6eyCwlmpwPTBV5JfGGZgamhiZmlgamlmbGSuK8ngUdiUIC6Yklqdmp qQWpRTB9TBycUg1M7Pcbb0tJiolxsB7lSj8p7O2mczzNa6/e03UhRcc/ZTV7T12oVKO1tmLB 5k+7z9gd7FoZfeVKzbaD6cYzWpdJmPY9dPz867vTiyfPZK8+CDr/XvzALNdV/DcDu20XHDeo cfig/vuHTtQqtX39O3oMf87gSa1tdk2YMGdLf+SLEyXpqepFZkLSS9PbXjqza64469h0NiLS 5N71KXy8Gmlpe3+3/j/4ItlCNvD7E4F7vw/sLvivvTV54aq/DssuJIns/mL2SuIq84tb8/Zw 3Fe4vWGzrmKwxL0Z13W+f3dSmrWn2dB4wcOFsc2VNyLfBt2dULbGqySWK0BW/6HJzXuvthp9 n28zeQlr9ossmQxPEyWW4oxEQy3mouJEALGUZ2ldAwAA X-CMS-MailID: 20220516165419eucas1p104aadda60df323e6154bfc3b92103b7b X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220516165419eucas1p104aadda60df323e6154bfc3b92103b7b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220516165419eucas1p104aadda60df323e6154bfc3b92103b7b References: <20220516165416.171196-1-p.raghav@samsung.com> X-Spam-Status: No, score=-7.4 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 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