The Btrfs file-system looks like its new “CLEAR_FREE” feature will be ready to go for the upcoming Linux 6.16 kernel cycle.
David Sterba of SUSE has been working on the CLEAR_FREE patch series as a new kernel ioctl for clearing unused space in various manners. The patches have been queued into the Btrfs for-next Git branch and thus likely material for the upcoming merge window (Linux 6.16) barring any last minute issues or reservations from coming about.
Btrfs CLEAR_FREE is a more extensible version of FITRIM that does more than just TRIM/DISCARD but can be used for secure erase, zeroing out unused blocks, and extended with other capabilities.
David Sterba explained in the prior patch series of this CLEAR_FREE functionality:
“Add ioctl that is similar to FITRIM and in addition to trim can do also zeroing (either plain overwrite, or unmap the blocks if the device supports it) and secure erase.
This can be used to zero the unused space in e.g. VM images (when run from inside the guest, if fstrim is not supported) or free space on thin-provisioned devices.
The secure erase is provided by blkdiscard command but I’m not aware of equivalent that can be run on a filesystem, so this is for parity.”
In initial form is the secure erase mode as well as zero-out mode for CLEAR_FREE. The secure erase will securely erase unused space and depends upon hardware support. The zero-out mode will write zeroes to the blocks unless the hardware supports the UNMAP command.