Skip to contentSkip to conversation

btrfs: zoned: fix active-zone accounting and transitions

PATCH In review Dongjiang Zhu 2 participants 6 messages Nov 25 – Nov 27 Btrfs file system

lore
Share & tools
lore
#0 lore raw

v4 cover btrfs: zoned: fix active-zone accounting and transitions

This series addresses active-zone accounting and block group transitions on zoned devices. It simplifies conventional-zone handling, restores metadata/system write roles at mount, and addresses a balance self-deadlock and a race during zone finishing.

The four patches:

1. Track only sequential zones as active.
2. Restore the normal metadata and system write roles at mount, keeping one active block group for each role and finishing the remaining active non-data block groups.
3. Remove obsolete allocation-time non-data activation, leaving activation and role switching to the writeback path.
4. Serialize concurrent finish operations on the same block group, keeping it active until the device operations and active-list cleanup complete.

Jochen Philipp tested a rebased version of this series on his filesystem. He reported writing another 2.3 TB via rsync without Btrfs errors, a clean unmount, no errors from btrfs check --readonly, and a successful read-write mount afterwards. Many thanks to Jochen for the extensive testing.

Changes in v4:
- Rebased onto btrfs for-next at 7bfc2c517eac.
- Retained the upstream active-zone bitmap check for mount-time reservation accounting and the conditional reservation updates during activation and finishing.
- Moved abandoned-tail accounting into do_zone_finish(), alongside the alloc_offset update, preserving read-only block group accounting.
- Removed the unnecessary temporary block group references in mount-time cleanup.
- Updated the commit messages to reflect the current base and clarify the role-recovery and zone-finishing behavior.

Changes in v3:
- Dropped the block-group flag comment changes from patch 1; no functional changes.

Changes in v2:
- Removed the [BUG], [CAUSE] and [FIX] headings from the commit messages.
- Added a helper for identifying zones that need active-zone tracking.
- Added block group locking around alloc_offset and zone_unusable accesses during mount recovery.
- Explained why moving the active-bit clear alone does not serialize concurrent zone finish operations.

Previous versions:
v3: https://lore.kernel.org/linux-btrfs/[email protected]/
v2: https://lore.kernel.org/linux-btrfs/[email protected]/
v1: https://lore.kernel.org/linux-btrfs/[email protected]/

Dongjiang Zhu (4):
btrfs: zoned: track only sequential zones as active
btrfs: zoned: recover active non-data block group roles on mount
btrfs: zoned: remove obsolete non-data block group activation helper
btrfs: zoned: serialize zone finishing per block group

 fs/btrfs/block-group.c |  38 ++------
 fs/btrfs/block-group.h |   1 +
 fs/btrfs/disk-io.c     |   7 +-
 fs/btrfs/zoned.c       | 211 +++++++++++++++++++++++++++++------------
 fs/btrfs/zoned.h       |   9 +-
 5 files changed, 167 insertions(+), 99 deletions(-)
Signature · 1 line
2.39.5
#2 lore raw

PATCH v4 2/4 btrfs: zoned: recover active non-data block group roles on mount

Mount restores active sequential non-data block groups and their reservations, but leaves active_meta_bg and active_system_bg unset. Writing to a recovered block group does not set its role pointer:
check_bg_is_active() returns early because ZONE_IS_ACTIVE is already set, skipping the role assignment.

These block groups can still be finished through other paths, but metadata/system write-time switching cannot identify the previous block group when the corresponding role pointer is NULL.

Restore these roles during mount so write-time switching can identify and finish the previous non-data block group.

Keep the active block group with the largest writable tail for each metadata/system role and finish the others. Since the tree-log role is not persisted, leave a reservation for a new tree-log block group.

Account for the abandoned tails in do_zone_finish().

---
 fs/btrfs/disk-io.c |   7 +++-
 fs/btrfs/zoned.c   | 102 +++++++++++++++++++++++++++++++++++++++++----
 fs/btrfs/zoned.h   |   7 +++-
 3 files changed, 106 insertions(+), 10 deletions(-)
fs/btrfs/disk-io.c +6 -1
index fde9f4c4ea11..021dcd38b7be 100644
@@ -3768,7 +3768,12 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
 
 	btrfs_free_zone_cache(fs_info);
 
-	btrfs_check_active_zone_reservation(fs_info);
+	ret = btrfs_restore_active_nondata_bgs(fs_info);
+	if (ret) {
+		btrfs_err(fs_info, "failed to restore active non-data block groups: %pe",
+			  ERR_PTR(ret));
+		goto fail_sysfs;
+	}
 
 	if (!sb_rdonly(sb) && fs_info->fs_devices->missing_devices &&
 	    !btrfs_check_rw_degradable(fs_info, NULL)) {
fs/btrfs/zoned.c +95 -7

201 lines not on this page · raw message

fs/btrfs/zoned.h +5 -2
index 2225090839f3..8ed28e47d71b 100644
@@ -100,7 +100,7 @@ void btrfs_zoned_release_data_reloc_bg(struct btrfs_fs_info *fs_info, u64 logica
 				       u64 length);
 int btrfs_zone_finish_one_bg(struct btrfs_fs_info *fs_info);
 int btrfs_zoned_activate_one_bg(struct btrfs_space_info *space_info, bool do_finish);
-void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info);
+int btrfs_restore_active_nondata_bgs(struct btrfs_fs_info *fs_info);
 int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num_bytes);
 void btrfs_show_zoned_stats(struct btrfs_fs_info *fs_info, struct seq_file *seq);
 
@@ -286,7 +286,10 @@ static inline int btrfs_zoned_activate_one_bg(struct btrfs_space_info *space_inf
 	return 0;
 }
 
-static inline void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info) { }
+static inline int btrfs_restore_active_nondata_bgs(struct btrfs_fs_info *fs_info)
+{
+	return 0;
+}
 
 static inline int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info,
 						  u64 num_bytes)
Signature · 1 line
2.39.5
#1 lore raw

PATCH v4 1/4 btrfs: zoned: track only sequential zones as active

In reply to Dongjiang Zhu

Conventional zones do not consume hardware active-zone slots, but conventional stripes can still be included in runtime accounting. This complicates active-zone state management and increases the risk of accounting errors. Simplify the accounting by tracking only sequential zones as active.

---
 fs/btrfs/zoned.c | 48 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 15 deletions(-)
fs/btrfs/zoned.c +33 -15
index e6ce6f05ad75..3475e7785f58 100644
@@ -1980,7 +1980,6 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
 		} else if (map->num_stripes == num_conventional) {
 			cache->alloc_offset = last_alloc;
 			cache->zone_capacity = cache->length;
-			set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &cache->runtime_flags);
 			goto out;
 		}
 	}
@@ -2016,6 +2015,8 @@ 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 (test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &cache->runtime_flags)) {
+			ASSERT(test_bit(BLOCK_GROUP_FLAG_SEQUENTIAL_ZONE,
+					&cache->runtime_flags));
 			spin_lock(&fs_info->zone_active_bgs_lock);
 			if (list_empty(&cache->active_bg_list)) {
 				btrfs_get_block_group(cache);
@@ -2211,6 +2212,9 @@ static bool check_bg_is_active(struct btrfs_eb_write_context *ctx,
 	if (test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags))
 		return true;
 
+	if (!test_bit(BLOCK_GROUP_FLAG_SEQUENTIAL_ZONE, &block_group->runtime_flags))
+		return true;
+
 	if (fs_info->treelog_bg == block_group->start) {
 		if (!btrfs_zone_activate(block_group)) {
 			int ret_fin;
@@ -2407,6 +2411,18 @@ int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, u64 logical,
 	return btrfs_zoned_issue_zeroout(tgt_dev, physical_pos, length);
 }
 
+static inline bool btrfs_needs_active_zone_tracking(struct btrfs_device *dev,
+						    u64 physical)
+{
+	if (!btrfs_dev_is_sequential(dev, physical))
+		return false;
+
+	if (dev->zone_info->max_active_zones == 0)
+		return false;
+
+	return true;
+}
+
 /*
  * Activate block group and underlying device zones
  *
@@ -2431,6 +2447,9 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)
 	if (unlikely(btrfs_is_testing(fs_info)))
 		return true;
 
+	if (!test_bit(BLOCK_GROUP_FLAG_SEQUENTIAL_ZONE, &block_group->runtime_flags))
+		return true;
+
 	map = block_group->physical_map;
 
 	spin_lock(&fs_info->zone_active_bgs_lock);
@@ -2462,7 +2481,7 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)
 		if (!device->bdev)
 			continue;
 
-		if (zinfo->max_active_zones == 0)
+		if (!btrfs_needs_active_zone_tracking(device, physical))
 			continue;
 
 		/*
@@ -2537,27 +2556,23 @@ static int call_zone_finish(struct btrfs_block_group *block_group,
 	struct btrfs_device *device = stripe->dev;
 	const u64 physical = stripe->physical;
 	struct btrfs_zoned_device_info *zinfo = device->zone_info;
+	unsigned int nofs_flags;
 	bool cleared;
 	int ret;
 
 	if (!device->bdev)
 		return 0;
 
-	if (zinfo->max_active_zones == 0)
+	if (!btrfs_needs_active_zone_tracking(device, physical))
 		return 0;
 
-	if (btrfs_dev_is_sequential(device, physical)) {
-		unsigned int nofs_flags;
-
-		nofs_flags = memalloc_nofs_save();
-		ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
-				       physical >> SECTOR_SHIFT,
-				       zinfo->zone_size >> SECTOR_SHIFT);
-		memalloc_nofs_restore(nofs_flags);
-
-		if (ret)
-			return ret;
-	}
+	nofs_flags = memalloc_nofs_save();
+	ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
+			       physical >> SECTOR_SHIFT,
+			       zinfo->zone_size >> SECTOR_SHIFT);
+	memalloc_nofs_restore(nofs_flags);
+	if (ret)
+		return ret;
 
 	cleared = btrfs_dev_clear_active_zone(device, physical);
 	if (!(block_group->flags & BTRFS_BLOCK_GROUP_DATA) && cleared)
@@ -3168,6 +3183,9 @@ void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info)
 			if (!device->bdev)
 				continue;
 
+			if (zinfo->max_active_zones == 0)
+				continue;
+
 			if (!test_bit(physical >> zinfo->zone_size_shift, zinfo->active_zones))
 				continue;
 
Signature · 1 line
2.39.5
#4 lore raw

PATCH v4 4/4 btrfs: zoned: serialize zone finishing per block group

In reply to Dongjiang Zhu

On an HC620 with max_active_zones=128, buffered writes occupied all 128 active-zone slots. A metadata-heavy create/delete workload followed by sync then forced a metadata block group switch.

A kernel with additional zone finish tracing reported:

zoned-debug: finish clear-runtime bg=140928614400 caller=btrfs_zone_finish_endio_workfn comm=kworker/u8:7
zoned-debug: finish early-inactive bg=140928614400 caller=btrfs_check_meta_write_pointer comm=sync
zoned-debug: pivot finish ret=0 old_bg=140928614400 new_bg=339839287296
zoned-debug: activate fail slot bg=339839287296 type=metadata left=0 max_active=128 comm=sync
zoned-debug: finish zone-mgmt bg=140928614400 ret=0 left=0 caller=btrfs_zone_finish_endio_workfn comm=kworker/u8:7 BTRFS error (device sdb): error while writing out transaction: -EAGAIN
BTRFS error (device sdb state A): Transaction 67 aborted (-EAGAIN)
BTRFS info (device sdb state EA): forced readonly
zoned-debug: clear-active dev=/dev/sdb pos=140928614400 left=1 max_active=128

The transaction was aborted before the old block group returned its active-zone slot, forcing the filesystem read-only.

This happens because do_zone_finish() clears BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE before issuing the zone finish operation. This allows the following interleaving:

Thread A, endio worker Thread B, transaction writeback

clear ZONE_IS_ACTIVE
call_zone_finish(old)
observe old as inactive return from do_zone_finish(old) activate(new)
fail with left == 0
clear the device active bit
increment active_zones_left

Thread B treats the cleared active bit as a completed finish, although thread A has not yet returned the active-zone slot.

Add ZONE_FINISHING to serialize finishers per block group. Keep ZONE_IS_ACTIVE set until the device operations and active-list cleanup are complete, then wake waiting finishers. Release any temporary read-only reference acquired by a waiting caller.

---
 fs/btrfs/block-group.h |  1 +
 fs/btrfs/zoned.c       | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)
fs/btrfs/block-group.h +1 -0
index d567ed822e55..31aca6424d54 100644
@@ -88,6 +88,7 @@ enum btrfs_block_group_flags {
 	BLOCK_GROUP_FLAG_NEW,
 	BLOCK_GROUP_FLAG_FULLY_REMAPPED,
 	BLOCK_GROUP_FLAG_STRIPE_REMOVAL_PENDING,
+	BLOCK_GROUP_FLAG_ZONE_FINISHING,
 };
 
 enum btrfs_caching_type {
fs/btrfs/zoned.c +30 -1
index 2d02d6fd2526..14ea819831b6 100644
@@ -2589,6 +2589,7 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
 	const bool is_metadata = (block_group->flags &
 			(BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM));
 	struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
+	bool bg_ro = false;
 	int ret = 0;
 	int i;
 
@@ -2600,6 +2601,12 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
 		return 0;
 	}
 
+	if (test_bit(BLOCK_GROUP_FLAG_ZONE_FINISHING, &block_group->runtime_flags)) {
+		spin_unlock(&block_group->lock);
+		spin_unlock(&space_info->lock);
+		goto wait_finish;
+	}
+
 	/* Check if we have unwritten allocated space */
 	if (is_metadata &&
 	    block_group->start + block_group->alloc_offset > block_group->meta_write_pointer) {
@@ -2630,6 +2637,7 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
 		ret = btrfs_inc_block_group_ro(block_group, false);
 		if (ret)
 			return ret;
+		bg_ro = true;
 
 		/* Ensure all writes in this block group finish */
 		btrfs_wait_block_group_reservations(block_group);
@@ -2655,6 +2663,13 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
 			return 0;
 		}
 
+		if (test_bit(BLOCK_GROUP_FLAG_ZONE_FINISHING,
+			     &block_group->runtime_flags)) {
+			spin_unlock(&block_group->lock);
+			spin_unlock(&space_info->lock);
+			goto wait_finish;
+		}
+
 		if (block_group->reserved ||
 		    test_bit(BLOCK_GROUP_FLAG_ZONED_DATA_RELOC,
 			     &block_group->runtime_flags)) {
@@ -2676,7 +2691,7 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
 		btrfs_space_info_update_bytes_zone_unusable(space_info, tail_unusable);
 	}
 
-	clear_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags);
+	set_bit(BLOCK_GROUP_FLAG_ZONE_FINISHING, &block_group->runtime_flags);
 	block_group->alloc_offset = block_group->zone_capacity;
 	if (block_group->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM))
 		block_group->meta_write_pointer = block_group->start +
@@ -2700,8 +2715,13 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
 		btrfs_dec_block_group_ro(block_group);
 
 	spin_lock(&fs_info->zone_active_bgs_lock);
+	spin_lock(&block_group->lock);
+	clear_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags);
 	ASSERT(!list_empty(&block_group->active_bg_list));
 	list_del_init(&block_group->active_bg_list);
+	clear_and_wake_up_bit(BLOCK_GROUP_FLAG_ZONE_FINISHING,
+			      &block_group->runtime_flags);
+	spin_unlock(&block_group->lock);
 	spin_unlock(&fs_info->zone_active_bgs_lock);
 
 	/* For active_bg_list */
@@ -2710,6 +2730,15 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
 	clear_and_wake_up_bit(BTRFS_FS_NEED_ZONE_FINISH, &fs_info->flags);
 
 	return ret;
+
+wait_finish:
+	wait_on_bit_io(&block_group->runtime_flags,
+		       BLOCK_GROUP_FLAG_ZONE_FINISHING,
+		       TASK_UNINTERRUPTIBLE);
+	if (bg_ro)
+		btrfs_dec_block_group_ro(block_group);
+
+	return 0;
 }
 
 int btrfs_zone_finish(struct btrfs_block_group *block_group)
Signature · 1 line
2.39.5
#3 lore raw

PATCH v4 3/4 btrfs: zoned: remove obsolete non-data block group activation helper

In reply to Dongjiang Zhu

On an HC620 with max_active_zones=128, file writes occupied all 128 active-zone slots. With four direct-I/O writers still running, starting a balance with

btrfs balance start -f -dusage=0 -musage=0 -susage=100 <mountpoint>

left the balance task blocked in D state. SysRq-w reported:

task:btrfs state:D stack:0 pid:8145

  Call Trace:
   <TASK>
   __schedule+0x50e/0xfe0
   schedule+0x22/0xa0
   schedule_preempt_disabled+0x10/0x20
   __mutex_lock.constprop.0+0x380/0x920
   btrfs_inc_block_group_ro+0x6a/0x270 [btrfs]
   do_zone_finish+0x2b6/0x4c0 [btrfs]
   btrfs_zone_finish_one_bg+0x184/0x1f0 [btrfs]
   btrfs_zoned_activate_one_bg+0x189/0x1d0 [btrfs]
   reserve_chunk_space+0xdb/0x180 [btrfs]
   btrfs_inc_block_group_ro+0x252/0x270 [btrfs]
   btrfs_relocate_block_group+0xc2/0x2260 [btrfs]
   btrfs_relocate_chunk+0x39/0x1c0 [btrfs]
   btrfs_balance+0x911/0x1810 [btrfs]
   </TASK>

The blocked balance task also stalls transaction commit and data writers, so the filesystem can no longer make write progress or unmount cleanly.

This happens because the outer btrfs_inc_block_group_ro() holds ro_block_group_mutex while reserve_chunk_space() tries to activate a system block group. When no active-zone slot is available, btrfs_zoned_activate_one_bg() starts finishing a partially written data block group.

do_zone_finish() then enters btrfs_inc_block_group_ro() again. The same task waits for ro_block_group_mutex that it already holds and self-deadlocks.

These allocation-time activation calls were needed for active_total_bytes accounting, which has been removed. Metadata and system block groups can instead be activated during writeback.

Remove both calls and the unused helper. This avoids recursively entering btrfs_inc_block_group_ro() while holding ro_block_group_mutex and leaves activation to the writeback path, where normal metadata and system block group switching is handled.

---
 fs/btrfs/block-group.c | 38 +++++++++-----------------------
 fs/btrfs/zoned.c       | 50 ------------------------------------------
 fs/btrfs/zoned.h       |  8 -------
 3 files changed, 10 insertions(+), 86 deletions(-)
fs/btrfs/block-group.c +10 -28
index a40eedc65dd2..ff108c5de8fa 100644
@@ -3212,13 +3212,6 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
 
 	alloc_flags = btrfs_get_alloc_profile(fs_info, space_info->flags);
 	ret = btrfs_chunk_alloc(trans, space_info, alloc_flags, CHUNK_ALLOC_FORCE);
-	if (ret < 0)
-		goto out;
-	/*
-	 * We have allocated a new chunk. We also need to activate that chunk to
-	 * grant metadata tickets for zoned filesystem.
-	 */
-	ret = btrfs_zoned_activate_one_bg(space_info, true);
 	if (ret < 0)
 		goto out;
 
@@ -4201,29 +4194,18 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,
 		if (IS_ERR(bg)) {
 			ret = PTR_ERR(bg);
 		} else {
-			int activate_ret;
-
 			/*
-			 * We have a new chunk. We also need to activate it for
-			 * zoned filesystem.
+			 * If we fail to add the chunk item here, we end
+			 * up trying again at phase 2 of chunk allocation,
+			 * at btrfs_create_pending_block_groups(). So
+			 * ignore any error here. An ENOSPC here could
+			 * happen, due to the cases described at
+			 * do_chunk_alloc() - the system block group we
+			 * just created was just turned into RO mode by a
+			 * scrub for example, or a running discard
+			 * temporarily removed its free space entries, etc.
 			 */
-			activate_ret = btrfs_zoned_activate_one_bg(info, true);
-			if (activate_ret < 0) {
-				ret = activate_ret;
-			} else {
-				/*
-				 * If we fail to add the chunk item here, we end
-				 * up trying again at phase 2 of chunk allocation,
-				 * at btrfs_create_pending_block_groups(). So
-				 * ignore any error here. An ENOSPC here could
-				 * happen, due to the cases described at
-				 * do_chunk_alloc() - the system block group we
-				 * just created was just turned into RO mode by a
-				 * scrub for example, or a running discard
-				 * temporarily removed its free space entries, etc.
-				 */
-				btrfs_chunk_alloc_add_chunk_item(trans, bg);
-			}
+			btrfs_chunk_alloc_add_chunk_item(trans, bg);
 		}
 	}
 
fs/btrfs/zoned.c +0 -50

56 lines not on this page · raw message

fs/btrfs/zoned.h +0 -8
index 8ed28e47d71b..7db5d5a250ed 100644
@@ -99,7 +99,6 @@ bool btrfs_zoned_should_reclaim(const struct btrfs_fs_info *fs_info);
 void btrfs_zoned_release_data_reloc_bg(struct btrfs_fs_info *fs_info, u64 logical,
 				       u64 length);
 int btrfs_zone_finish_one_bg(struct btrfs_fs_info *fs_info);
-int btrfs_zoned_activate_one_bg(struct btrfs_space_info *space_info, bool do_finish);
 int btrfs_restore_active_nondata_bgs(struct btrfs_fs_info *fs_info);
 int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num_bytes);
 void btrfs_show_zoned_stats(struct btrfs_fs_info *fs_info, struct seq_file *seq);
@@ -279,13 +278,6 @@ static inline int btrfs_zone_finish_one_bg(struct btrfs_fs_info *fs_info)
 	return 1;
 }
 
-static inline int btrfs_zoned_activate_one_bg(struct btrfs_space_info *space_info,
-					      bool do_finish)
-{
-	/* Consider all the block groups are active */
-	return 0;
-}
-
 static inline int btrfs_restore_active_nondata_bgs(struct btrfs_fs_info *fs_info)
 {
 	return 0;
Signature · 1 line
2.39.5
#5 lore raw
In reply to Dongjiang Zhu

Hi Dongjiang,

I wanted to test v4 as well, but I couldn't find a tree it applies to:

- the base commit 7bfc2c517eac is no longer in btrfs for-next (looks like it has been rebased since)
- on current btrfs for-next, patch 1/4 fails to apply in fs/btrfs/zoned.c
- same on your for-next (df5b88a7914e)

Could you push v4 to a branch, or tell me which base to use?

Thanks,
Jochen

Am Mi., 25. Nov. 2026 um 11:21 Uhr schrieb Dongjiang Zhu <[email protected]>:

Quoted 68 lines

This series addresses active-zone accounting and block group transitions on zoned devices. It simplifies conventional-zone handling, restores metadata/system write roles at mount, and addresses a balance self-deadlock and a race during zone finishing.

The four patches:

1. Track only sequential zones as active.
2. Restore the normal metadata and system write roles at mount, keeping one active block group for each role and finishing the remaining active non-data block groups.
3. Remove obsolete allocation-time non-data activation, leaving activation and role switching to the writeback path.
4. Serialize concurrent finish operations on the same block group, keeping it active until the device operations and active-list cleanup complete.

Jochen Philipp tested a rebased version of this series on his filesystem. He reported writing another 2.3 TB via rsync without Btrfs errors, a clean unmount, no errors from btrfs check --readonly, and a successful read-write mount afterwards. Many thanks to Jochen for the extensive testing.

Changes in v4:
- Rebased onto btrfs for-next at 7bfc2c517eac.
- Retained the upstream active-zone bitmap check for mount-time reservation accounting and the conditional reservation updates during activation and finishing.
- Moved abandoned-tail accounting into do_zone_finish(), alongside the alloc_offset update, preserving read-only block group accounting.
- Removed the unnecessary temporary block group references in mount-time cleanup.
- Updated the commit messages to reflect the current base and clarify the role-recovery and zone-finishing behavior.

Changes in v3:
- Dropped the block-group flag comment changes from patch 1; no functional changes.

Changes in v2:
- Removed the [BUG], [CAUSE] and [FIX] headings from the commit messages.
- Added a helper for identifying zones that need active-zone tracking.
- Added block group locking around alloc_offset and zone_unusable accesses during mount recovery.
- Explained why moving the active-bit clear alone does not serialize concurrent zone finish operations.

Previous versions:
v3: https://lore.kernel.org/linux-btrfs/[email protected]/
v2: https://lore.kernel.org/linux-btrfs/[email protected]/
v1: https://lore.kernel.org/linux-btrfs/[email protected]/

Dongjiang Zhu (4):
btrfs: zoned: track only sequential zones as active
btrfs: zoned: recover active non-data block group roles on mount
btrfs: zoned: remove obsolete non-data block group activation helper
btrfs: zoned: serialize zone finishing per block group

 fs/btrfs/block-group.c |  38 ++------
 fs/btrfs/block-group.h |   1 +
 fs/btrfs/disk-io.c     |   7 +-
 fs/btrfs/zoned.c       | 211 +++++++++++++++++++++++++++++------------
 fs/btrfs/zoned.h       |   9 +-
 5 files changed, 167 insertions(+), 99 deletions(-)

--
2.39.5