All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pankaj Raghav <p.raghav@samsung.com>
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 <p.raghav@samsung.com>,
	Luis Chamberlain <mcgrof@kernel.org>, Chris Mason <clm@fb.com>,
	Josef Bacik <josef@toxicpanda.com>,
	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	[thread overview]
Message-ID: <20220505134710.132630-6-p.raghav@samsung.com> (raw)
In-Reply-To: <20220505134710.132630-1-p.raghav@samsung.com>

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 <mcgrof@kernel.org>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
 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
-- 
2.25.1


  parent reply	other threads:[~2022-05-05 13:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220505134710.132630-1-p.raghav@samsung.com>
     [not found] ` <CGME20220505134934eucas1p2de726a86c47310171425a17a7ce2858b@eucas1p2.samsung.com>
2022-05-05 13:47   ` [PATCH v2 01/11] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Pankaj Raghav
     [not found] ` <CGME20220505135100eucas1p29e1b1452cc81a76460b938df339cb91a@eucas1p2.samsung.com>
2022-05-05 13:47   ` [PATCH v2 02/11] block: allow blk-zoned devices to have non-power-of-2 zone size Pankaj Raghav
     [not found] ` <CGME20220505135101eucas1p10477067397a4fdadf9fe7adbb26d1edc@eucas1p1.samsung.com>
2022-05-05 13:47   ` [PATCH v2 03/11] nvme: zns: Allow ZNS drives that have non-power_of_2 " Pankaj Raghav
     [not found] ` <CGME20220505135102eucas1p10efc01a623d97cbd6634943faa506353@eucas1p1.samsung.com>
2022-05-05 13:47   ` [PATCH v2 04/11] nvmet: Allow ZNS target to support non-power_of_2 zone sizes Pankaj Raghav
     [not found] ` <CGME20220505135104eucas1p1bed3e1e47255518296b4cb15ec0c042b@eucas1p1.samsung.com>
2022-05-05 13:47   ` Pankaj Raghav [this message]
     [not found] ` <CGME20220505135105eucas1p1428258bde56a77a96d98509a2c0d5fe9@eucas1p1.samsung.com>
2022-05-05 13:47   ` [PATCH v2 06/11] btrfs: zoned: Make sb_zone_number function non power of 2 compatible Pankaj Raghav
     [not found] ` <CGME20220505135106eucas1p18d4d0bc1e5fb02375229b05b6dbdf92c@eucas1p1.samsung.com>
2022-05-05 13:47   ` [PATCH v2 07/11] btrfs: zoned: use generic btrfs zone helpers to support npo2 zoned devices Pankaj Raghav
     [not found] ` <CGME20220505135108eucas1p295ecfd1113baa72d7522416a761a983c@eucas1p2.samsung.com>
2022-05-05 13:47   ` [PATCH v2 08/11] btrfs: zoned: relax the alignment constraint for " Pankaj Raghav
     [not found] ` <CGME20220505135109eucas1p168fb7625ef67de5a1f98520cdd29311e@eucas1p1.samsung.com>
2022-05-05 13:47   ` [PATCH v2 09/11] zonefs: allow non power of 2 " Pankaj Raghav
     [not found] ` <CGME20220505135110eucas1p1fc49b2574920b9a2a274f9d77feb5d18@eucas1p1.samsung.com>
2022-05-05 13:47   ` [PATCH v2 10/11] null_blk: " Pankaj Raghav
     [not found] ` <CGME20220505135111eucas1p218b79f4b1e54bb3a24d2ec189ec445d1@eucas1p2.samsung.com>
2022-05-05 13:47   ` [PATCH v2 11/11] dm-zoned: ensure only power of 2 zone sizes are allowed Pankaj Raghav
2022-05-05 13:47     ` [dm-devel] " Pankaj Raghav

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220505134710.132630-6-p.raghav@samsung.com \
    --to=p.raghav@samsung.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=clm@fb.com \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=dsterba@suse.com \
    --cc=gost.dev@samsung.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jaegeuk@kernel.org \
    --cc=jiangbo.365@bytedance.com \
    --cc=jonathan.derrick@linux.dev \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matias.bjorling@wdc.com \
    --cc=mcgrof@kernel.org \
    --cc=pankydev8@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.