From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=46.30.189.100 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795959124; b=rEjgO8/Szg+lF2mpRHNmOB9JCNSa/WzQFNJGnKzmuMPllVxZV6mB/xFM9M3mLGembUh2 caVVhlflhr+NlmcOCL1Zg4FAjy07xoTsjybG14gF+lZih+yGy8IvIQheKqmj29kASMH6A nCk5GnSaRZ5Vip7lftw2kOqP4h0r+aR1/n2CIkxvK6Nm2kKP/x0QE5bNw2MwkSTiM7sgO v7/6gDzd6r0r51TutMuJfXUbuCx/6UFSiqx94s9zbDgMDxJWGl5tIqOgH8t3FlaFb+KMd AZHqMWN3VsJ+G1i1Pq5PV/AmFLHLJI0/hsUaMlTQK1Xaz4WzErBEYJ3ajrzJRdkOOQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795959124; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ewhM8/dUDVdnWKxc3scfGam5bysoTL5Yi41Gbg7Xw9Q=; b=K+NYsUHskNH6SauBhwuA7bQpZdbkAwLNG7Y7r+fysNGwb7qw+m/hXPcNOLO6w7LqN+S/ eKyN9nf1VLolSS4a7K4paCFK1G+cQJtgvWZJ1bp7O4lmj4fw/Tfu9AXwbxkxTo8yraWG+ ew7oTEP4Yo4RJrRPODpVT8MgLILC8Yz/Dg5VOvK0lrETGqbyn7U8c/HKn41NQULT1J+pp 9+EQVYk0WW+GPL12GeC4lZihULl1AlVoSQr8g3B1SYNT1dqxQIOMBbxXQe+WF7Uzvuz6I K2tOwVK97J6G+nTIirYCm56WMUoIkdDtgvra/vqDZjL11QKX7JMsI3wkorl9jFG6gVQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=iodev.co.uk; spf=pass smtp.mailfrom=iodev.co.uk; arc=none smtp.remote-ip=46.30.189.100 Received: from iodev.co.uk (iodev.co.uk [46.30.189.100]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AC7F606A31C; Sun, 29 Nov 2026 13:32:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3AC7F606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=iodev.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iodev.co.uk Received: from localhost (unknown [79.116.217.174]) by iodev.co.uk (Postfix) with ESMTPSA id E4A3F5F0BA7; Sun, 29 Nov 2026 14:32:00 +0100 (CET) From: Ismael Luceno To: linux-btrfs@vger.kernel.org, David Sterba , Chris Mason Cc: Ismael Luceno , linux-kernel@vger.kernel.org, Qu Wenruo , Anand Jain , Filipe Manana Subject: [PATCH 6/6] btrfs: derive relocation group length from its members Date: Sun, 29 Nov 2026 14:31:19 +0100 Message-ID: <20261129133125.3293-7-ismael@iodev.co.uk> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261129133125.3293-1-ismael@iodev.co.uk> References: <20261129133125.3293-1-ismael@iodev.co.uk> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A relocation group is the set of members that share one allocation. Its length was stored per member, and cluster_add_member() copied the same value into every member of the group. Nothing needs a stored value: the length is the sum of the members' lengths, and prealloc can compute it when it issues the group. Compute the group length in prealloc_file_extent_cluster() and the cluster's allocation size from the members. No behaviour changes. This lets the next change grow a group past the extents it started with. Signed-off-by: Ismael Luceno --- fs/btrfs/relocation.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 9bf0f9bc794c4..3b6dd9f9ec7e0 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -139,10 +139,9 @@ struct file_extent_cluster { u64 data_offset[MAX_EXTENTS]; /* * Consecutive members with the same group_start are segments of one old - * extent. They share one allocation of group_len bytes. + * extent. They share one allocation, as big as the sum of their lengths. */ u64 group_start[MAX_EXTENTS]; - u64 group_len[MAX_EXTENTS]; unsigned int nr; u64 owning_root; }; @@ -2837,8 +2836,7 @@ static u64 cluster_allocation_bytes(const struct file_extent_cluster *cluster) unsigned int i; for (i = 0; i < cluster->nr; i++) - if (i == 0 || cluster->group_start[i] != cluster->group_start[i - 1]) - total += cluster->group_len[i]; + total += cluster->member_end[i] + 1 - cluster->boundary[i]; return total; } @@ -2887,7 +2885,7 @@ static noinline_for_stack int prealloc_file_extent_cluster(struct reloc_control unsigned int last = nr; unsigned int n = 0; u64 group = cluster->group_start[nr]; - u64 group_len = cluster->group_len[nr]; + u64 group_len = 0; u64 lock_end; unsigned int i; @@ -2898,6 +2896,7 @@ static noinline_for_stack int prealloc_file_extent_cluster(struct reloc_control pieces[n].data_offset = cluster->data_offset[i]; pieces[n].len = cluster->member_end[i] + 1 - cluster->boundary[i]; + group_len += pieces[n].len; n++; } lock_end = pieces[n - 1].file_start + pieces[n - 1].len - 1; @@ -3387,7 +3386,7 @@ static int cluster_begin_group(struct reloc_control *rc, u64 start, /* Append one referenced range to the cluster as a member. */ static void cluster_add_member(struct reloc_control *rc, u64 start, u64 len, - u64 group_start, u64 group_len, u64 data_offset) + u64 group_start, u64 data_offset) { struct file_extent_cluster *cluster = &rc->cluster; unsigned int nr = cluster->nr; @@ -3402,7 +3401,6 @@ static void cluster_add_member(struct reloc_control *rc, u64 start, u64 len, cluster->member_end[nr] = start + len - 1; cluster->data_offset[nr] = data_offset; cluster->group_start[nr] = group_start; - cluster->group_len[nr] = group_len; cluster->nr++; } @@ -3440,20 +3438,16 @@ static noinline_for_stack int relocate_data_extent(struct reloc_control *rc, for (i = 0; i < es.nr; ) { unsigned int count = min_t(unsigned int, es.nr - i, MAX_EXTENTS); u64 group_start = start + es.segs[i].offset; - u64 group_len = 0; u64 data_offset = 0; unsigned int j; - for (j = i; j < i + count; j++) - group_len += es.segs[j].len; - ret = cluster_begin_group(rc, group_start, count); if (ret) goto out; for (j = i; j < i + count; j++) { cluster_add_member(rc, start + es.segs[j].offset, - es.segs[j].len, group_start, group_len, + es.segs[j].len, group_start, data_offset); data_offset += es.segs[j].len; } -- 2.56.0