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=1795959098; b=0UnReXFwBauyv/ZmdmbOWwuNCPVEscI/9nJbJp6lkcv5ZXXdchqwrWkoFFZyiM4YreSm g7rV0B1hFSiNKfiFO4s3kleaXQvFT2atqTznR9jbTR/viWrNgs0yHl4/F4obHdxHYEaMG Z5Wrta4bJDgNpkOOyO+sskT7iGP2AULLVrYZKDbOPhIhzOpsqz8sTeZziYjcL9wF7h0k+ jDugbFdP0jB8/z8MuQUn4Qnfs+EAv8fvTRRfasQa8mE77cGwtiB4TrealK1xTfPpBdP86 jPMXbrWN/+Laa1hZ9jmgRQ4dWn52LWVXTWq/yGaV9JLH8coHUgYtr+3iQ7JPDbLNFGw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795959098; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=1gLPexx677S6chWjzdleeEOVpWiiNIgSd1BZOa2uOBY=; b=JbAFgjF59n6dP2GknRbifkf9dK9LK2M7+oGVpNKjE1QVdyU527VFxQTDm+oN2dwTIlQM RSH9zNOUuXGpeXUl5WmHsZ9AN4FeGjNVuoPjR0126FdfBVRpnVsJT7BKjt6QF54YI81GY dy5q4uekvC1hqNHiBZC3lc+F/3jHich1bXrVGt9wAC6KfYXeifj8X7Q/NIMq264zDkwvw W97flgfqPzica423HG+aC/KmP0YX64z/401fQLAXza4vCcPQ/aHFaWeGRtG18rD5eaKYv ipZ8JA4LPjoMZ8ihd3AqYYtzFLdFQeiAmjJwnRpivSiR7dXbW54TrZUwOZpP25u+LCg== 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 EBA21606A31C; Sun, 29 Nov 2026 13:31:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EBA21606A31C 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 906985F0B94; Sun, 29 Nov 2026 14:31:27 +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 0/6] btrfs: trim unused space when relocating data extents Date: Sun, 29 Nov 2026 14:31:13 +0100 Message-ID: <20261129133125.3293-1-ismael@iodev.co.uk> X-Mailer: git-send-email 2.56.0 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 data balance copies every data extent whole, including bytes that no file references. Those dead bytes stay allocated, and an overwritten file keeps its old extents until every reference to them is gone. This series copies only the referenced bytes. For each old extent, the referenced ranges are collected and laid out in one new allocation, and each file extent is remapped to its own range. Dead bytes are not copied, so they are freed with the old block group. Patches 2-6 support this change: a helper that preallocates one allocation for several file extents, NOCOW writeback into relocation extents, a scan of the running transaction for references, a retry for references that survive the update stage, and a group length derived from its members. Testing Measured in QEMU guests, one run per kernel. Base is f2805cb. Series is this six-patch series. Every run passed btrfs check. Timings are not reported, because they varied more between runs than between kernels. - Holes: a 64 MiB extent with 16 dead 1 MiB holes, then a balance. Data used 80 MiB -> 64 MiB (base -> series). Extents stay at 33. - Random overwrites: a 256 MiB file with 600 random 4 KiB overwrites, then a balance. Data used 258.32 MiB -> 258.32 MiB (base) and 258.32 MiB -> 256.00 MiB (series). - Read: a 64 MiB file written as 32 2 MiB chunks with 1 MiB overwritten in the middle of each, then a direct sequential read. Device read requests 136 -> 136 (base) and 136 -> 134 (series). - Overhead: the same layout, a balance, then a rewrite of the first 80%. Whole extent bytes are the distinct on-disk extents the file references, at full size. Overhead is whole minus referenced (64 MiB). Base: whole 96 -> 96 -> 72 MiB; overhead 32 -> 32 -> 8 MiB (write, balance, rewrite) Series: whole 96 -> 64 -> 65 MiB; overhead 32 -> 0 -> 1 MiB Metadata after the balance: base 288 KiB, series 240 KiB. - xfstests: the existing trim test passes on the series. The new tests in the xfstests series (btrfs/361-363) pass on the series with zero bytes left beyond the file size, and fail on base with 16 MiB, 2.33 MiB and 8 MiB left. The three tests are sent to fstests@vger.kernel.org as a separate series, submitted together with this one: "[PATCH 0/3] btrfs: test that balance frees dead bytes of data extents". Ismael Luceno (6): btrfs: add prealloc helper for sharing one allocation btrfs: allow NOCOW writeback into data relocation extents btrfs: relocate only referenced bytes of a data extent btrfs: scan the running transaction for data extent references btrfs: retry a block group that references survive the update stage btrfs: derive relocation group length from its members fs/btrfs/btrfs_inode.h | 14 ++ fs/btrfs/inode.c | 182 ++++++++++++++- fs/btrfs/relocation.c | 505 ++++++++++++++++++++++++++++++++++------- 3 files changed, 613 insertions(+), 88 deletions(-) -- 2.56.0