mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ismael Luceno <ismael@iodev.co.uk>
To: linux-btrfs@vger.kernel.org, David Sterba <dsterba@suse.com>,
	Chris Mason <mason@kernel.org>
Cc: Ismael Luceno <ismael@iodev.co.uk>,
	linux-kernel@vger.kernel.org, Qu Wenruo <wqu@suse.com>,
	Anand Jain <asj@kernel.org>, Filipe Manana <fdmanana@suse.com>
Subject: [PATCH 0/6] btrfs: trim unused space when relocating data extents
Date: Sun, 29 Nov 2026 14:31:13 +0100	[thread overview]
Message-ID: <20261129133125.3293-1-ismael@iodev.co.uk> (raw)

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


             reply	other threads:[~2026-11-29 13:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 13:31 Ismael Luceno [this message]
2026-11-29 13:31 ` [PATCH 1/6] btrfs: add prealloc helper for sharing one allocation Ismael Luceno
2026-11-29 13:31 ` [PATCH 2/6] btrfs: allow NOCOW writeback into data relocation extents Ismael Luceno
2026-11-29 13:31 ` [PATCH 3/6] btrfs: relocate only referenced bytes of a data extent Ismael Luceno
2026-11-29 13:31 ` [PATCH 4/6] btrfs: scan the running transaction for data extent references Ismael Luceno
2026-11-29 13:31 ` [PATCH 5/6] btrfs: retry a block group that references survive the update stage Ismael Luceno
2026-11-29 13:31 ` [PATCH 6/6] btrfs: derive relocation group length from its members Ismael Luceno
2026-11-29 21:00 ` [PATCH 0/6] btrfs: trim unused space when relocating data extents Qu Wenruo

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=20261129133125.3293-1-ismael@iodev.co.uk \
    --to=ismael@iodev.co.uk \
    --cc=asj@kernel.org \
    --cc=dsterba@suse.com \
    --cc=fdmanana@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=wqu@suse.com \
    /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

all inboxes | Powered by JetHome®