Skip to content

Using discard on raw images leads to fragmentation on disk

I use the raw image format. When calling trim (discard) in the guest system, QEMU call fallocate with the FALLOC_FL_PUNCH_HOLE flag. This creates a sparse file. When writing new data, the file system physically places the data in a new location. This leads to fragmentation and a performance drop. This behavior is good for SSD because it causes a trim on the physical device.

When using the FALLOC_FL_ZERO_RANGE flag, file system converts the range to unwritten extents. This does not free up space, and next write will be to the same location. This behavior is well suited for HDD because it reduces fragmentation.

It would be nice to have an option that specifies the behavior of trim on raw images (PUNCH_HOLE\ZERO_RANGE).

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information