linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Naohiro Aota <naohiro.aota@wdc.com>
To: David Sterba <dsterba@suse.com>, Josef Bacik <josef@toxicpanda.com>
Cc: linux-btrfs@vger.kernel.org, Naohiro Aota <naohiro.aota@wdc.com>
Subject: [PATCH v2 09/17] btrfs: zoned: introduce physical_map to btrfs_block_group
Date: Thu, 19 Aug 2021 21:19:16 +0900	[thread overview]
Message-ID: <2b5e458e2e77a4cc29d081d859d7002d07fc4b9e.1629349224.git.naohiro.aota@wdc.com> (raw)
In-Reply-To: <cover.1629349224.git.naohiro.aota@wdc.com>

We will use a block group's physical location to track active zones and
finish fully written zones in the following commits. Since the zone
activation is done in the extent allocation context which already holding
the tree locks, we can't query the chunk tree for the physical locations.
So, copy the location info into a block group and use it for activation.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/block-group.c |  1 +
 fs/btrfs/block-group.h |  1 +
 fs/btrfs/zoned.c       | 17 +++++++++++++++--
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index de22e3c9599e..c94815cbd136 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -144,6 +144,7 @@ void btrfs_put_block_group(struct btrfs_block_group *cache)
 		 */
 		WARN_ON(!RB_EMPTY_ROOT(&cache->full_stripe_locks_root.root));
 		kfree(cache->free_space_ctl);
+		kfree(cache->physical_map);
 		kfree(cache);
 	}
 }
diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h
index 2db40a005512..265db2c316d3 100644
--- a/fs/btrfs/block-group.h
+++ b/fs/btrfs/block-group.h
@@ -204,6 +204,7 @@ struct btrfs_block_group {
 	u64 zone_unusable;
 	u64 zone_capacity;
 	u64 meta_write_pointer;
+	struct map_lookup *physical_map;
 };
 
 static inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index a198ce073353..cfc6d4337473 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1158,10 +1158,19 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
 
 	map = em->map_lookup;
 
+	cache->physical_map = kmalloc(map_lookup_size(map->num_stripes),
+				      GFP_NOFS);
+	if (!cache->physical_map) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	memcpy(cache->physical_map, map, map_lookup_size(map->num_stripes));
+
 	alloc_offsets = kcalloc(map->num_stripes, sizeof(*alloc_offsets), GFP_NOFS);
 	if (!alloc_offsets) {
-		free_extent_map(em);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out;
 	}
 
 	caps = kcalloc(map->num_stripes, sizeof(*caps), GFP_NOFS);
@@ -1344,6 +1353,10 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
 	if (!ret)
 		cache->meta_write_pointer = cache->alloc_offset + cache->start;
 
+	if (ret) {
+		kfree(cache->physical_map);
+		cache->physical_map = NULL;
+	}
 	kfree(caps);
 	kfree(alloc_offsets);
 	free_extent_map(em);
-- 
2.33.0


  parent reply	other threads:[~2021-08-19 12:27 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19 12:19 [PATCH v2 00/17] ZNS Support for Btrfs Naohiro Aota
2021-08-19 12:19 ` [PATCH v2 01/17] btrfs: zoned: load zone capacity information from devices Naohiro Aota
2021-08-24  7:52   ` Johannes Thumshirn
2021-08-19 12:19 ` [PATCH v2 02/17] btrfs: zoned: move btrfs_free_excluded_extents out from btrfs_calc_zone_unusable Naohiro Aota
2021-08-24  7:55   ` Johannes Thumshirn
2021-08-19 12:19 ` [PATCH v2 03/17] btrfs: zoned: calculate free space from zone capacity Naohiro Aota
2021-08-24  7:59   ` Johannes Thumshirn
2021-08-24 15:27     ` David Sterba
2021-08-24 16:04       ` Johannes Thumshirn
2021-08-19 12:19 ` [PATCH v2 04/17] btrfs: zoned: tweak reclaim threshold for " Naohiro Aota
2021-08-24  8:09   ` Johannes Thumshirn
2021-08-19 12:19 ` [PATCH v2 05/17] btrfs: zoned: consider zone as full when no more SB can be written Naohiro Aota
2021-08-24  8:37   ` Johannes Thumshirn
2021-08-19 12:19 ` [PATCH v2 06/17] btrfs: zoned: locate superblock position using zone capacity Naohiro Aota
2021-08-25  8:32   ` Johannes Thumshirn
2021-08-19 12:19 ` [PATCH v2 07/17] btrfs: zoned: finish superblock zone once no space left for new SB Naohiro Aota
2021-08-19 12:19 ` [PATCH v2 08/17] btrfs: zoned: load active zone information from devices Naohiro Aota
2021-08-19 12:19 ` Naohiro Aota [this message]
2021-08-19 12:19 ` [PATCH v2 10/17] btrfs: zoned: implement active zone tracking Naohiro Aota
2021-08-19 12:19 ` [PATCH v2 11/17] btrfs: zoned: load active zone info for block group Naohiro Aota
2021-08-19 12:19 ` [PATCH v2 12/17] btrfs: zoned: activate block group on allocation Naohiro Aota
2021-08-19 12:19 ` [PATCH v2 13/17] btrfs: zoned: activate new block group Naohiro Aota
2021-08-19 12:19 ` [PATCH v2 14/17] btrfs: move ffe_ctl one level up Naohiro Aota
2021-08-19 12:19 ` [PATCH v2 15/17] btrfs: zoned: avoid chunk allocation if active block group has enough space Naohiro Aota
2021-08-19 12:19 ` [PATCH v2 16/17] btrfs: zoned: finish fully written block group Naohiro Aota
2021-08-19 12:19 ` [PATCH v2 17/17] btrfs: zoned: finish relocating " Naohiro Aota
2021-08-27 16:25 ` [PATCH v2 00/17] ZNS Support for Btrfs David Sterba

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=2b5e458e2e77a4cc29d081d859d7002d07fc4b9e.1629349224.git.naohiro.aota@wdc.com \
    --to=naohiro.aota@wdc.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).