Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4720177ioa; Wed, 27 Apr 2022 09:37:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0r2IpE7Q2MT4W8DYMYGyTBJ4BNUODviYKBusYV8u6CHBLqnYu8eksDfLVfNIim6sZVRJO X-Received: by 2002:a17:90a:8418:b0:1d2:7c69:e3bf with SMTP id j24-20020a17090a841800b001d27c69e3bfmr44721555pjn.44.1651077425322; Wed, 27 Apr 2022 09:37:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651077425; cv=none; d=google.com; s=arc-20160816; b=GWzUFUNoOdSy0THTZw+bqgrZ1ZhufmTJ3wMRElGSdUttm7CG3zcTDCX6P2FPwS2Jni aNsrmCnm0vJgC1kg9RluqemAQ7zbC7Cc6HDHfuDhH3gOQ2EScR+OdIkOEEmaD70BwCwq aA1bOw10budjG5/jIUlGMiDu9gxS0BXivNZuFUJl7kJD6oTyZew7kmiip9E1trPxw50Z B7R9Lxj0hOTfbLlaOwVxZ5WEIAHhdBqWoPxTCF+FtN/tIsawCokbhBQclMGX/bpPkvIg 9DgzFlR9Ou/0zrkJx2mX4SEPYFQyaqlAPZCSXaR7YpJbMvzptlPLt0HvcCPluJfdygqS YQug== 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=kk01EsRG9bOHVzhx2cg7vI10rthuoQfVL8TCej8gbAs=; b=it9uv4OoT6ZJVWIaiDXHUaEfX3dlqP8w99RGXsxwU0GyIdRJnUhrZZp0w7bm1hFJ+R sxJDnxd+9a2/tqyaSYk+WzC9jYo5a26LtcSr30n/dQTtMV6hURwK/6mLlm1EFpDhprNr ZsS7XExWzz5Pl5p+WgmfaGLgj2gNQ4QWmNoloIijWw5Yt9zXKR+GcjfhFYNA21ckkg0P UM4onwMf+K1KxFsnPKJdJomTr27hMzfI6M3UriJ5X2K/kcvyQYzR8/LEmW/Xwig1TFrU 8IvY9akQGyo/zgXLW/Xd2ChHTHlA2NdSkj5+ulyTXXmXcap9/1QMiiZE5MwJvJdydnmi kR0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=FqFqteqG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i34-20020a635422000000b003ab9d94aaccsi1911884pgb.328.2022.04.27.09.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:37:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=FqFqteqG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 E899B3E24D7; Wed, 27 Apr 2022 09:06:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241806AbiD0QH2 (ORCPT + 99 others); Wed, 27 Apr 2022 12:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241425AbiD0QGx (ORCPT ); Wed, 27 Apr 2022 12:06:53 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E62D3CAAC9 for ; Wed, 27 Apr 2022 09:03:01 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220427160259euoutp014a464edf38733cb9e4a04d3882717038~pzE9Uypsd0745007450euoutp01R for ; Wed, 27 Apr 2022 16:02:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220427160259euoutp014a464edf38733cb9e4a04d3882717038~pzE9Uypsd0745007450euoutp01R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651075379; bh=kk01EsRG9bOHVzhx2cg7vI10rthuoQfVL8TCej8gbAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FqFqteqGXSEnxZPhnX9rym6n42YAt++KmTUYH1akFOm0A7L9YLhwHpvVJ5z+0TJl9 A71EFZm4I1wTNw7c+GIBonIM8041uzM6cxt8uvhd7XeS0ftGXi1kqVecDOT0q+lFCo xeb6kGclgglBpZfHmT9Vj1NgpQ/SIdZW/rLg5myE= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220427160257eucas1p248f9fb67b38f65e92cd401d8333f1f48~pzE7tOLRh2334023340eucas1p2g; Wed, 27 Apr 2022 16:02:57 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 40.0A.10260.13969626; Wed, 27 Apr 2022 17:02:57 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220427160257eucas1p21fb58d0129376a135fdf0b9c2fe88895~pzE7TkyRS2335223352eucas1p2Z; Wed, 27 Apr 2022 16:02:57 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220427160257eusmtrp29abf9fbaa39f05eb9b4bd28a52f41a07~pzE7Sr62r2598325983eusmtrp2c; Wed, 27 Apr 2022 16:02:57 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-7e-62696931489b Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 9B.71.09522.13969626; Wed, 27 Apr 2022 17:02:57 +0100 (BST) Received: from localhost (unknown [106.210.248.162]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220427160256eusmtip1cbd768be896ffc9fa5c108cd32dcf1a6~pzE67wefT0884308843eusmtip1h; Wed, 27 Apr 2022 16:02:56 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, axboe@kernel.dk, snitzer@kernel.org, hch@lst.de, mcgrof@kernel.org, naohiro.aota@wdc.com, sagi@grimberg.me, damien.lemoal@opensource.wdc.com, dsterba@suse.com, johannes.thumshirn@wdc.com Cc: linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, clm@fb.com, gost.dev@samsung.com, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, josef@toxicpanda.com, jonathan.derrick@linux.dev, agk@redhat.com, kbusch@kernel.org, kch@nvidia.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, bvanassche@acm.org, jiangbo.365@bytedance.com, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, linux-block@vger.kernel.org, Pankaj Raghav Subject: [PATCH 01/16] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Wed, 27 Apr 2022 18:02:40 +0200 Message-Id: <20220427160255.300418-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160255.300418-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAA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0MzA1NDEzNLA1NLMWEmc17OgI1FIID2xJDU7NbUgtQimj4mDU6qBidvFgLde KU2Y82fPlJdpbQYOeVKdrT8nT3Zp9Pj6z2de32p1k57g7xxG05c4HVkckRoT84zVlGX/068R 548EqHmt61bz5bh/wTjjCUfeQ4bqHexaC7W2bOSLuPV7i+rMeyH8OUptHw5s2bp94dn6fd48 xw08429uNq5fmZm7q8uq/KTxmvVfZy5uYXjf25yisU2u2EFIbncqy0K7WYa9j2bz3DRWNlwc /0XLevpHofcCOleeiO5kuMZeM2mD2aZzB1k4tN5POijOtaC4/L/gnT1nPbS5plTdKfk1cZv4 KyPNxzP+OphweMVyeCp8dXoVczXr7Lbu0mUBOSv/Oa3N3OHt8YV/9cX87Pf163yclFiKMxIN tZiLihMBAepjMLADAAA= X-CMS-MailID: 20220427160257eucas1p21fb58d0129376a135fdf0b9c2fe88895 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220427160257eucas1p21fb58d0129376a135fdf0b9c2fe88895 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220427160257eucas1p21fb58d0129376a135fdf0b9c2fe88895 References: <20220427160255.300418-1-p.raghav@samsung.com> X-Spam-Status: No, score=-2.5 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 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 Signed-off-by: Pankaj Raghav --- block/blk-zoned.c | 8 +++++++- include/linux/blkdev.h | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 38cd840d8838..1dff4a8bd51d 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -117,10 +117,16 @@ EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); 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