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 1) and xfs (patch 2). The walk is read-only, under the shared inode lock of the balloon, which keeps fallocate, truncate and extent moves away from it, so no block can be freed and reused under the discard. Physically adjacent extents are merged into one discard, so that the device below gets whole clusters. A balloon inflated before this series is released by the next FITRIM, no userspace change is needed. 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 Tested on 6.12.0-211.52.1.22.19.vz10 rebuilt with this series, alone and together with 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; - fstrim -o/-l discards only the part of the balloon in the range, a repeated discard changes nothing, and data written over the space of a deflated balloon reads back intact; - test_ploop_balloon.py from PR 519: green on ploop and qcow2 with pytest -n 10. On the stock kernel only the test for the space under the balloon fails. Not covered: a read-only mount (the pass is skipped there), 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. Denis V. Lunev (2): ext4: discard the balloon on FITRIM xfs: discard the balloon on FITRIM fs/ext4/mballoc.c | 99 +++++++++++++++++++++++++++++++++++++++- fs/xfs/xfs_discard.c | 106 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+), 1 deletion(-) -- 2.53.0 _______________________________________________ Devel mailing list [email protected] https://lists.openvz.org/mailman/listinfo/devel
