From patchwork Thu May 5 13:47:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12839624 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CF10C433F5 for ; Thu, 5 May 2022 13:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349312AbiEENyy (ORCPT ); Thu, 5 May 2022 09:54:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380158AbiEENyt (ORCPT ); Thu, 5 May 2022 09:54:49 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2167257154 for ; Thu, 5 May 2022 06:51:08 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220505135106euoutp0293ae4cc5a844621ec56cfbd805652267~sOcGV5_s92896128961euoutp02g for ; Thu, 5 May 2022 13:51:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220505135106euoutp0293ae4cc5a844621ec56cfbd805652267~sOcGV5_s92896128961euoutp02g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651758666; bh=U9RzqUijJL5PmqUeIybgHDju5FpS85GPewMJfUjtd+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iPWKeMJIpkJOy0x1P/dHwOmblPG0gu4RALHmksy8KWJiUQKERa2jZr8De2iG9PaUX 2Y4BC+MztqPmwrd+NJX7pBw0Zw+G7hOcM5LLNTyy+nUZRLreB4B9FkD86i4TyWu480 SF9ecUMc/bX2PZNjm3LWvjK9Lv5zDqmDLBRBxn5w= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220505135104eucas1p1f7413241441378ad3d8a2fcbfb72bd5d~sOcEh4oMU0188401884eucas1p1X; Thu, 5 May 2022 13:51:04 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 19.FC.10009.846D3726; Thu, 5 May 2022 14:51:04 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220505135104eucas1p1bed3e1e47255518296b4cb15ec0c042b~sOcD8lxBw1068810688eucas1p1D; Thu, 5 May 2022 13:51:04 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220505135104eusmtrp1758e1912f2f38f38511d760a6d5554ac~sOcD7cTl01310613106eusmtrp1O; Thu, 5 May 2022 13:51:04 +0000 (GMT) X-AuditID: cbfec7f2-e95ff70000002719-37-6273d6484bb4 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 84.6A.09404.846D3726; Thu, 5 May 2022 14:51:04 +0100 (BST) Received: from localhost (unknown [106.210.248.170]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220505135103eusmtip1f8faf002ab4e89d5bdd4994a68da949b~sOcDjxkyl0093500935eusmtip1H; Thu, 5 May 2022 13:51:03 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, dsterba@suse.com, jaegeuk@kernel.org, bvanassche@acm.org, hare@suse.de Cc: jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, matias.bjorling@wdc.com, gost.dev@samsung.com, pankydev8@gmail.com, Pankaj Raghav , Luis Chamberlain , Chris Mason , Josef Bacik , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/11] btrfs: zoned: Cache superblock location in btrfs_zoned_device_info Date: Thu, 5 May 2022 15:47:05 +0200 Message-Id: <20220505134710.132630-6-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505134710.132630-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SfUxTZxTGfe+9vbdtqFxaEl5xbqMLJrgBEvfxjk7ncH/cxMRtMVnGyGBF b4BZSm2tOnCjjAJSCNSiTrrK2Ijho12KgIayZTTEKisirp0MxmjtBEQo+IENMpTNclnmf79z zvO8zznJy8fFIV4sP095iFUr5QopKSQuXl4aSmSGNdlb+z0IWcdrSXT63hKOTLVnKLQ8OISj 649KMDTqdGDop+9NGGq1ujA0YTfjqNp5j0Ct+gCOHgdSkOdWC4W8PRYSGctDOBoxTgK0cE5P IdvoJLFTzHh/282s9NtI5kTpPMU4zOMU4x3UMh1tlSTzne4Uzvw4qiMZR5mfx9R0tQHG3nWD YDoHihhj53kes9DxPFPhrMLej/xY+NZ+VpF3mFUn7/hUmPvIN0SonDFH7fMGUgeaJAYg4EP6 VTgVdJMGIOSL6RYAl275MK54CGCTq4viigUAG9zXgQHwVy2Lpte4fjOAM1VNvPBTYvoOgHWW 3LCGpLfAkspVbzRdBeBgaZAIFzjtxmDJjWUsbJDQmXC2/T4ZZoKOh1PdvtW+iE6Flxr0gNvv BVjvWaTCLKBl0FIZ4HGaKPhL/QQRZvyppvTCN3g4ANLDArjw2I9x5nehP/Q3j2MJnLnSRXH8 HByoqyY4LoKTI8trZj2AtQ47yZ0pgzVXFWHE6QRo70nm5O/AwK8VFKdYD0fmorgV1kPTxa9x ri2Cx8vFnFoKHUsTa6EQer+yrIUy8KytmzKCOPMzx5ifOcb8f24jwNtADKvV5OewmhQleyRJ I8/XaJU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uTM JywgNjNQffPW2cwTGAVmIUnNQpJawMi0ilEktbQ4Nz232EivODG3uDQvXS85P3cTIzC+tx37 uWUH48pXH/UOMTJxMB5ilOBgVhLhdV5akCTEm5JYWZValB9fVJqTWnyI0RTo7onMUqLJ+cAE k1cSb2hmYGpoYmZpYGppZqwkzutZ0JEoJJCeWJKanZpakFoE08fEwSnVwFSZWqW8un+6uf/m 7zvT2ri/vsq4tHHVtbt+n3PnCJiUGn1ZG/Zs3s6iv0dU9+9JMPJU7RB1yJn7wDt/JZ+dzGZn 87N79v5J1HV9fFxS5QpT8Yf1x7Ttnhj6cB/W32/8drKhiXHn75SIXRa5D6Mmsbx9q9Z4Nqne vs6pVtxTfjfHnSAD9aO63CGsnX9Fz6Yk6d3xbVqbMPtFinCtnJXS3Vetj3l3aa09sq6meHL8 NJ0qiUAzibyr73ua+Arfbtzmc+78f/FHSw41Zh66+maa47oDvQc+zRU5uXjaHtPKCa2ztvFn Lk05titzc5Jx2fefCzWOLdP7J3fg6sRVfO0cG0NP7VpXusDlV1jBoatHvScpsRRnJBpqMRcV JwIA3qSA/ngDAAA= X-CMS-MailID: 20220505135104eucas1p1bed3e1e47255518296b4cb15ec0c042b X-Msg-Generator: CA X-RootMTR: 20220505135104eucas1p1bed3e1e47255518296b4cb15ec0c042b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220505135104eucas1p1bed3e1e47255518296b4cb15ec0c042b References: <20220505134710.132630-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Instead of calculating the superblock location every time, cache the superblock zone location in btrfs_zoned_device_info struct and use it to locate the zone index. The functions such as btrfs_sb_log_location_bdev() and btrfs_reset_sb_log_zones() which work directly on block_device shall continue to use the sb_zone_number because btrfs_zoned_device_info struct might not have been initialized at that point. This patch will enable non power-of-2 zoned devices to not perform division to lookup superblock and its mirror location. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 13 +++++++++---- fs/btrfs/zoned.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 06f22c021..e8c7cebb2 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -511,6 +511,11 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) max_active_zones - nactive); } + /* Cache the sb zone number */ + for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; ++i) { + zone_info->sb_zone_location[i] = + sb_zone_number(zone_info->zone_size_shift, i); + } /* Validate superblock log */ nr_zones = BTRFS_NR_SB_LOG_ZONES; for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { @@ -518,7 +523,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) u64 sb_wp; int sb_pos = BTRFS_NR_SB_LOG_ZONES * i; - sb_zone = sb_zone_number(zone_info->zone_size_shift, i); + sb_zone = zone_info->sb_zone_location[i]; if (sb_zone + 1 >= zone_info->nr_zones) continue; @@ -866,7 +871,7 @@ int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw, return 0; } - zone_num = sb_zone_number(zinfo->zone_size_shift, mirror); + zone_num = zinfo->sb_zone_location[mirror]; if (zone_num + 1 >= zinfo->nr_zones) return -ENOENT; @@ -883,7 +888,7 @@ static inline bool is_sb_log_zone(struct btrfs_zoned_device_info *zinfo, if (!zinfo) return false; - zone_num = sb_zone_number(zinfo->zone_size_shift, mirror); + zone_num = zinfo->sb_zone_location[mirror]; if (zone_num + 1 >= zinfo->nr_zones) return false; @@ -1011,7 +1016,7 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, u32 sb_zone; u64 sb_pos; - sb_zone = sb_zone_number(shift, i); + sb_zone = zinfo->sb_zone_location[i]; if (!(end <= sb_zone || sb_zone + BTRFS_NR_SB_LOG_ZONES <= begin)) { have_sb = true; diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 10f31d1c8..694ab6d1e 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -27,6 +27,7 @@ struct btrfs_zoned_device_info { unsigned long *active_zones; struct blk_zone *zone_cache; struct blk_zone sb_zones[2 * BTRFS_SUPER_MIRROR_MAX]; + u32 sb_zone_location[BTRFS_SUPER_MIRROR_MAX]; }; #ifdef CONFIG_BLK_DEV_ZONED From patchwork Thu May 5 13:47:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12839623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B328C433FE for ; Thu, 5 May 2022 13:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380210AbiEENyw (ORCPT ); Thu, 5 May 2022 09:54:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380165AbiEENyt (ORCPT ); Thu, 5 May 2022 09:54:49 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66E7D57178 for ; Thu, 5 May 2022 06:51:09 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220505135108euoutp011cf5908467b201799f81329332622c6b~sOcHdyQP43116431164euoutp01u for ; Thu, 5 May 2022 13:51:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220505135108euoutp011cf5908467b201799f81329332622c6b~sOcHdyQP43116431164euoutp01u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651758668; bh=LMzILViEYGl7DXa37dpeTA+tqVrqwK5EcVpc6Ix2yY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CPGQ9j92/rr1enTM8W51HIe+iuZEr6A+pmjVyB7wTM9oQYKbiJDfLBmKJxgvr+u5d npf6DVf6mvZCT4debamywIdobwudx1L2C+Xeuk3k+NeDyd9YRWyd/NB7gcT9i76zY2 PfUIAswbVhwRgza41F2Utlnk2O9/yPWlY5G3pKFM= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220505135105eucas1p1875318bd43e3622035711a71d689236f~sOcFcxcL70606606066eucas1p1W; Thu, 5 May 2022 13:51:05 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 60.BC.09887.946D3726; Thu, 5 May 2022 14:51:05 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220505135105eucas1p1428258bde56a77a96d98509a2c0d5fe9~sOcFECa1e1070010700eucas1p1C; Thu, 5 May 2022 13:51:05 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220505135105eusmtrp19dbb21ab3bd151eb0520eaf17fcf130f~sOcFDNRxd1365913659eusmtrp1B; Thu, 5 May 2022 13:51:05 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-f7-6273d649daa6 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id A6.6A.09404.946D3726; Thu, 5 May 2022 14:51:05 +0100 (BST) Received: from localhost (unknown [106.210.248.170]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220505135105eusmtip1f64a5a3601c119d85d57b328e28ec824~sOcEvSwAx2664626646eusmtip1f; Thu, 5 May 2022 13:51:05 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, dsterba@suse.com, jaegeuk@kernel.org, bvanassche@acm.org, hare@suse.de Cc: jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, matias.bjorling@wdc.com, gost.dev@samsung.com, pankydev8@gmail.com, Pankaj Raghav , Luis Chamberlain , Chris Mason , Josef Bacik , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/11] btrfs: zoned: Make sb_zone_number function non power of 2 compatible Date: Thu, 5 May 2022 15:47:06 +0200 Message-Id: <20220505134710.132630-7-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505134710.132630-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCKsWRmVeSWpSXmKPExsWy7djP87qe14qTDJ4fM7dYfbefzWLah5/M FpP6Z7Bb/D57ntniwo9GJoubB3YyWexZNInJYuXqo0wWT9bPYrboOfCBxWJly0Nmiz8PDS0u PV7BbnF51xw2iwltX5ktbkx4ymjxeWkLu8Wam09ZHIQ8Ll/x9vh3Yg2bx8Tmd+weO2fdZfe4 fLbUY9OqTjaPhQ1TmT1232xg89jZep/Vo2/LKkaP9VuusnhsPl3tMWHzRlaPz5vkPNoPdDMF 8Edx2aSk5mSWpRbp2yVwZbz7vZWx4JBkxda7NxkbGD+JdDFyckgImEj83tfI0sXIxSEksIJR YvqRqWwQzhdGiQn3GpggnM+MEh+edDHBtDy9dgSqajmjxNOpB6D6XzJKrJ42C8jh4GAT0JJo 7GQHiYsIdDNKnG1+A1bELHCKSaLx6m8mkCJhgQSJaauFQKayCKhKXPn5ghEkzCtgJXH4UDzE MnmJmZe+s4PYnALWEnM6H7KC2LwCghInZz5hAbGZgWqat85mBhkvIXCNU+Ldw43sEM0uEpOX PoSyhSVeHd8CZctInJ7cwwJhV0s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hIStxc2MULYwhJ/ rnVBFT1nlNj17w9rFyMHB5uAlkRjJztIXERgKqPEhe0XWEAcZoFrTBIND3exgXQLC8RJNNzc BjaJRUBV4srPF4wgzbwCVhKHD8VDLJCXmHnpOzuIzSlgLTGn8yEriC0EVDLx4TuwMbwCghIn Zz5hAbGZgeqbt85mnsAoMAtJahaS1AJGplWMIqmlxbnpucVGesWJucWleel6yfm5mxiB8b3t 2M8tOxhXvvqod4iRiYPxEKMEB7OSCK/z0oIkId6UxMqq1KL8+KLSnNTiQ4ymQGdPZJYSTc4H Jpi8knhDMwNTQxMzSwNTSzNjJXFez4KORCGB9MSS1OzU1ILUIpg+Jg5OqQYmtTSvPQapMTFZ a80L1q2q63sTy3/SKfwQz5kn218+eL/j6X6ur7vurVx5SHnxfWsu8ykuJy9v2cp05+GUwu2c AS8+rU58sOBBivjKTK6e7zkW3ws+thX3KrCHBd9Pn+HGP+lwaYjex9zwKa9uuk4tXZBWdGBv 764k1fncNwRfs11RnL+bX3LN1/OlqpVL+AKfr+ry6ChJ7WxpKhFesnTHs+lxyzL9wloETGK9 Rc+bmj05v7omvWdL2WzfU9OXJSyZqKe4S1Pxc4XaJJbw46/XbQycxPmU+XjZz2USrJEs/80+ MtRYSaY4+58QVjT2Wq3RKR5/x7nxi6fcqUjnzQl+Xh4rn+SriIUZHciILyhUYinOSDTUYi4q TgQAF6KNiXgDAAA= X-CMS-MailID: 20220505135105eucas1p1428258bde56a77a96d98509a2c0d5fe9 X-Msg-Generator: CA X-RootMTR: 20220505135105eucas1p1428258bde56a77a96d98509a2c0d5fe9 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220505135105eucas1p1428258bde56a77a96d98509a2c0d5fe9 References: <20220505134710.132630-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Make the calculation in sb_zone_number function to be generic and work for both power-of-2 and non power-of-2 zone sizes. The function signature has been modified to take block device and mirror as input as this function is only invoked from callers that have access to the block device. This enables to use the generic bdev_zone_no function provided by the block layer to calculate the zone number. Even though division is used to calculate the zone index for non power-of-2 zone sizes, this function will not be used in the fast path as the sb_zone_location cache is used for the superblock zone location. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index e8c7cebb2..5be2ef7bb 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -34,9 +34,6 @@ #define BTRFS_SB_LOG_FIRST_OFFSET (512ULL * SZ_1G) #define BTRFS_SB_LOG_SECOND_OFFSET (4096ULL * SZ_1G) -#define BTRFS_SB_LOG_FIRST_SHIFT const_ilog2(BTRFS_SB_LOG_FIRST_OFFSET) -#define BTRFS_SB_LOG_SECOND_SHIFT const_ilog2(BTRFS_SB_LOG_SECOND_OFFSET) - /* Number of superblock log zones */ #define BTRFS_NR_SB_LOG_ZONES 2 @@ -153,15 +150,23 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones, /* * Get the first zone number of the superblock mirror */ -static inline u32 sb_zone_number(int shift, int mirror) +static inline u32 sb_zone_number(struct block_device *bdev, int mirror) { u64 zone; ASSERT(mirror < BTRFS_SUPER_MIRROR_MAX); switch (mirror) { - case 0: zone = 0; break; - case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break; - case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break; + case 0: + zone = 0; + break; + case 1: + zone = bdev_zone_no(bdev, + BTRFS_SB_LOG_FIRST_OFFSET >> SECTOR_SHIFT); + break; + case 2: + zone = bdev_zone_no(bdev, + BTRFS_SB_LOG_SECOND_OFFSET >> SECTOR_SHIFT); + break; } ASSERT(zone <= U32_MAX); @@ -514,7 +519,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) /* Cache the sb zone number */ for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; ++i) { zone_info->sb_zone_location[i] = - sb_zone_number(zone_info->zone_size_shift, i); + sb_zone_number(bdev, i); } /* Validate superblock log */ nr_zones = BTRFS_NR_SB_LOG_ZONES; @@ -839,7 +844,7 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, nr_sectors = bdev_nr_sectors(bdev); nr_zones = nr_sectors >> zone_sectors_shift; - sb_zone = sb_zone_number(zone_sectors_shift + SECTOR_SHIFT, mirror); + sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) return -ENOENT; @@ -963,7 +968,7 @@ int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) nr_sectors = bdev_nr_sectors(bdev); nr_zones = nr_sectors >> zone_sectors_shift; - sb_zone = sb_zone_number(zone_sectors_shift + SECTOR_SHIFT, mirror); + sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) return -ENOENT; From patchwork Thu May 5 13:47:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12839625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D00D8C433EF for ; Thu, 5 May 2022 13:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380253AbiEENy4 (ORCPT ); Thu, 5 May 2022 09:54:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380182AbiEENyu (ORCPT ); Thu, 5 May 2022 09:54:50 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67EA657985 for ; Thu, 5 May 2022 06:51:10 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220505135109euoutp015383ea2dc583515a5509f81347842c80~sOcIhHCeW3220632206euoutp01J for ; Thu, 5 May 2022 13:51:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220505135109euoutp015383ea2dc583515a5509f81347842c80~sOcIhHCeW3220632206euoutp01J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651758669; bh=v9pKtSXVKfv3MO12A+XlAy96VR3If9OGCSyPe0WYtqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RTLI9ywN5NK5K0nO9CNdvIey2bElJMp/ujotMBFrAERIxDUR0Cfh+OcfvFTna4t1d U2Z0DYbRYbb66uWUX+uJg8IOpGioEQjaoSJTOgFDvtNTkcA8fBdCHJPEMbXHsGS4Ih 2+aBKMrUZzYqsD5KVqCblLJ4oZs84Wh3gW8SDuVo= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220505135107eucas1p1ff219a88a746cd60a19d7b0923f1c1fc~sOcG1xhY51069210692eucas1p1P; Thu, 5 May 2022 13:51:07 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 3D.72.10260.B46D3726; Thu, 5 May 2022 14:51:07 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220505135106eucas1p18d4d0bc1e5fb02375229b05b6dbdf92c~sOcGRtLtN0606206062eucas1p1J; Thu, 5 May 2022 13:51:06 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220505135106eusmtrp26370c76666ef9a33d416da1074037004~sOcGQ7dLv2658826588eusmtrp2H; Thu, 5 May 2022 13:51:06 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-bc-6273d64b2933 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 51.03.09522.A46D3726; Thu, 5 May 2022 14:51:06 +0100 (BST) Received: from localhost (unknown [106.210.248.170]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220505135106eusmtip2a91a9e33132b14e2af13f82ceeba777c~sOcF8YZ770094000940eusmtip2M; Thu, 5 May 2022 13:51:06 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, dsterba@suse.com, jaegeuk@kernel.org, bvanassche@acm.org, hare@suse.de Cc: jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, matias.bjorling@wdc.com, gost.dev@samsung.com, pankydev8@gmail.com, Pankaj Raghav , Luis Chamberlain , Chris Mason , Josef Bacik , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/11] btrfs: zoned: use generic btrfs zone helpers to support npo2 zoned devices Date: Thu, 5 May 2022 15:47:07 +0200 Message-Id: <20220505134710.132630-8-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505134710.132630-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOKsWRmVeSWpSXmKPExsWy7djP87re14qTDHbcF7NYfbefzWLah5/M FpP6Z7Bb/D57ntniwo9GJoubB3YyWexZNInJYuXqo0wWT9bPYrboOfCBxWJly0Nmiz8PDS0u PV7BbnF51xw2iwltX5ktbkx4ymjxeWkLu8Wam09ZHIQ8Ll/x9vh3Yg2bx8Tmd+weO2fdZfe4 fLbUY9OqTjaPhQ1TmT1232xg89jZep/Vo2/LKkaP9VuusnhsPl3tMWHzRlaPz5vkPNoPdD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JE AJVfVdZ4AwAA X-CMS-MailID: 20220505135106eucas1p18d4d0bc1e5fb02375229b05b6dbdf92c X-Msg-Generator: CA X-RootMTR: 20220505135106eucas1p18d4d0bc1e5fb02375229b05b6dbdf92c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220505135106eucas1p18d4d0bc1e5fb02375229b05b6dbdf92c References: <20220505134710.132630-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add helpers to calculate alignment, round up and round down for zoned devices. These helpers encapsulates the necessary handling for power_of_2 and non-power_of_2 zone sizes. Optimized calculations are performed for zone sizes that are power_of_2 with log and shifts. btrfs_zoned_is_aligned() is added instead of reusing bdev_zone_aligned() helper due to some use cases in btrfs where zone alignment is checked before having access to the underlying block device such as in this function: btrfs_load_block_group_zone_info(). Use the generic btrfs zone helpers to calculate zone index, check zone alignment, round up and round down operations. The zone_size_shift field is not needed anymore as generic helpers are used for calculation. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/volumes.c | 24 +++++++++------- fs/btrfs/zoned.c | 72 ++++++++++++++++++++++------------------------ fs/btrfs/zoned.h | 43 +++++++++++++++++++++++---- 3 files changed, 85 insertions(+), 54 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 94f851592..3d6b9a25a 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1408,7 +1408,7 @@ static u64 dev_extent_search_start(struct btrfs_device *device, u64 start) * allocator, because we anyway use/reserve the first two zones * for superblock logging. */ - return ALIGN(start, device->zone_info->zone_size); + return btrfs_zoned_roundup(start, device->zone_info->zone_size); default: BUG(); } @@ -1423,7 +1423,7 @@ static bool dev_extent_hole_check_zoned(struct btrfs_device *device, int ret; bool changed = false; - ASSERT(IS_ALIGNED(*hole_start, zone_size)); + ASSERT(btrfs_zoned_is_aligned(*hole_start, zone_size)); while (*hole_size > 0) { pos = btrfs_find_allocatable_zones(device, *hole_start, @@ -1560,7 +1560,7 @@ static int find_free_dev_extent_start(struct btrfs_device *device, search_start = dev_extent_search_start(device, search_start); WARN_ON(device->zone_info && - !IS_ALIGNED(num_bytes, device->zone_info->zone_size)); + !btrfs_zoned_is_aligned(num_bytes, device->zone_info->zone_size)); path = btrfs_alloc_path(); if (!path) @@ -5111,8 +5111,8 @@ static void init_alloc_chunk_ctl_policy_zoned( ctl->max_stripe_size = zone_size; if (type & BTRFS_BLOCK_GROUP_DATA) { - ctl->max_chunk_size = round_down(BTRFS_MAX_DATA_CHUNK_SIZE, - zone_size); + ctl->max_chunk_size = btrfs_zoned_rounddown( + BTRFS_MAX_DATA_CHUNK_SIZE, zone_size); } else if (type & BTRFS_BLOCK_GROUP_METADATA) { ctl->max_chunk_size = ctl->max_stripe_size; } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) { @@ -5124,9 +5124,10 @@ static void init_alloc_chunk_ctl_policy_zoned( } /* We don't want a chunk larger than 10% of writable space */ - limit = max(round_down(div_factor(fs_devices->total_rw_bytes, 1), - zone_size), - min_chunk_size); + limit = max( + btrfs_zoned_rounddown(div_factor(fs_devices->total_rw_bytes, 1), + zone_size), + min_chunk_size); ctl->max_chunk_size = min(limit, ctl->max_chunk_size); ctl->dev_extent_min = zone_size * ctl->dev_stripes; } @@ -6729,7 +6730,8 @@ static void submit_stripe_bio(struct btrfs_io_context *bioc, */ if (bio_op(bio) == REQ_OP_ZONE_APPEND) { if (btrfs_dev_is_sequential(dev, physical)) { - u64 zone_start = round_down(physical, fs_info->zone_size); + u64 zone_start = btrfs_zoned_rounddown(physical, + fs_info->zone_size); bio->bi_iter.bi_sector = zone_start >> SECTOR_SHIFT; } else { @@ -8051,8 +8053,8 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info, if (dev->zone_info) { u64 zone_size = dev->zone_info->zone_size; - if (!IS_ALIGNED(physical_offset, zone_size) || - !IS_ALIGNED(physical_len, zone_size)) { + if (!btrfs_zoned_is_aligned(physical_offset, zone_size) || + !btrfs_zoned_is_aligned(physical_len, zone_size)) { btrfs_err(fs_info, "zoned: dev extent devid %llu physical offset %llu len %llu is not aligned to device zone", devid, physical_offset, physical_len); diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 5be2ef7bb..3023c871e 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -177,13 +177,13 @@ static inline u32 sb_zone_number(struct block_device *bdev, int mirror) static inline sector_t zone_start_sector(u32 zone_number, struct block_device *bdev) { - return (sector_t)zone_number << ilog2(bdev_zone_sectors(bdev)); + return zone_number * bdev_zone_sectors(bdev); } static inline u64 zone_start_physical(u32 zone_number, struct btrfs_zoned_device_info *zone_info) { - return (u64)zone_number << zone_info->zone_size_shift; + return zone_number * zone_info->zone_size; } /* @@ -236,8 +236,8 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos, if (zinfo->zone_cache) { unsigned int i; - ASSERT(IS_ALIGNED(pos, zinfo->zone_size)); - zno = pos >> zinfo->zone_size_shift; + ASSERT(btrfs_zoned_is_aligned(pos, zinfo->zone_size)); + zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); /* * We cannot report zones beyond the zone end. So, it is OK to * cap *nr_zones to at the end. @@ -409,9 +409,8 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) } nr_sectors = bdev_nr_sectors(bdev); - zone_info->zone_size_shift = ilog2(zone_info->zone_size); - zone_info->nr_zones = nr_sectors >> ilog2(zone_sectors); - if (!IS_ALIGNED(nr_sectors, zone_sectors)) + zone_info->nr_zones = bdev_zone_no(bdev, nr_sectors); + if (!btrfs_zoned_is_aligned(nr_sectors, zone_sectors)) zone_info->nr_zones++; max_active_zones = bdev_max_active_zones(bdev); @@ -823,10 +822,8 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, u64 *bytenr_ret) { struct blk_zone zones[BTRFS_NR_SB_LOG_ZONES]; - sector_t zone_sectors; u32 sb_zone; int ret; - u8 zone_sectors_shift; sector_t nr_sectors; u32 nr_zones; @@ -837,12 +834,10 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, ASSERT(rw == READ || rw == WRITE); - zone_sectors = bdev_zone_sectors(bdev); - if (!is_power_of_2(zone_sectors)) + if (!is_power_of_2(bdev_zone_sectors(bdev))) return -EINVAL; - zone_sectors_shift = ilog2(zone_sectors); nr_sectors = bdev_nr_sectors(bdev); - nr_zones = nr_sectors >> zone_sectors_shift; + nr_zones = bdev_zone_no(bdev, nr_sectors); sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) @@ -959,14 +954,12 @@ int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) { sector_t zone_sectors; sector_t nr_sectors; - u8 zone_sectors_shift; u32 sb_zone; u32 nr_zones; zone_sectors = bdev_zone_sectors(bdev); - zone_sectors_shift = ilog2(zone_sectors); nr_sectors = bdev_nr_sectors(bdev); - nr_zones = nr_sectors >> zone_sectors_shift; + nr_zones = bdev_zone_no(bdev, nr_sectors); sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) @@ -992,18 +985,17 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, u64 hole_end, u64 num_bytes) { struct btrfs_zoned_device_info *zinfo = device->zone_info; - const u8 shift = zinfo->zone_size_shift; - u64 nzones = num_bytes >> shift; + u64 nzones = bdev_zone_no(device->bdev, num_bytes >> SECTOR_SHIFT); u64 pos = hole_start; u64 begin, end; bool have_sb; int i; - ASSERT(IS_ALIGNED(hole_start, zinfo->zone_size)); - ASSERT(IS_ALIGNED(num_bytes, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(hole_start, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(num_bytes, zinfo->zone_size)); while (pos < hole_end) { - begin = pos >> shift; + begin = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); end = begin + nzones; if (end > zinfo->nr_zones) @@ -1035,8 +1027,9 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, if (!(pos + num_bytes <= sb_pos || sb_pos + BTRFS_SUPER_INFO_SIZE <= pos)) { have_sb = true; - pos = ALIGN(sb_pos + BTRFS_SUPER_INFO_SIZE, - zinfo->zone_size); + pos = btrfs_zoned_roundup( + sb_pos + BTRFS_SUPER_INFO_SIZE, + zinfo->zone_size); break; } } @@ -1050,7 +1043,7 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos) { struct btrfs_zoned_device_info *zone_info = device->zone_info; - unsigned int zno = (pos >> zone_info->zone_size_shift); + unsigned int zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); /* We can use any number of zones */ if (zone_info->max_active_zones == 0) @@ -1072,7 +1065,7 @@ static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos) static void btrfs_dev_clear_active_zone(struct btrfs_device *device, u64 pos) { struct btrfs_zoned_device_info *zone_info = device->zone_info; - unsigned int zno = (pos >> zone_info->zone_size_shift); + unsigned int zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); /* We can use any number of zones */ if (zone_info->max_active_zones == 0) @@ -1108,14 +1101,14 @@ int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size) { struct btrfs_zoned_device_info *zinfo = device->zone_info; - const u8 shift = zinfo->zone_size_shift; - unsigned long begin = start >> shift; - unsigned long end = (start + size) >> shift; + unsigned long begin = bdev_zone_no(device->bdev, start >> SECTOR_SHIFT); + unsigned long end = + bdev_zone_no(device->bdev, (start + size) >> SECTOR_SHIFT); u64 pos; int ret; - ASSERT(IS_ALIGNED(start, zinfo->zone_size)); - ASSERT(IS_ALIGNED(size, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(start, zinfo->zone_size)); + ASSERT(btrfs_zoned_is_aligned(size, zinfo->zone_size)); if (end > zinfo->nr_zones) return -ERANGE; @@ -1139,8 +1132,9 @@ int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size) /* Free regions should be empty */ btrfs_warn_in_rcu( device->fs_info, - "zoned: resetting device %s (devid %llu) zone %llu for allocation", - rcu_str_deref(device->name), device->devid, pos >> shift); + "zoned: resetting device %s (devid %llu) zone %u for allocation", + rcu_str_deref(device->name), device->devid, + bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT)); WARN_ON_ONCE(1); ret = btrfs_reset_device_zone(device, pos, zinfo->zone_size, @@ -1237,7 +1231,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) return 0; /* Sanity check */ - if (!IS_ALIGNED(length, fs_info->zone_size)) { + if (!btrfs_zoned_is_aligned(length, fs_info->zone_size)) { btrfs_err(fs_info, "zoned: block group %llu len %llu unaligned to zone size %llu", logical, length, fs_info->zone_size); @@ -1325,7 +1319,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) * The group is mapped to a sequential zone. Get the zone write * pointer to determine the allocation offset within the zone. */ - WARN_ON(!IS_ALIGNED(physical[i], fs_info->zone_size)); + WARN_ON(!btrfs_zoned_is_aligned(physical[i], fs_info->zone_size)); nofs_flag = memalloc_nofs_save(); ret = btrfs_get_dev_zone(device, physical[i], &zone); memalloc_nofs_restore(nofs_flag); @@ -1351,10 +1345,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) switch (zone.cond) { case BLK_ZONE_COND_OFFLINE: case BLK_ZONE_COND_READONLY: - btrfs_err(fs_info, - "zoned: offline/readonly zone %llu on device %s (devid %llu)", - physical[i] >> device->zone_info->zone_size_shift, - rcu_str_deref(device->name), device->devid); + btrfs_err( + fs_info, + "zoned: offline/readonly zone %u on device %s (devid %llu)", + bdev_zone_no(device->bdev, + physical[i] >> SECTOR_SHIFT), + rcu_str_deref(device->name), device->devid); alloc_offsets[i] = WP_MISSING_DEV; break; case BLK_ZONE_COND_EMPTY: diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 694ab6d1e..b94ce4d1f 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -9,6 +9,7 @@ #include "disk-io.h" #include "block-group.h" #include "btrfs_inode.h" +#include "misc.h" #define BTRFS_DEFAULT_RECLAIM_THRESH (75) @@ -18,7 +19,6 @@ struct btrfs_zoned_device_info { * zoned block device. */ u64 zone_size; - u8 zone_size_shift; u32 nr_zones; unsigned int max_active_zones; atomic_t active_zones_left; @@ -30,6 +30,36 @@ struct btrfs_zoned_device_info { u32 sb_zone_location[BTRFS_SUPER_MIRROR_MAX]; }; +static inline bool btrfs_zoned_is_aligned(u64 pos, u64 zone_size) +{ + u64 remainder = 0; + + if (is_power_of_two_u64(zone_size)) + return IS_ALIGNED(pos, zone_size); + + div64_u64_rem(pos, zone_size, &remainder); + return remainder == 0; +} + +static inline u64 btrfs_zoned_roundup(u64 pos, u64 zone_size) +{ + if (is_power_of_two_u64(zone_size)) + return ALIGN(pos, zone_size); + + return div64_u64(pos + zone_size - 1, zone_size) * zone_size; +} + +static inline u64 btrfs_zoned_rounddown(u64 pos, u64 zone_size) +{ + u64 remainder = 0; + if (is_power_of_two_u64(zone_size)) + return round_down(pos, zone_size); + + div64_u64_rem(pos, zone_size, &remainder); + pos -= remainder; + return pos; +} + #ifdef CONFIG_BLK_DEV_ZONED int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone); @@ -253,7 +283,8 @@ static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) if (!zone_info) return false; - return test_bit(pos >> zone_info->zone_size_shift, zone_info->seq_zones); + return test_bit(bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT), + zone_info->seq_zones); } static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos) @@ -263,7 +294,8 @@ static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos) if (!zone_info) return true; - return test_bit(pos >> zone_info->zone_size_shift, zone_info->empty_zones); + return test_bit(bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT), + zone_info->empty_zones); } static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device, @@ -275,7 +307,7 @@ static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device, if (!zone_info) return; - zno = pos >> zone_info->zone_size_shift; + zno = bdev_zone_no(device->bdev, pos >> SECTOR_SHIFT); if (set) set_bit(zno, zone_info->empty_zones); else @@ -329,7 +361,8 @@ static inline bool btrfs_can_zone_reset(struct btrfs_device *device, return false; zone_size = device->zone_info->zone_size; - if (!IS_ALIGNED(physical, zone_size) || !IS_ALIGNED(length, zone_size)) + if (!btrfs_zoned_is_aligned(physical, zone_size) || + !btrfs_zoned_is_aligned(length, zone_size)) return false; return true; From patchwork Thu May 5 13:47:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12839626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC250C43219 for ; Thu, 5 May 2022 13:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380241AbiEENy7 (ORCPT ); Thu, 5 May 2022 09:54:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380207AbiEENyw (ORCPT ); Thu, 5 May 2022 09:54:52 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 772F857110 for ; Thu, 5 May 2022 06:51:11 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220505135110euoutp01a7d585ebdd01639795b4d202d0d84349~sOcJa8-S23116431164euoutp01z for ; Thu, 5 May 2022 13:51:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220505135110euoutp01a7d585ebdd01639795b4d202d0d84349~sOcJa8-S23116431164euoutp01z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651758670; bh=OUOs5yoREFPm133MftqN/52v0OJCiB1b6vGYcsnZpfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uw/z6ktZDEetNfF04XYyIz4VfwwvEUOgly6aTcV3WrahzMVh2n8A8Vzh6qc2r32uB /ctoSuUTS69txG46Bu2tEF3RvO4pXU+XF5n+wHwyhAty9kpI+aC9wAsR81RciIuBVv z+APW0xdtsBJurULIbie7N+tmWgN6zZipyVE8sHU= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220505135108eucas1p1f497195530c192725734360b68b241fd~sOcH5PivL0606806068eucas1p1V; Thu, 5 May 2022 13:51:08 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id AD.FC.10009.C46D3726; Thu, 5 May 2022 14:51:08 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220505135108eucas1p295ecfd1113baa72d7522416a761a983c~sOcHZVNdK3188131881eucas1p2o; Thu, 5 May 2022 13:51:08 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220505135108eusmtrp27da582a3255e196cafcfad4d7d6cfedc~sOcHYhC4I2662626626eusmtrp28; Thu, 5 May 2022 13:51:08 +0000 (GMT) X-AuditID: cbfec7f2-e95ff70000002719-43-6273d64cf082 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id F2.03.09522.B46D3726; Thu, 5 May 2022 14:51:07 +0100 (BST) Received: from localhost (unknown [106.210.248.170]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220505135107eusmtip1ff787df647b476670b2a8f0579b4cd21~sOcHG4JsC2664626646eusmtip1h; Thu, 5 May 2022 13:51:07 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, dsterba@suse.com, jaegeuk@kernel.org, bvanassche@acm.org, hare@suse.de Cc: jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, matias.bjorling@wdc.com, gost.dev@samsung.com, pankydev8@gmail.com, Pankaj Raghav , Luis Chamberlain , Chris Mason , Josef Bacik , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 08/11] btrfs: zoned: relax the alignment constraint for zoned devices Date: Thu, 5 May 2022 15:47:08 +0200 Message-Id: <20220505134710.132630-9-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505134710.132630-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGKsWRmVeSWpSXmKPExsWy7djP87o+14qTDBYelLdYfbefzWLah5/M FpP6Z7Bb/D57ntniwo9GJoubB3YyWexZNInJYuXqo0wWT9bPYrboOfCBxWJly0Nmiz8PDS0u PV7BbnF51xw2iwltX5ktbkx4ymjxeWkLu8Wam09ZHIQ8Ll/x9vh3Yg2bx8Tmd+weO2fdZfe4 fLbUY9OqTjaPhQ1TmT1232xg89jZep/Vo2/LKkaP9VuusnhsPl3tMWHzRlaPz5vkPNoPdDMF 8Edx2aSk5mSWpRbp2yVwZez7u4W54LFAxcYlt9kbGO/ydjFyckgImEismHWNvYuRi0NIYAWj xJuPC9hAEkICXxglnt2Tg0h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wam09ZHIQ8Ll/x9vh3Yg2bx8Tmd+weO2fdZfe4 fLbUY9OqTjaPhQ1TmT1232xg89jZep/Vo2/LKkaP9VuusnhsPl3tMWHzRlaPz5vkPNoPdDMF 8Efp2RTll5akKmTkF5fYKkUbWhjpGVpa6BmZWOoZGpvHWhmZKunb2aSk5mSWpRbp2yXoZez7 u4W54LFAxcYlt9kbGO/ydjFyckgImEhsfXCWqYuRi0NIYCmjxJZVR5ghEhIStxc2MULYwhJ/ rnWxQRQ9Z5S423qBpYuRg4NNQEuisZMdJC4iMJVR4sJ2kDgXB7PANSaJhoe72EC6hQUiJD48 vcgCYrMIqEpcfvaPCcTmFbCSmL3+IdQGeYmZl76zg9icAtYSczofsoLYQkA1Ex++Y4OoF5Q4 OfMJ2BxmoPrmrbOZJzAKzEKSmoUktYCRaRWjSGppcW56brGhXnFibnFpXrpecn7uJkZghG87 9nPzDsZ5rz7qHWJk4mA8xCjBwawkwuu8tCBJiDclsbIqtSg/vqg0J7X4EKMp0N0TmaVEk/OB KSavJN7QzMDU0MTM0sDU0sxYSZzXs6AjUUggPbEkNTs1tSC1CKaPiYNTqoFprVKvd0bIWktb vjuHixwuPJRKsP25/7fhAr3o0icMtuKljVXVy3oTal3cX0zcrVjP5bx012LDFdpe69Z8WC9e aH9YI2+vqsmFu4KXvnr/Umj68PKWd+P/xvPhnsnZ/8/V2nw883jvie7Gb7UGpx8/Lnt6OOl5 dGxX9BzTyUtdYkOm3D0hUqBUvXv95SxVHYtJz8X01jbf0a53Kz9bbqqUIc/iGcx7yZfv3PTO ICZr7R0H/P4wbmB49jHq+1PR44tCTXRtzogZBN8RZHBVV/ff1Ni6pufAUTEJnT+Gh9zqDsam SarUi25Qz12ofedu7dtT6meMNr3fueL+qxf7mffsytsuY1TDsEOC8ajF0jIlluKMREMt5qLi RAC0jTRDeQMAAA== X-CMS-MailID: 20220505135108eucas1p295ecfd1113baa72d7522416a761a983c X-Msg-Generator: CA X-RootMTR: 20220505135108eucas1p295ecfd1113baa72d7522416a761a983c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220505135108eucas1p295ecfd1113baa72d7522416a761a983c References: <20220505134710.132630-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Checks were in place to return error when a non power-of-2 zoned devices is detected. Remove those checks as non power-of-2 zoned devices are now supported. Relax the zone size constraint to align with a sane default of 1MB. This 1M default has been chosen as the minimum alignment requirement for zone sizes to make sure zones align with sectorsize in different architectures. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 3023c871e..a6b15fbe1 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -54,6 +54,13 @@ */ #define BTRFS_MAX_ZONE_SIZE SZ_8G +/* + * A minimum alignment of 1MB is chosen for zoned devices as their zone sizes + * can be non power of 2. This is to make sure the zones correctly align to the + * sectorsize. + */ +#define BTRFS_ZONED_MIN_ALIGN_SECTORS ((u64)SZ_1M >> SECTOR_SHIFT) + #define SUPER_INFO_SECTORS ((u64)BTRFS_SUPER_INFO_SIZE >> SECTOR_SHIFT) static inline bool sb_zone_is_full(const struct blk_zone *zone) @@ -394,8 +401,8 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) zone_sectors = bdev_zone_sectors(bdev); } - /* Check if it's power of 2 (see is_power_of_2) */ - ASSERT(zone_sectors != 0 && (zone_sectors & (zone_sectors - 1)) == 0); + ASSERT(zone_sectors != 0 && + IS_ALIGNED(zone_sectors, BTRFS_ZONED_MIN_ALIGN_SECTORS)); zone_info->zone_size = zone_sectors << SECTOR_SHIFT; /* We reject devices with a zone size larger than 8GB */ @@ -834,9 +841,11 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, ASSERT(rw == READ || rw == WRITE); - if (!is_power_of_2(bdev_zone_sectors(bdev))) - return -EINVAL; nr_sectors = bdev_nr_sectors(bdev); + + if (!IS_ALIGNED(nr_sectors, BTRFS_ZONED_MIN_ALIGN_SECTORS)) + return -EINVAL; + nr_zones = bdev_zone_no(bdev, nr_sectors); sb_zone = sb_zone_number(bdev, mirror);