Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4720422ioa; Wed, 27 Apr 2022 09:37:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeR1Y/uS+YPeQ1/s1T52+WBLgkRJwfx0CUNB/zzXSIKd9d4DTuARE+ODonC8+NDM0mMm88 X-Received: by 2002:a17:90a:398c:b0:1d9:5e2b:b043 with SMTP id z12-20020a17090a398c00b001d95e2bb043mr20886454pjb.101.1651077445631; Wed, 27 Apr 2022 09:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651077445; cv=none; d=google.com; s=arc-20160816; b=hzRJy3pRTmXJ4u00r5ie3YeDqAo72b31os2u+BB50hKxJQ6wbzl82yTNanXNemh0XP iXoekgkOuVq3sV09eVRF2foTyVJgoN/FbhuVN98T1xUW5qrDddde8BVsWZJ4Ooa75LK5 zfn1wgQ6Ei2pi5/eSb+Q/CyXHjVMv8eJDA/jx5UeQafyYp1K0hUTlKWn0dOXEw3SUhou H+Qd/yJELJHQ+H2cTMA+sThLer7bV7OASmpJxI0ZVpDJgIz3p7EyHK0IFHSWvV0M91z3 yV6p/9NCoxs58GcjsNvbOPmC+oBaXXK4ZTBFfSZAdU42zWPeYoHQqar9UUBH1CHFQ/gS Lwgg== 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=RJVMrlQpvMBXokOVGO8QBkDOO+u9KZOAxDi7xzIPKXQ=; b=0IH4Z6oh+i6h69Ha6tLVOE3lC/TfAkjdHJd6fLSXDY3UusF3mi/yuXaraMxYj7b+eD f+3mlbt+eCfaUMeQbqxUBYmu3kAwtzeC4QULG834DwiG2hCbS/PZjpSSQO9SIeWhkCiP eWMfO1S/WOjF7fGFVbua3M20hvthhFYmDfWLpGH4PWxoZnelWxJlBAuH+i/rDqkdPxW6 +5V8D/HzUsXEbITh47tUx9hNupP9nVVLfupiqscaXfleo0VqhHSqKtLQuRG5wRJHcg8X sqZAQkDuMAU1OOBM9lNPWwAM/HuY/68qhMaHsIRJQXV49xnJL3PQDnO3u8EnLxqXH13L 79Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="Hm/DOeyC"; 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 qe7-20020a17090b4f8700b001cba3085ef9si6301750pjb.27.2022.04.27.09.37.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:37:25 -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="Hm/DOeyC"; 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 B6B444A18CC; Wed, 27 Apr 2022 09:07:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241977AbiD0QID (ORCPT + 99 others); Wed, 27 Apr 2022 12:08:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241641AbiD0QGy (ORCPT ); Wed, 27 Apr 2022 12:06:54 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16F1F3CD5B9 for ; Wed, 27 Apr 2022 09:03:06 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220427160300euoutp01570f632de1d2f0164055e49231e58137~pzE_X6tC-0745607456euoutp01Q for ; Wed, 27 Apr 2022 16:03:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220427160300euoutp01570f632de1d2f0164055e49231e58137~pzE_X6tC-0745607456euoutp01Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651075380; bh=RJVMrlQpvMBXokOVGO8QBkDOO+u9KZOAxDi7xzIPKXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hm/DOeyCcaKdDk9xu6hdF6129Z33BVsqljAvLdYQOq4TXbF86UxKVp4//UAYM1JWb ZMLN0ZHtnzpC3du0x1jTRHI9nhHOp8VFEjt2LCcBy6Sl7f4scRPldoQnFGcsaXOY+J 6eYqmxgN6KDAf93zrKzPXCr/9iFVZ2HYmQ1+OJM8= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220427160258eucas1p252cb6872c7cc20eea327c199f8e2aec9~pzE8vLb-p1589415894eucas1p2E; Wed, 27 Apr 2022 16:02:58 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id C2.0A.10260.23969626; Wed, 27 Apr 2022 17:02:58 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220427160258eucas1p19548a7094f67b4c9f340add776f60082~pzE8W8LWT0330603306eucas1p1Q; Wed, 27 Apr 2022 16:02:58 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220427160258eusmtrp2f76aadf93653911fc7f556ba6f0a2efb~pzE8ULUY32598325983eusmtrp2d; Wed, 27 Apr 2022 16:02:58 +0000 (GMT) X-AuditID: cbfec7f5-bf3ff70000002814-81-6269693261bd Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 7D.71.09522.23969626; Wed, 27 Apr 2022 17:02:58 +0100 (BST) Received: from localhost (unknown [106.210.248.162]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220427160258eusmtip2b1f69ceee95e1cec081198bf82161f87~pzE79CnAQ2569125691eusmtip2E; Wed, 27 Apr 2022 16:02:58 +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 02/16] block: add blk_queue_zone_aligned and bdev_zone_aligned helper Date: Wed, 27 Apr 2022 18:02:41 +0200 Message-Id: <20220427160255.300418-3-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: H4sIAA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BQSSE8sSc1OTS1ILYLpY+LglGpgOlYt+uyP 4MbKiz+3vmr4/3fGp3QrZr5382afuudfWSes+vTWB1udzvjH7B7xZldmL8nd8vXH6t3bpkzk jOJZy6q6b85K4R3Z6y3MYgzN7s3U8P36YoXTl9ftK/V3bEqZHNiVfDThzzHJKKmZ1Sbek9Yu XRu3wH9d0IfkyN40szSRDvdpXO6XWZOSDB1WxutY72yt6W2cckMh53nK7lwL14RZ07NFvIK8 vgfXXWRak3djU/u3XzHd92x3Ft6/eFryj13xUm3hPcv+b35cr8MdvWf/C5u5IRu47kS3Bt04 s6bPutrs8zTerU/r74v0/5qlbj3ppecVi6aYLXWfRTyVtPcf4vPZVsmwQ2DTJCcRVyWW4oxE Qy3mouJEAGOYaxeyAwAA X-CMS-MailID: 20220427160258eucas1p19548a7094f67b4c9f340add776f60082 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220427160258eucas1p19548a7094f67b4c9f340add776f60082 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220427160258eucas1p19548a7094f67b4c9f340add776f60082 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 Checking if a given sector is aligned to a zone is a very common operation that is performed for zoned devices. Add blk_queue_zone_aligned helper to check for this instead of opencoding it everywhere. The helper is made to be generic so that it can also check for alignment for non non-power-of-2 zone size devices. As the existing deployments of zoned devices had power-of-2 assumption, power-of-2 optimized calculation is done for devices with power-of-2 zone size Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- include/linux/blkdev.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index c4e4c7071b7b..f8f2d2998afb 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -676,6 +676,22 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, return div64_u64(sector, zone_sectors); } +static inline bool blk_queue_zone_aligned(struct request_queue *q, sector_t sec) +{ + sector_t zone_sectors = blk_queue_zone_sectors(q); + u64 remainder = 0; + + if (!blk_queue_is_zoned(q)) + return false; + + if (is_power_of_2(zone_sectors)) + return IS_ALIGNED(sec, zone_sectors); + + div64_u64_rem(sec, zone_sectors, &remainder); + /* if there is a remainder, then the sector is not aligned */ + return remainder == 0; +} + static inline bool blk_queue_zone_is_seq(struct request_queue *q, sector_t sector) { @@ -722,6 +738,12 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, { return 0; } + +static inline bool blk_queue_zone_aligned(struct request_queue *q, sector_t sec) +{ + return false; +} + static inline unsigned int queue_max_open_zones(const struct request_queue *q) { return 0; @@ -1361,6 +1383,15 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev) return 0; } +static inline bool bdev_zone_aligned(struct block_device *bdev, sector_t sec) +{ + struct request_queue *q = bdev_get_queue(bdev); + + if (q) + return blk_queue_zone_aligned(q, sec); + return false; +} + static inline unsigned int bdev_max_open_zones(struct block_device *bdev) { struct request_queue *q = bdev_get_queue(bdev); -- 2.25.1