From: "Denis V. Lunev" <den@openvz.org>
To: khorenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 v2 0/3] ext4, xfs: discard the balloon on FITRIM
Date: Tue, 10 Nov 2026 23:27:52 +0100 [thread overview]
Message-ID: <20261110222756.3236854-1-den@openvz.org> (raw)
The balloon holds filesystem space that never carries data, but its
blocks are allocated, so FITRIM walks past them, and inflating the
balloon is a plain fallocate() that does not discard either. Once the
balloon is inflated over the blocks of removed files, e.g. on an online
shrink of a Container disk, the ploop or qcow2 image keeps those
clusters mapped for good, and compaction, which is FITRIM, does not
give them back (VSTOR-153590).
This series makes FITRIM discard the unwritten extents of the balloon
after the free space, on ext4 (patch 2) and xfs (patch 3). The walk
holds the inode locks of the balloon exclusively, after waiting for
direct I/O and flushing its page cache, as punch hole does, so no block
can be freed, reused or written under the discard. Physically adjacent
extents are merged, so that the device below gets whole clusters, and
a long run is discarded in interruptible chunks. A balloon inflated
before this series is released by the next FITRIM, no userspace change
is needed. Patch 1 fixes an inode reference leak in xfs_balloon_get()
that FITRIM would now hit too.
The ploop side is openvz/ploop.ovz PR 519: tests for this, and fixes of
the ploop-balloon discard options found on the way:
https://bitbucket.org/openvz/ploop.ovz/pull-requests/519
Changes since v1
(https://lore.virtuozzo.com/kernel/20261110212459.3158424-1-den@openvz.org/):
- take the balloon inode locks exclusively, wait for direct I/O and
flush the page cache before the walk; v1 held the shared lock, which
did not keep writeback and direct I/O from converting an extent the
walk had seen unwritten (Sashiko);
- walk to the end of the file instead of i_size, as fallocate() with
FALLOC_FL_KEEP_SIZE can leave unwritten extents past it (Sashiko);
- discard a merged run in chunks aligned to the discard granularity,
checking for fatal signals and freezing between them;
- drop the read-only mount skip: ploop does not set balloon_ino on a
read-only mount, and the free space pass does not skip one either;
- ext4: do not count the balloon in the trimmed length, so fstrim -v no
longer reports it as freed on every call; no 64-bit division on
i_size any more (Sashiko);
- xfs: fail FITRIM on an error reading the balloon inode, use
GFP_KERNEL, and fix the xfs_balloon_get() leak in patch 1 (Sashiko);
- every FITRIM still discards the balloon again: neither filesystem
bumps a counter on fallocate() of the balloon that a skip could rely
on, and a wrong skip would leave clusters mapped for good, while a
repeated discard of unmapped clusters is cheap.
Tested on 6.12.0-211.52.1.22.19.vz10 rebuilt with this series and the
VSTOR-154159 max_discard_segments fixes:
- ploop and qcow2 images with ext4 and xfs: write 2G, remove it without
a trim, inflate the balloon over the free space, ploop-balloon
discard. Stock: the image keeps mapping the removed 2G. Patched: the
image maps about as much as when it was created, a kept file is
intact, fsck and ploop check / qemu-img check are clean;
- 16G removed under a balloon of about 38G: a full fstrim takes under
3 seconds, a SIGKILL one second into it ends fstrim at once, a
repeated fstrim takes a fraction of a second, fsck is clean;
- test_ploop_balloon.py from PR 519: green on ploop and qcow2. On the
stock kernel only the tests for the space under the balloon fail.
Not covered: ext4 bigalloc, a realtime xfs balloon (skipped). On ploop1
discard works on whole clusters, so up to two clusters at the ends of
each contiguous piece of the balloon stay mapped, as do pieces shorter
than the FITRIM minimum length.
Denis V. Lunev (3):
xfs: release the balloon inode when xfs_balloon_get() refuses it
ext4: discard the balloon on FITRIM
xfs: discard the balloon on FITRIM
fs/ext4/mballoc.c | 126 +++++++++++++++++++++++++++++++++++++
fs/xfs/xfs_discard.c | 144 +++++++++++++++++++++++++++++++++++++++++++
fs/xfs/xfs_super.c | 4 +-
3 files changed, 273 insertions(+), 1 deletion(-)
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next reply other threads:[~2026-11-10 22:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 22:27 Denis V. Lunev [this message]
2026-11-10 22:27 ` [Devel] [PATCH hci-8.1 v2 1/3] xfs: release the balloon inode when xfs_balloon_get() refuses it Denis V. Lunev
2026-11-10 22:31 ` no-reply
2026-11-10 22:27 ` [Devel] [PATCH hci-8.1 v2 2/3] ext4: discard the balloon on FITRIM Denis V. Lunev
2026-11-10 22:35 ` no-reply
2026-11-10 22:27 ` [Devel] [PATCH hci-8.1 v2 3/3] xfs: " Denis V. Lunev
2026-11-10 22:36 ` no-reply
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=20261110222756.3236854-1-den@openvz.org \
--to=den@openvz.org \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.