Commit 5a7d107e authored by Naohiro Aota's avatar Naohiro Aota Committed by David Sterba
Browse files

btrfs: zoned: don't activate non-DATA BG on allocation



Now that a non-DATA block group is activated at write time, don't
activate it on allocation time.

Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 6a8ebc77
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4089,7 +4089,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,

	if (IS_ERR(ret_bg)) {
		ret = PTR_ERR(ret_bg);
	} else if (from_extent_allocation) {
	} else if (from_extent_allocation && (flags & BTRFS_BLOCK_GROUP_DATA)) {
		/*
		 * New block group is likely to be used soon. Try to activate
		 * it now. Failure is OK for now.
+7 −1
Original line number Diff line number Diff line
@@ -3690,7 +3690,9 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group,
	}
	spin_unlock(&block_group->lock);

	if (!ret && !btrfs_zone_activate(block_group)) {
	/* Metadata block group is activated at write time. */
	if (!ret && (block_group->flags & BTRFS_BLOCK_GROUP_DATA) &&
	    !btrfs_zone_activate(block_group)) {
		ret = 1;
		/*
		 * May need to clear fs_info->{treelog,data_reloc}_bg.
@@ -3866,6 +3868,10 @@ static void found_extent(struct find_free_extent_ctl *ffe_ctl,
static int can_allocate_chunk_zoned(struct btrfs_fs_info *fs_info,
				    struct find_free_extent_ctl *ffe_ctl)
{
	/* Block group's activeness is not a requirement for METADATA block groups. */
	if (!(ffe_ctl->flags & BTRFS_BLOCK_GROUP_DATA))
		return 0;

	/* If we can activate new zone, just allocate a chunk and use it */
	if (btrfs_can_activate_zone(fs_info->fs_devices, ffe_ctl->flags))
		return 0;
+0 −28
Original line number Diff line number Diff line
@@ -761,18 +761,6 @@ static void flush_space(struct btrfs_fs_info *fs_info,
		break;
	case ALLOC_CHUNK:
	case ALLOC_CHUNK_FORCE:
		/*
		 * For metadata space on zoned filesystem, reaching here means we
		 * don't have enough space left in active_total_bytes. Try to
		 * activate a block group first, because we may have inactive
		 * block group already allocated.
		 */
		ret = btrfs_zoned_activate_one_bg(fs_info, space_info, false);
		if (ret < 0)
			break;
		else if (ret == 1)
			break;

		trans = btrfs_join_transaction(root);
		if (IS_ERR(trans)) {
			ret = PTR_ERR(trans);
@@ -784,22 +772,6 @@ static void flush_space(struct btrfs_fs_info *fs_info,
					CHUNK_ALLOC_FORCE);
		btrfs_end_transaction(trans);

		/*
		 * For metadata space on zoned filesystem, allocating a new chunk
		 * is not enough. We still need to activate the block * group.
		 * Active the newly allocated block group by (maybe) finishing
		 * a block group.
		 */
		if (ret == 1) {
			ret = btrfs_zoned_activate_one_bg(fs_info, space_info, true);
			/*
			 * Revert to the original ret regardless we could finish
			 * one block group or not.
			 */
			if (ret >= 0)
				ret = 1;
		}

		if (ret > 0 || ret == -ENOSPC)
			ret = 0;
		break;