Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp360931iog; Wed, 15 Jun 2022 03:54:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vAFbpdltmSF2G6LFNNBMlsn/onldnLiqp21DzR4+NSFJByQVwkw2EYChLigEPILMYCV/IJ X-Received: by 2002:a17:90b:3b45:b0:1e8:8688:219d with SMTP id ot5-20020a17090b3b4500b001e88688219dmr9515749pjb.231.1655290482049; Wed, 15 Jun 2022 03:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655290482; cv=none; d=google.com; s=arc-20160816; b=rndK7l9R/Yk6iwcYXXfuRUoguJmLQQWHPrUwH+TrV3df0tqY/m1J3XF4/88DM+jrSl owp4xBb8RAl8XFOaol30M99HaGuMGaMQjdYXaHnhrRWKSnzeTtn8hvr3riqjievbCOpJ HjgzHLtJmHcNQX1fFR2vvnGi7RTmzVDtdbleyevfQ/w6SjkX7JnAZUpMweOD+76C982b ra/A5F9SPGS2f1/7vkdKy58FJ0stkga3sK/+HnO+SpYN2f6rqxEhrtmy1i0ZxvtRvTTW Z1rTD2Bpjqc945YBvRNGPb9/cUJU3rNuM8Vzhj9taWxI7+SFBvrVP/sziId+pIacMPkQ cAag== 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=Owj5SwDy5cIi235KyiliqrWe09HaL8B16ylUw06/YSQ=; b=zRHlLK3GSjdPcY+q8xv+7vjahcDYEtrlDQLwm5LXJXkAed8b9on9ISynVq0bNiUkUv 5QZQ2yM1epvHkT06RDfz3Eysljr2wFWEwme31YOnR7B/AgzpXybnP47LG0tdPTwro6S0 L5YEF1smK5Zjzr7AiCCvb3iyVaz6d7rTLSZFFXU/NosGsaC6eB6b6VrgULzdBGoKK4M3 hW3XmyuNMpI262vAKeeroX/1Ck/x5YkmVZCfUATZ4M736IsVWSU+ZzWIL/olNtXOzsU5 ECTEtCE5tTzKnCjYrrTkZ2r9P+tp1v8NH5UaakOKA8EUrGVRh+pBeKXAdByQ/CC6Jplz Pevw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=jtXOC52f; 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 d14-20020a17090a498e00b001e2d215e322si2104148pjh.126.2022.06.15.03.54.30; Wed, 15 Jun 2022 03:54:42 -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=jtXOC52f; 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 S1347176AbiFOKTs (ORCPT + 99 others); Wed, 15 Jun 2022 06:19:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346521AbiFOKTg (ORCPT ); Wed, 15 Jun 2022 06:19:36 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DA153F89F for ; Wed, 15 Jun 2022 03:19:31 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220615101930euoutp0233f9dfa02dc8a1ce377cc800fe365d07~4xACslHCr2915529155euoutp02B for ; Wed, 15 Jun 2022 10:19:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220615101930euoutp0233f9dfa02dc8a1ce377cc800fe365d07~4xACslHCr2915529155euoutp02B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1655288370; bh=Owj5SwDy5cIi235KyiliqrWe09HaL8B16ylUw06/YSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jtXOC52fvw37hNrubcz1a6F9mtfmezXeGipERA4vXY/EXRwA/1rXreHjJotmcopow by1Zu7fyx04YH79lQrGQhoYIs6H3q2EM2rMCgriWfKn+HIj+V84Beq/tBfhs/s+2Kd GQZgt1idh7YvWW/pKCMwu8u+jYgai/Poag5CBTYU= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220615101928eucas1p1b977b0e4c5103c43695d0073172d222d~4xAA3t8X30963309633eucas1p1n; Wed, 15 Jun 2022 10:19:28 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id D5.2B.09664.032B9A26; Wed, 15 Jun 2022 11:19:28 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220615101927eucas1p17220c7a36f69f59ff8ddd560b42967ec~4xAAaJBok2789027890eucas1p1_; Wed, 15 Jun 2022 10:19:27 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220615101927eusmtrp21290cb4f6f1f11203710eaa6a045886f~4xAAZHNrb0349503495eusmtrp2H; Wed, 15 Jun 2022 10:19:27 +0000 (GMT) X-AuditID: cbfec7f2-d81ff700000025c0-b9-62a9b2307870 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 15.45.09095.F22B9A26; Wed, 15 Jun 2022 11:19:27 +0100 (BST) Received: from localhost (unknown [106.210.248.244]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220615101926eusmtip2a4d1534f6d9fb211105b6da848dd27ef~4w--OR_FM0785907859eusmtip2F; Wed, 15 Jun 2022 10:19:26 +0000 (GMT) From: Pankaj Raghav To: hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, axboe@kernel.dk Cc: bvanassche@acm.org, linux-kernel@vger.kernel.org, jiangbo.365@bytedance.com, hare@suse.de, pankydev8@gmail.com, dm-devel@redhat.com, jonathan.derrick@linux.dev, gost.dev@samsung.com, dsterba@suse.com, jaegeuk@kernel.org, linux-nvme@lists.infradead.org, Johannes.Thumshirn@wdc.com, linux-block@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v7 01/13] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Wed, 15 Jun 2022 12:19:08 +0200 Message-Id: <20220615101920.329421-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220615101920.329421-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJKsWRmVeSWpSXmKPExsWy7djP87oGm1YmGSz5wWOx+m4/m8W0Dz+Z LX6fPc9ssffdbFaLCz8amSxuHtjJZLFn0SQmi5WrjzJZPFk/i9mi58AHFou/XfeAYi0PgYpv aVtc3jWHzWL+sqfsFjcmPGW0+Ly0hd1izc2nLBZtG78yOgh7XL7i7fHvxBo2j52z7rJ7XD5b 6rFpVSebx8KGqcwem5fUe+y+2QCUa73P6vF+31U2j74tqxg91m+5yuKx+XS1x+dNch7tB7qZ AvijuGxSUnMyy1KL9O0SuDKWn2tiLmgTqfh/dAtzA+NVg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ff8ddd560b42967ec X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220615101927eucas1p17220c7a36f69f59ff8ddd560b42967ec X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220615101927eucas1p17220c7a36f69f59ff8ddd560b42967ec References: <20220615101920.329421-1-p.raghav@samsung.com> X-Spam-Status: No, score=-8.3 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=ham 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 38cd840d8..8b0615287 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 DIV_ROUND_UP_SECTOR_T(capacity, zone_sectors); } EXPORT_SYMBOL_GPL(blkdev_nr_zones); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 914c613d8..39017ae9d 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -681,9 +681,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