* [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM
@ 2026-11-11 11:31 Denis V. Lunev
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 1/5] ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM Denis V. Lunev
` (6 more replies)
0 siblings, 7 replies; 18+ messages in thread
From: Denis V. Lunev @ 2026-11-11 11:31 UTC (permalink / raw)
To: khorenko; +Cc: devel
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 4) and xfs (patch 5). 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 3 fixes an inode reference leak in xfs_balloon_get()
that FITRIM would now hit too.
Patches 1 and 2 are mainline fixes of the xfs FITRIM free space walk,
merged for 7.4-rc2 with Cc: stable. hci-8.1 carries the RHEL backport
of b0ffe661fab4 ("xfs: fix performance problems when fstrimming a
subset of a fragmented AG") and has both bugs. The ploop tests ran into
the second one: of several free extents of the longest length in an AG
only one is discarded, so whether FITRIM gives the space back depends
on where xfs put the files. The first one makes later batches of a
whole-AG walk skip the free extents below the block they restart from.
The ploop side is a stack of openvz/ploop.ovz PRs, 523, 520, 521 and
519. PR 519 holds the tests for this series and goes in after it:
https://bitbucket.org/openvz/ploop.ovz/pull-requests/519
Changes since v2
(https://lore.virtuozzo.com/kernel/20261110222756.3236854-1-den@openvz.org/):
- add the mainline xfs FITRIM fixes as patches 1 and 2;
- skip an empty balloon before taking its locks. A non-empty one is
still walked whole on every FITRIM, whatever the range; the notes in
patches 4 and 5 say why (Sashiko);
- xfs: convert minlen to sectors in 64 bits (Sashiko).
Tested on 6.12.0-211.52.1.22.19.vz10 rebuilt with this series and the
VSTOR-154159 max_discard_segments fixes:
- test_ploop_balloon.py of PR 519 on ploop and qcow2 images with ext4
and xfs is green, dmesg is clean. It covers discarding the space under
a balloon inflated over removed data, deflating it and writing over
it, online and offline shrink, and free runs a few clusters long
released by a default discard. The xfs case of the last one fails on
v2 of this series, without patches 1 and 2, on both image formats;
- the fstrim time and SIGKILL checks of v2 were not repeated: the walk
itself did not change.
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.
Daejun Park (2):
ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM
ms/xfs: don't skip free extents of the longest length in a whole-AG
FITRIM
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 | 170 +++++++++++++++++++++++++++++++++++++++++--
fs/xfs/xfs_super.c | 4 +-
3 files changed, 291 insertions(+), 9 deletions(-)
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Devel] [PATCH hci-8.1 v3 1/5] ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM
2026-11-11 11:31 [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM Denis V. Lunev
@ 2026-11-11 11:31 ` Denis V. Lunev
2026-11-11 11:35 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 2/5] ms/xfs: don't skip free extents of the longest length in " Denis V. Lunev
` (5 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Denis V. Lunev @ 2026-11-11 11:31 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Daejun Park <daejun7.park@samsung.com>
A whole-device FITRIM walks every AG but the last by length, in
batches. xfs_trim_gather_extents() saves the record to restart from in
tcur->start. But tcur->start is also the start of the range to trim.
Later batches therefore never discard the free extents below that
block.
Save the restart record in a new restart_bno field.
Cc: stable@vger.kernel.org # v6.10
Fixes: b0ffe661fab4 ("xfs: fix performance problems when fstrimming a subset of a fragmented AG")
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
(cherry picked from commit 595e67d7261673d03c96950ffbb2e545c00376ed)
https://virtuozzo.atlassian.net/browse/VSTOR-153590
Feature: fix ms/xfs
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
Notes:
A clean cherry-pick of mainline 595e67d72616 (v7.4-rc2), no changes.
hci-8.1 has the RHEL backport of b0ffe661fab4 it fixes.
fs/xfs/xfs_discard.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index 93943e698eea..41c98f9abde1 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -181,6 +181,8 @@ struct xfs_trim_cur {
xfs_agblock_t end;
xfs_extlen_t minlen;
bool by_bno;
+ /* restart point (with count) for the by-length walk */
+ xfs_agblock_t restart_bno;
};
static int
@@ -226,14 +228,15 @@ xfs_trim_gather_extents(
error = xfs_alloc_lookup_le(cur, tcur->start, 0, &i);
if (!error && !i)
error = xfs_alloc_lookup_ge(cur, tcur->start, 0, &i);
- } else if (tcur->start == 0) {
+ } else if (tcur->restart_bno == NULLAGBLOCK) {
/* first time through a by-len starts with max length */
cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag);
error = xfs_alloc_lookup_ge(cur, 0, tcur->count, &i);
} else {
/* nth time through a by-len starts where we left off */
cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag);
- error = xfs_alloc_lookup_le(cur, tcur->start, tcur->count, &i);
+ error = xfs_alloc_lookup_le(cur, tcur->restart_bno,
+ tcur->count, &i);
}
if (error)
goto out_del_cursor;
@@ -263,9 +266,15 @@ xfs_trim_gather_extents(
if (--batch <= 0) {
/*
* Update the cursor to point at this extent so we
- * restart the next batch from this extent.
+ * restart the next batch from this extent. The
+ * by-length walk does not visit extents in block
+ * order, so it must keep the start of the range and
+ * restart from restart_bno instead.
*/
- tcur->start = fbno;
+ if (tcur->by_bno)
+ tcur->start = fbno;
+ else
+ tcur->restart_bno = fbno;
tcur->count = flen;
break;
}
@@ -368,6 +377,7 @@ xfs_trim_perag_extents(
.start = start,
.end = end,
.minlen = minlen,
+ .restart_bno = NULLAGBLOCK,
};
int error = 0;
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Devel] [PATCH hci-8.1 v3 2/5] ms/xfs: don't skip free extents of the longest length in a whole-AG FITRIM
2026-11-11 11:31 [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM Denis V. Lunev
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 1/5] ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM Denis V. Lunev
@ 2026-11-11 11:31 ` Denis V. Lunev
2026-11-11 11:35 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 3/5] xfs: release the balloon inode when xfs_balloon_get() refuses it Denis V. Lunev
` (4 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Denis V. Lunev @ 2026-11-11 11:31 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Daejun Park <daejun7.park@samsung.com>
Since commit a66d636385d6 ("xfs: fix fstrim offset calculations"), the
by-length walk of an AG in FITRIM starts with
xfs_alloc_lookup_ge(cur, 0, pagf_longest) and walks down. The lookup
lands on the longest free extent with the lowest block number. The
other free extents of that length sort after it and are never
discarded.
Start every by-length batch with xfs_alloc_lookup_le() at restart_bno.
Suggested-by: Dave Chinner <dgc@kernel.org>
Link: https://lore.kernel.org/r/ZgiJWxVcVwag0fIP@dread.disaster.area
Cc: stable@vger.kernel.org
Fixes: a66d636385d6 ("xfs: fix fstrim offset calculations")
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
(cherry picked from commit 5745f4f10a1a16aa5bb020acc38afa33f2d5ff99)
https://virtuozzo.atlassian.net/browse/VSTOR-153590
Feature: fix ms/xfs
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
Notes:
A clean cherry-pick of mainline 5745f4f10a1a (v7.4-rc2) on top of
patch 1, no changes. This is the bug the ploop tests hit on xfs: one of
several free extents of the longest length discarded.
fs/xfs/xfs_discard.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index 41c98f9abde1..a6c43e4fdec3 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -228,12 +228,12 @@ xfs_trim_gather_extents(
error = xfs_alloc_lookup_le(cur, tcur->start, 0, &i);
if (!error && !i)
error = xfs_alloc_lookup_ge(cur, tcur->start, 0, &i);
- } else if (tcur->restart_bno == NULLAGBLOCK) {
- /* first time through a by-len starts with max length */
- cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag);
- error = xfs_alloc_lookup_ge(cur, 0, tcur->count, &i);
} else {
- /* nth time through a by-len starts where we left off */
+ /*
+ * A by-len walk starts at the last record of the longest
+ * length (restart_bno is NULLAGBLOCK until the first batch
+ * ends) and then where the previous batch stopped.
+ */
cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag);
error = xfs_alloc_lookup_le(cur, tcur->restart_bno,
tcur->count, &i);
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Devel] [PATCH hci-8.1 v3 3/5] xfs: release the balloon inode when xfs_balloon_get() refuses it
2026-11-11 11:31 [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM Denis V. Lunev
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 1/5] ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM Denis V. Lunev
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 2/5] ms/xfs: don't skip free extents of the longest length in " Denis V. Lunev
@ 2026-11-11 11:31 ` Denis V. Lunev
2026-11-11 11:35 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 4/5] ext4: discard the balloon on FITRIM Denis V. Lunev
` (3 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Denis V. Lunev @ 2026-11-11 11:31 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Denis V. Lunev <den@openvz.org>
xfs_balloon_get() looks the balloon inode up with xfs_iget() and returns
-EINVAL when it is not a regular file or is immutable, without
releasing the reference it took. Every statfs and every open of the
balloon then leaks a reference on such an inode, which the VFS reports
as a busy inode at unmount.
Release the inode before returning -EINVAL.
https://virtuozzo.atlassian.net/browse/VSTOR-153590
Feature: fs/xfs: fast online shrink support
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
Notes:
Unchanged since v2.
fs/xfs/xfs_super.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index d24ceb045364..6deab3e5d76c 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -924,8 +924,10 @@ xfs_balloon_get(struct xfs_mount *mp, u64 balloon_ino, uint flags)
if (error)
return ERR_PTR(error);
inode = VFS_I(ip);
- if (!S_ISREG(inode->i_mode) || IS_IMMUTABLE(inode))
+ if (!S_ISREG(inode->i_mode) || IS_IMMUTABLE(inode)) {
+ xfs_irele(ip);
return ERR_PTR(-EINVAL);
+ }
return ip;
}
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Devel] [PATCH hci-8.1 v3 4/5] ext4: discard the balloon on FITRIM
2026-11-11 11:31 [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM Denis V. Lunev
` (2 preceding siblings ...)
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 3/5] xfs: release the balloon inode when xfs_balloon_get() refuses it Denis V. Lunev
@ 2026-11-11 11:31 ` Denis V. Lunev
2026-11-11 11:40 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 5/5] xfs: " Denis V. Lunev
` (2 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Denis V. Lunev @ 2026-11-11 11:31 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Denis V. Lunev <den@openvz.org>
The balloon holds file system space that never carries data, but its
blocks are allocated, so ext4_trim_all_free() never discards them, and
inflating the balloon is a plain fallocate() that does not discard
either. Once the balloon is inflated over blocks that held data, e.g.
on an online shrink after files were removed, the device below keeps
them allocated: a ploop or qcow2 image keeps host disk space the
container can never use, and compaction, which is FITRIM, does not give
it back.
Walk the balloon after the free space in ext4_trim_fs() and discard its
unwritten extents that fall into the requested range. The walk goes to
the end of the extent tree, as fallocate() with FALLOC_FL_KEEP_SIZE can
leave extents past i_size. Physically adjacent extents are merged into
one discard, otherwise every cut at the unwritten extent length limit
leaves a partly covered cluster of the image below. A merged run is
discarded in chunks, with a check for fatal signals and freezing
between them.
The walk holds i_rwsem and the invalidate lock exclusively, after
waiting for direct I/O and flushing the page cache of the balloon, as
punch hole does. No block of the balloon can be freed and reused under
the discard, and nothing is written to it meanwhile, so an extent that
is still unwritten reads as zeroes before and after the discard. The
balloon is hidden from lookup and opened only through
EXT4_IOC_OPEN_BALLOON, which takes CAP_SYS_ADMIN, so the lock only
waits for ploop inflating or shrinking it.
An empty balloon is skipped before taking the locks. Any other one is
walked whole on every FITRIM, whatever range it asks for, as its
extent tree is indexed by file offset; FITRIM is rare enough for that.
Discarding the balloon again each time is cheap: dm-ploop completes
the discard of an unmapped cluster at once.
The balloon is not counted in the trimmed length reported to
userspace, and a discard error fails FITRIM.
A balloon inflated before this change is released by the next FITRIM.
https://virtuozzo.atlassian.net/browse/VSTOR-153590
Feature: fs/ext4: fast online shrink support
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
Notes:
The balloon is locked, flushed and walked whole on every FITRIM,
whatever the range. This is deliberate: ploop runs FITRIM on
compaction, about once a day. Measured on a 4-CPU VM with a balloon of
84-99G over all the free space of a 100G image: a FITRIM after the
first one spends 0.3-0.7s in the balloon, on ploop and qcow2, ext4 and
xfs, for a contiguous balloon and for one in up to about 10000 pieces.
The time goes mostly into discarding clusters that are already unmapped
and grows with the size of the balloon and the number of its pieces.
The locks held meanwhile only keep ploop from resizing the balloon.
Narrowing the walk to the range would need a reverse map from blocks to
file offsets. An empty balloon, the common case, is skipped before the
locks are taken.
fs/ext4/mballoc.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index aaf2c24c514c..4906f49353bf 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -7009,6 +7009,126 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
return ret;
}
+#define EXT4_BALLOON_DISCARD_CHUNK (128U << 20)
+
+static int ext4_trim_balloon_run(struct super_block *sb, ext4_fsblk_t pblk,
+ ext4_fsblk_t len, ext4_fsblk_t start,
+ ext4_fsblk_t end, ext4_fsblk_t minblocks)
+{
+ unsigned int gran = max_t(unsigned int, 1,
+ bdev_discard_granularity(sb->s_bdev) >> sb->s_blocksize_bits);
+ unsigned int chunk = roundup(EXT4_BALLOON_DISCARD_CHUNK >>
+ sb->s_blocksize_bits, gran);
+ ext4_fsblk_t last = pblk + len - 1, next;
+ int ret;
+
+ if (!len)
+ return 0;
+ if (pblk < start)
+ pblk = start;
+ if (last > end)
+ last = end;
+ if (last < pblk || last - pblk + 1 < minblocks)
+ return 0;
+
+ /*
+ * Chunks keep a long run interruptible. They end on multiples of the
+ * discard granularity, so no cluster below is split between two.
+ */
+ while (pblk <= last) {
+ u64 rem = pblk;
+
+ next = pblk + chunk - do_div(rem, chunk);
+ if (next > last + 1)
+ next = last + 1;
+ trace_ext4_discard_blocks(sb, pblk, next - pblk);
+ ret = sb_issue_discard(sb, pblk, next - pblk, GFP_NOFS, 0);
+ if (ret)
+ return ret;
+ pblk = next;
+ if (ext4_trim_interrupted())
+ break;
+ cond_resched();
+ }
+
+ return 0;
+}
+
+/*
+ * Blocks of the balloon never hold data, but they are allocated, so
+ * ext4_trim_all_free() never discards them. Discard its unwritten
+ * extents, merging physically adjacent ones, so that the device below
+ * can release the space as it does for free blocks.
+ */
+static int ext4_trim_balloon(struct super_block *sb, ext4_fsblk_t start,
+ ext4_fsblk_t end, ext4_fsblk_t minblocks)
+{
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+ ext4_fsblk_t run_pblk = 0, run_len = 0;
+ struct ext4_map_blocks map;
+ struct inode *inode = NULL;
+ ext4_lblk_t lblk;
+ bool unwritten;
+ int ret, err;
+
+ /* ext4_load_balloon() replaces s_balloon_ino under s_umount */
+ down_read(&sb->s_umount);
+ if (sbi->s_balloon_ino && sbi->s_balloon_ino->i_blocks)
+ inode = igrab(sbi->s_balloon_ino);
+ up_read(&sb->s_umount);
+ if (!inode)
+ return 0;
+
+ /*
+ * Nobody may write the balloon meanwhile: data written into an
+ * unwritten extent would be discarded with it.
+ */
+ inode_lock(inode);
+ inode_dio_wait(inode);
+ filemap_invalidate_lock(inode->i_mapping);
+ ret = filemap_write_and_wait(inode->i_mapping);
+ if (ret)
+ goto out;
+
+ for (lblk = 0; lblk < EXT_MAX_BLOCKS; lblk += map.m_len) {
+ if (ext4_trim_interrupted())
+ break;
+ cond_resched();
+
+ map.m_lblk = lblk;
+ map.m_len = EXT_MAX_BLOCKS - lblk;
+ err = ext4_map_blocks(NULL, inode, &map, 0);
+ if (err < 0) {
+ ret = err;
+ break;
+ }
+ if (!map.m_len)
+ break;
+
+ unwritten = err > 0 && (map.m_flags & EXT4_MAP_UNWRITTEN);
+ if (unwritten && run_len && run_pblk + run_len == map.m_pblk) {
+ run_len += map.m_len;
+ continue;
+ }
+
+ ret = ext4_trim_balloon_run(sb, run_pblk, run_len, start, end,
+ minblocks);
+ if (ret)
+ break;
+ run_pblk = map.m_pblk;
+ run_len = unwritten ? map.m_len : 0;
+ }
+ if (!ret && !ext4_trim_interrupted())
+ ret = ext4_trim_balloon_run(sb, run_pblk, run_len, start, end,
+ minblocks);
+out:
+ filemap_invalidate_unlock(inode->i_mapping);
+ inode_unlock(inode);
+ iput(inode);
+
+ return ret;
+}
+
/**
* ext4_trim_fs() -- trim ioctl handle function
* @sb: superblock for filesystem
@@ -7028,6 +7148,7 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
ext4_group_t group, first_group, last_group;
ext4_grpblk_t cnt = 0, first_cluster, last_cluster;
uint64_t start, end, minlen, trimmed = 0;
+ ext4_fsblk_t last_blk;
ext4_fsblk_t first_data_blk =
le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
ext4_fsblk_t max_blks = ext4_blocks_count(EXT4_SB(sb)->s_es);
@@ -7061,6 +7182,7 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
&first_group, &first_cluster);
ext4_get_group_no_and_offset(sb, (ext4_fsblk_t) end,
&last_group, &last_cluster);
+ last_blk = end;
/* end now represents the last cluster to discard in this group */
end = EXT4_CLUSTERS_PER_GROUP(sb) - 1;
@@ -7103,6 +7225,10 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
first_cluster = 0;
}
+ if (!ret && !ext4_trim_interrupted())
+ ret = ext4_trim_balloon(sb, start, last_blk,
+ EXT4_C2B(EXT4_SB(sb), minlen));
+
if (!ret)
EXT4_SB(sb)->s_last_trim_minblks = minlen;
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Devel] [PATCH hci-8.1 v3 5/5] xfs: discard the balloon on FITRIM
2026-11-11 11:31 [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM Denis V. Lunev
` (3 preceding siblings ...)
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 4/5] ext4: discard the balloon on FITRIM Denis V. Lunev
@ 2026-11-11 11:31 ` Denis V. Lunev
2026-11-11 11:40 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
2026-11-12 12:07 ` [Devel] [PATCH hci-8.1 v3 0/5] ext4, " Konstantin Khorenko
2026-11-12 12:08 ` Konstantin Khorenko
6 siblings, 2 replies; 18+ messages in thread
From: Denis V. Lunev @ 2026-11-11 11:31 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Denis V. Lunev <den@openvz.org>
The balloon holds file system space that never carries data, but its
blocks are allocated, so the free space walk of xfs_ioc_trim() never
discards them, and inflating the balloon is a plain fallocate() that
does not discard either. Once the balloon is inflated over blocks that
held data, e.g. on an online shrink after files were removed, the
device below keeps them allocated: a ploop or qcow2 image keeps host
disk space the container can never use, and compaction, which is
FITRIM, does not give it back.
Walk the balloon after the free space of the data device and discard
its unwritten extents that fall into the requested range, merging
physically adjacent ones into one discard. The walk goes to the end of
the file offset space, as fallocate() with FALLOC_FL_KEEP_SIZE can
leave extents past i_size. A merged run is discarded in chunks, with a
check for fatal signals and freezing between them.
The walk holds the IOLOCK and the MMAPLOCK exclusively, after waiting
for direct I/O and flushing the page cache of the balloon. No block of
the balloon can be freed and reused under the discard, and nothing is
written to it meanwhile, so an extent that is still unwritten reads as
zeroes before and after the discard. The balloon is hidden from lookup
and opened only through XFS_IOC_OPEN_BALLOON, which takes
CAP_SYS_ADMIN, so the locks only wait for ploop inflating or shrinking
it.
An empty balloon is skipped before taking the locks. Any other one is
walked whole on every FITRIM, whatever range it asks for, as its
extent map is indexed by file offset; FITRIM is rare enough for that.
Discarding the balloon again each time is cheap: dm-ploop completes
the discard of an unmapped cluster at once.
A discard error or a failure to read the balloon inode fails FITRIM;
a balloon that is no longer a regular mutable file is skipped.
A balloon inflated before this change is released by the next FITRIM.
https://virtuozzo.atlassian.net/browse/VSTOR-153590
Feature: fs/xfs: fast online shrink support
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
Notes:
- The balloon is locked, flushed and walked whole on every FITRIM,
whatever the range. This is deliberate: ploop runs FITRIM on
compaction, about once a day. Measured on a 4-CPU VM with a balloon of
84-99G over all the free space of a 100G image: a FITRIM after the
first one spends 0.3-0.7s in the balloon, on ploop and qcow2, ext4 and
xfs, for a contiguous balloon and for one in up to about 10000 pieces.
The time goes mostly into discarding clusters that are already unmapped
and grows with the size of the balloon and the number of its pieces.
The locks held meanwhile only keep ploop from resizing the balloon.
Narrowing the walk to the range would need a reverse map from blocks to
file offsets. An empty balloon, the common case, is skipped before the
locks are taken.
- XFS_FSB_TO_BB(mp, minlen) could not wrap in 32 bits: xfs_ioc_trim()
rejects a minlen above the AG size, and an AG is at most 1 TiB, 2^31
sectors. The u64 cast keeps the check from depending on that.
fs/xfs/xfs_discard.c | 144 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 144 insertions(+)
diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index a6c43e4fdec3..72c6d1bb3fba 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -22,6 +22,10 @@
#include "xfs_health.h"
#include "xfs_rtbitmap.h"
#include "xfs_rtgroup.h"
+#include "xfs_bit.h"
+#include "xfs_inode.h"
+#include "xfs_bmap.h"
+#include "xfs_super.h"
/*
* Notes on an efficient, low latency fstrim algorithm
@@ -843,6 +847,140 @@ xfs_trim_rtdev_extents(
# define xfs_trim_rtdev_extents(...) (-EOPNOTSUPP)
#endif /* CONFIG_XFS_RT */
+#define XFS_BALLOON_DISCARD_CHUNK_BB ((128U << 20) >> BBSHIFT)
+
+static int
+xfs_trim_balloon_run(
+ struct xfs_mount *mp,
+ xfs_daddr_t daddr,
+ uint64_t len,
+ xfs_daddr_t start,
+ xfs_daddr_t end,
+ xfs_extlen_t minlen)
+{
+ struct block_device *bdev = mp->m_ddev_targp->bt_bdev;
+ unsigned int gran = max(1U,
+ bdev_discard_granularity(bdev) >> BBSHIFT);
+ unsigned int chunk = roundup(XFS_BALLOON_DISCARD_CHUNK_BB, gran);
+ xfs_daddr_t last = daddr + len - 1, next;
+ int error;
+
+ if (!len)
+ return 0;
+ if (daddr < start)
+ daddr = start;
+ if (last > end)
+ last = end;
+ if (last < daddr || last - daddr + 1 < XFS_FSB_TO_BB(mp, (u64)minlen))
+ return 0;
+
+ /*
+ * Chunks keep a long run interruptible. They end on multiples of the
+ * discard granularity, so no cluster below is split between two.
+ */
+ while (daddr <= last) {
+ u64 rem = daddr;
+
+ next = daddr + chunk - do_div(rem, chunk);
+ if (next > last + 1)
+ next = last + 1;
+ error = blkdev_issue_discard(bdev, daddr, next - daddr,
+ GFP_KERNEL);
+ if (error)
+ return error;
+ daddr = next;
+ if (xfs_trim_should_stop())
+ break;
+ cond_resched();
+ }
+
+ return 0;
+}
+
+/*
+ * Blocks of the balloon never hold data, but they are allocated, so the
+ * free space btree walk never discards them. Discard its unwritten
+ * extents, merging physically adjacent ones, so that the device below
+ * can release the space as it does for free blocks.
+ */
+static int
+xfs_trim_balloon(
+ struct xfs_mount *mp,
+ xfs_daddr_t start,
+ xfs_daddr_t end,
+ xfs_extlen_t minlen)
+{
+ u64 balloon_ino = READ_ONCE(mp->m_balloon_ino);
+ xfs_daddr_t run_daddr = 0;
+ uint64_t run_len = 0;
+ struct xfs_bmbt_irec map;
+ struct xfs_inode *ip;
+ xfs_fileoff_t off = 0;
+ unsigned int lock_mode;
+ bool unwritten;
+ int nmaps, error;
+
+ if (!balloon_ino)
+ return 0;
+ ip = xfs_balloon_get(mp, balloon_ino, 0);
+ if (IS_ERR(ip))
+ return PTR_ERR(ip) == -EINVAL ? 0 : PTR_ERR(ip);
+ error = 0;
+ if (XFS_IS_REALTIME_INODE(ip) || !ip->i_nblocks)
+ goto out_rele;
+
+ /*
+ * Nobody may write the balloon meanwhile: data written into an
+ * unwritten extent would be discarded with it.
+ */
+ xfs_ilock(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
+ inode_dio_wait(VFS_I(ip));
+ error = filemap_write_and_wait(VFS_I(ip)->i_mapping);
+ if (error)
+ goto out_unlock;
+
+ while (off < XFS_MAX_FILEOFF) {
+ if (xfs_trim_should_stop())
+ break;
+ cond_resched();
+
+ nmaps = 1;
+ lock_mode = xfs_ilock_data_map_shared(ip);
+ error = xfs_bmapi_read(ip, off, XFS_MAX_FILEOFF - off, &map,
+ &nmaps, 0);
+ xfs_iunlock(ip, lock_mode);
+ if (error || !nmaps || !map.br_blockcount)
+ break;
+ off = map.br_startoff + map.br_blockcount;
+
+ unwritten = xfs_bmap_is_real_extent(&map) &&
+ map.br_state == XFS_EXT_UNWRITTEN;
+ if (unwritten && run_len && run_daddr + run_len ==
+ XFS_FSB_TO_DADDR(mp, map.br_startblock)) {
+ run_len += XFS_FSB_TO_BB(mp, map.br_blockcount);
+ continue;
+ }
+
+ error = xfs_trim_balloon_run(mp, run_daddr, run_len, start,
+ end, minlen);
+ if (error)
+ break;
+ run_len = 0;
+ if (unwritten) {
+ run_daddr = XFS_FSB_TO_DADDR(mp, map.br_startblock);
+ run_len = XFS_FSB_TO_BB(mp, map.br_blockcount);
+ }
+ }
+ if (!error && !xfs_trim_should_stop())
+ error = xfs_trim_balloon_run(mp, run_daddr, run_len, start,
+ end, minlen);
+out_unlock:
+ xfs_iunlock(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
+out_rele:
+ xfs_irele(ip);
+ return error;
+}
+
/*
* trim a range of the filesystem.
*
@@ -915,6 +1053,12 @@ xfs_ioc_trim(
error = xfs_trim_datadev_extents(mp, start, end, minlen);
if (error)
last_error = error;
+
+ if (!xfs_trim_should_stop()) {
+ error = xfs_trim_balloon(mp, start, end, minlen);
+ if (error)
+ last_error = error;
+ }
}
if (rt_bdev && !xfs_trim_should_stop()) {
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 2/5] ms/xfs: don't skip free extents of the longest length in a whole-AG FITRIM
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 2/5] ms/xfs: don't skip free extents of the longest length in " Denis V. Lunev
@ 2026-11-11 11:35 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
1 sibling, 0 replies; 18+ messages in thread
From: no-reply @ 2026-11-11 11:35 UTC (permalink / raw)
To: Denis V. Lunev, khorenko; +Cc: devel
> From: Daejun Park <daejun7.park@samsung.com>
>
> Since commit a66d636385d6 ("xfs: fix fstrim offset calculations"), the
> by-length walk of an AG in FITRIM starts with
> xfs_alloc_lookup_ge(cur, 0, pagf_longest) and walks down. The lookup
> lands on the longest free extent with the lowest block number. The
> other free extents of that length sort after it and are never
> discarded.
>
> Start every by-length batch with xfs_alloc_lookup_le() at restart_bno.
>
> Suggested-by: Dave Chinner <dgc@kernel.org>
> Link: https://lore.kernel.org/r/ZgiJWxVcVwag0fIP@dread.disaster.area
> Cc: stable@vger.kernel.org
> Fixes: a66d636385d6 ("xfs: fix fstrim offset calculations")
> Signed-off-by: Daejun Park <daejun7.park@samsung.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Carlos Maiolino <cem@kernel.org>
> (cherry picked from commit 5745f4f10a1a16aa5bb020acc38afa33f2d5ff99)
>
> https://virtuozzo.atlassian.net/browse/VSTOR-153590
>
> Feature: fix ms/xfs
> Signed-off-by: Denis V. Lunev <den@openvz.org>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261111113135.4023555-1-den@openvz.org?part=2
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 3/5] xfs: release the balloon inode when xfs_balloon_get() refuses it
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 3/5] xfs: release the balloon inode when xfs_balloon_get() refuses it Denis V. Lunev
@ 2026-11-11 11:35 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
1 sibling, 0 replies; 18+ messages in thread
From: no-reply @ 2026-11-11 11:35 UTC (permalink / raw)
To: Denis V. Lunev, khorenko; +Cc: devel
> From: Denis V. Lunev <den@openvz.org>
>
> xfs_balloon_get() looks the balloon inode up with xfs_iget() and returns
> -EINVAL when it is not a regular file or is immutable, without
> releasing the reference it took. Every statfs and every open of the
> balloon then leaks a reference on such an inode, which the VFS reports
> as a busy inode at unmount.
>
> Release the inode before returning -EINVAL.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-153590
>
> Feature: fs/xfs: fast online shrink support
> Signed-off-by: Denis V. Lunev <den@openvz.org>
This patch is unchanged since "[Devel] [PATCH hci-8.1 v2 1/3] xfs: release the balloon inode when xfs_balloon_get() refuses it", which Sashiko reviewed and found no issues in. That review applies to this posting unaltered, so the patch has not been reviewed again.
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110222756.3236854-1-den@openvz.org?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 1/5] ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 1/5] ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM Denis V. Lunev
@ 2026-11-11 11:35 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
1 sibling, 0 replies; 18+ messages in thread
From: no-reply @ 2026-11-11 11:35 UTC (permalink / raw)
To: khorenko, Denis V. Lunev; +Cc: devel
> From: Daejun Park <daejun7.park@samsung.com>
>
> A whole-device FITRIM walks every AG but the last by length, in
> batches. xfs_trim_gather_extents() saves the record to restart from in
> tcur->start. But tcur->start is also the start of the range to trim.
> Later batches therefore never discard the free extents below that
> block.
>
> Save the restart record in a new restart_bno field.
>
> Cc: stable@vger.kernel.org # v6.10
> Fixes: b0ffe661fab4 ("xfs: fix performance problems when fstrimming a subset of a fragmented AG")
> Signed-off-by: Daejun Park <daejun7.park@samsung.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Carlos Maiolino <cem@kernel.org>
> (cherry picked from commit 595e67d7261673d03c96950ffbb2e545c00376ed)
>
> https://virtuozzo.atlassian.net/browse/VSTOR-153590
>
> Feature: fix ms/xfs
> Signed-off-by: Denis V. Lunev <den@openvz.org>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261111113135.4023555-1-den@openvz.org?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 5/5] xfs: discard the balloon on FITRIM
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 5/5] xfs: " Denis V. Lunev
@ 2026-11-11 11:40 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
1 sibling, 0 replies; 18+ messages in thread
From: no-reply @ 2026-11-11 11:40 UTC (permalink / raw)
To: Denis V. Lunev, khorenko; +Cc: devel
> From: Denis V. Lunev <den@openvz.org>
>
> The balloon holds file system space that never carries data, but its
> blocks are allocated, so the free space walk of xfs_ioc_trim() never
> discards them, and inflating the balloon is a plain fallocate() that
> does not discard either. Once the balloon is inflated over blocks that
> held data, e.g. on an online shrink after files were removed, the
> device below keeps them allocated: a ploop or qcow2 image keeps host
> disk space the container can never use, and compaction, which is
> FITRIM, does not give it back.
>
> Walk the balloon after the free space of the data device and discard
> its unwritten extents that fall into the requested range, merging
> physically adjacent ones into one discard. The walk goes to the end of
> the file offset space, as fallocate() with FALLOC_FL_KEEP_SIZE can
> [ ... ]
>
> https://virtuozzo.atlassian.net/browse/VSTOR-153590
>
> Feature: fs/xfs: fast online shrink support
> Signed-off-by: Denis V. Lunev <den@openvz.org>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261111113135.4023555-1-den@openvz.org?part=5
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 4/5] ext4: discard the balloon on FITRIM
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 4/5] ext4: discard the balloon on FITRIM Denis V. Lunev
@ 2026-11-11 11:40 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
1 sibling, 0 replies; 18+ messages in thread
From: no-reply @ 2026-11-11 11:40 UTC (permalink / raw)
To: Denis V. Lunev, khorenko; +Cc: devel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] ext4: FITRIM balloon discard merges only logically contiguous extents
--
commit 5d29cebdec45f399e32530ba7c9295bebaf3a2e6
Author: Denis V. Lunev <den@openvz.org>
ext4: discard the balloon on FITRIM
This commit makes ext4_trim_fs() walk the balloon inode after the free
space and discard its unwritten extents that fall into the requested
range. Physically adjacent extents are merged into one discard, and long
runs are discarded in chunks with checks for fatal signals and freezing.
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
[ ... ]
> +static int ext4_trim_balloon(struct super_block *sb, ext4_fsblk_t start,
> + ext4_fsblk_t end, ext4_fsblk_t minblocks)
> +{
[ ... ]
> + unwritten = err > 0 && (map.m_flags & EXT4_MAP_UNWRITTEN);
> + if (unwritten && run_len && run_pblk + run_len == map.m_pblk) {
> + run_len += map.m_len;
> + continue;
> + }
> +
> + ret = ext4_trim_balloon_run(sb, run_pblk, run_len, start, end,
> + minblocks);
> + if (ret)
> + break;
> + run_pblk = map.m_pblk;
> + run_len = unwritten ? map.m_len : 0;
[Severity: Low]
The commit message says "Physically adjacent extents are merged into one
discard, otherwise every cut at the unwritten extent length limit leaves a
partly covered cluster of the image below." Is that description accurate
for what ext4_trim_balloon() does?
When the walk meets a hole or a written extent, the code takes the
non-merge path above. It calls ext4_trim_balloon_run() on the pending run
and then sets run_len to 0. The next unwritten extent then starts a new run
even if its m_pblk equals the end of the previous run:
unwritten extent A (pblk P .. P+n-1)
hole / written extent in the logical range
unwritten extent B (pblk P+n ..)
A and B are physically adjacent but are discarded as two separate runs.
The boundary cluster can then be left partly covered, which is the case the
merging is meant to avoid.
Only extents that are consecutive in logical order and also physically
adjacent are merged. The common case, a split at the unwritten extent
length limit, is handled correctly. Could the commit message be reworded
to say that logically consecutive, physically adjacent extents are merged?
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261111113135.4023555-1-den@openvz.org?part=4
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 2/5] ms/xfs: don't skip free extents of the longest length in a whole-AG FITRIM
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 2/5] ms/xfs: don't skip free extents of the longest length in " Denis V. Lunev
2026-11-11 11:35 ` no-reply
@ 2026-11-12 12:07 ` Konstantin Khorenko
1 sibling, 0 replies; 18+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 12:07 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying as is.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 1/5] ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 1/5] ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM Denis V. Lunev
2026-11-11 11:35 ` no-reply
@ 2026-11-12 12:07 ` Konstantin Khorenko
1 sibling, 0 replies; 18+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 12:07 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying as is.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 3/5] xfs: release the balloon inode when xfs_balloon_get() refuses it
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 3/5] xfs: release the balloon inode when xfs_balloon_get() refuses it Denis V. Lunev
2026-11-11 11:35 ` no-reply
@ 2026-11-12 12:07 ` Konstantin Khorenko
1 sibling, 0 replies; 18+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 12:07 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying with these fixes on my side:
- added Fixes: 3681ad22775c ("xfs: Teach the fs where the balloon
inode is")
- "Every statfs and every open of the balloon" -> "Every mount,
remount, statfs and open of the balloon"
On Wed, 11 Nov 2026 12:31:33 +0100, Denis V. Lunev wrote:
> releasing the reference it took. Every statfs and every open of the
> balloon then leaks a reference on such an inode, which the VFS reports
> as a busy inode at unmount.
xfs_balloon_check() calls xfs_balloon_get() at mount and remount too,
and a balloon_ino= naming a directory is the most likely way to get
there.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM
2026-11-11 11:31 [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM Denis V. Lunev
` (4 preceding siblings ...)
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 5/5] xfs: " Denis V. Lunev
@ 2026-11-12 12:07 ` Konstantin Khorenko
2026-11-12 12:08 ` Konstantin Khorenko
6 siblings, 0 replies; 18+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 12:07 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying with these fixes on my side:
- 3/5: added Fixes: 3681ad22775c ("xfs: Teach the fs where the balloon
inode is"), and mount and remount added to the list of leaking calls
- 4/5, 5/5: "opened only through ..._OPEN_BALLOON, which takes
CAP_SYS_ADMIN" reworded: a file handle opens the balloon too
- 4/5, 5/5: "Physically adjacent extents are merged" -> "Extents that
follow each other both in the file and on disk are merged"
On Wed, 11 Nov 2026 12:31:30 +0100, Denis V. Lunev wrote:
> Daejun Park (2):
> ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM
> ms/xfs: don't skip free extents of the longest length in a whole-AG
> FITRIM
>
> 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
Separate patches, not needed for this series; I created a task for
each:
1. A balloon discard error fails FITRIM, while both file systems
ignore discard errors in the free space pass. ploop_trim() then
stops and skips its smaller minlen rounds, which worked before this
series. Please say whether that difference is wanted; if not, treat
a balloon discard error the way the free space pass does.
https://virtuozzo.atlassian.net/browse/VSTOR-154840
2. The chunks end on multiples of the discard granularity counted
from the partition start, but the block layer aligns discards to
the start of the whole disk. On a partition that does not start on
a cluster boundary every chunk boundary splits a cluster, and ploop
keeps it mapped. Partitions made by ploop start at one cluster, so
this is minor: add the partition start to the remainder, or narrow
the comment.
https://virtuozzo.atlassian.net/browse/VSTOR-154841
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 4/5] ext4: discard the balloon on FITRIM
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 4/5] ext4: discard the balloon on FITRIM Denis V. Lunev
2026-11-11 11:40 ` no-reply
@ 2026-11-12 12:07 ` Konstantin Khorenko
1 sibling, 0 replies; 18+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 12:07 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying with these fixes on my side:
- "Physically adjacent extents are merged into one discard" ->
"Extents that follow each other both in the file and on disk are
merged into one discard"
- "opened only through EXT4_IOC_OPEN_BALLOON, which takes
CAP_SYS_ADMIN, so the lock only waits for ploop" -> "only a
privileged process opens it, through EXT4_IOC_OPEN_BALLOON or a file
handle, so in practice the lock waits only for ploop"
On Wed, 11 Nov 2026 12:31:34 +0100, Denis V. Lunev wrote:
> leave extents past i_size. Physically adjacent extents are merged into
> one discard, otherwise every cut at the unwritten extent length limit
> leaves a partly covered cluster of the image below. A merged run is
Sashiko is right here: the run also ends at a hole, a written extent
or an extent placed on disk before the one before it in the file.
ploop fills the balloon from offset 0 and never writes it, so the
code is fine and only the wording changes.
> balloon is hidden from lookup and opened only through
> EXT4_IOC_OPEN_BALLOON, which takes CAP_SYS_ADMIN, so the lock only
> waits for ploop inflating or shrinking it.
open_by_handle_at() opens the balloon too. It needs privileges as
well, and the exclusive locks cover any opener, so only the wording
changes.
> + /*
> + * Chunks keep a long run interruptible. They end on multiples of the
> + * discard granularity, so no cluster below is split between two.
> + */
Item 2 of the cover letter reply.
> + ret = sb_issue_discard(sb, pblk, next - pblk, GFP_NOFS, 0);
> + if (ret)
> + return ret;
Item 1 of the cover letter reply.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 5/5] xfs: discard the balloon on FITRIM
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 5/5] xfs: " Denis V. Lunev
2026-11-11 11:40 ` no-reply
@ 2026-11-12 12:07 ` Konstantin Khorenko
1 sibling, 0 replies; 18+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 12:07 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying with these fixes on my side:
- "merging physically adjacent ones into one discard" -> "merging those
that follow each other both in the file and on disk into one
discard"
- "opened only through XFS_IOC_OPEN_BALLOON, which takes CAP_SYS_ADMIN,
so the locks only wait for ploop" -> "only a privileged process opens
it, through XFS_IOC_OPEN_BALLOON or a file handle, so in practice the
locks wait only for ploop"
On Wed, 11 Nov 2026 12:31:35 +0100, Denis V. Lunev wrote:
> its unwritten extents that fall into the requested range, merging
> physically adjacent ones into one discard. The walk goes to the end of
The run also ends at a hole, a written extent or an extent placed on
disk before the one before it in the file, the same as on ext4.
ploop fills the balloon from offset 0 and never writes it, so the
code is fine and only the wording changes.
> and opened only through XFS_IOC_OPEN_BALLOON, which takes
> CAP_SYS_ADMIN, so the locks only wait for ploop inflating or shrinking
> it.
open_by_handle_at() and XFS_IOC_OPEN_BY_HANDLE open the balloon too.
They need privileges as well, and the exclusive locks cover any opener,
so only the wording changes.
> + /*
> + * Chunks keep a long run interruptible. They end on multiples of the
> + * discard granularity, so no cluster below is split between two.
> + */
Item 2 of the cover letter reply.
> + error = blkdev_issue_discard(bdev, daddr, next - daddr,
> + GFP_KERNEL);
> + if (error)
> + return error;
Item 1 of the cover letter reply.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM
2026-11-11 11:31 [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM Denis V. Lunev
` (5 preceding siblings ...)
2026-11-12 12:07 ` [Devel] [PATCH hci-8.1 v3 0/5] ext4, " Konstantin Khorenko
@ 2026-11-12 12:08 ` Konstantin Khorenko
6 siblings, 0 replies; 18+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 12:08 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
On Wed, 11 Nov 2026 12:31:30 +0100, Denis V. Lunev wrote:
> ext4, xfs: discard the balloon on FITRIM
>
> 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).
>
> [...]
Applied to branch-rh10-6.12.0-211.52.1.22.x.vz10-ovz, will be released in rh10-6.12.0-211.52.1.22.21.vz10, thanks!
[1/5] ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/2cd1118f9a7f
[2/5] ms/xfs: don't skip free extents of the longest length in a whole-AG FITRIM
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/54b149136857
[3/5] xfs: release the balloon inode when xfs_balloon_get() refuses it
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/af1a0755a838
[4/5] ext4: discard the balloon on FITRIM
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/39aa4cc013bd
[5/5] xfs: discard the balloon on FITRIM
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/eaadefa92505
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2026-11-12 12:10 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 11:31 [Devel] [PATCH hci-8.1 v3 0/5] ext4, xfs: discard the balloon on FITRIM Denis V. Lunev
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 1/5] ms/xfs: don't skip free extents in later batches of a whole-AG FITRIM Denis V. Lunev
2026-11-11 11:35 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 2/5] ms/xfs: don't skip free extents of the longest length in " Denis V. Lunev
2026-11-11 11:35 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 3/5] xfs: release the balloon inode when xfs_balloon_get() refuses it Denis V. Lunev
2026-11-11 11:35 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 4/5] ext4: discard the balloon on FITRIM Denis V. Lunev
2026-11-11 11:40 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
2026-11-11 11:31 ` [Devel] [PATCH hci-8.1 v3 5/5] xfs: " Denis V. Lunev
2026-11-11 11:40 ` no-reply
2026-11-12 12:07 ` Konstantin Khorenko
2026-11-12 12:07 ` [Devel] [PATCH hci-8.1 v3 0/5] ext4, " Konstantin Khorenko
2026-11-12 12:08 ` Konstantin Khorenko
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.