2 minutes
test-discard
Overview
One of my first projects at Red Hat was test-discard, a userspace testing tool designed to explore how real SSDs and block devices respond to discard/TRIM operations. Although modest in size, this work had outsized impact on filesystem and storage stack behavior in Linux.
21 commits · 3,382 insertions(+) · 1,057 deletions(-)
What test-discard was
Before FITRIM and widespread filesystems support for efficient discard handling, there was limited insight into how different SSDs handled discard/TRIM commands — the ATA/SCSI operations that tell a drive which blocks are no longer in use so it can reclaim and erase them internally. TRIM behavior varies widely by controller and firmware, and naive approaches (e.g., always issuing discard on every file delete) can cause severe performance degradation on many devices.
test-discard was an early, lightweight tool for exercising discard paths on block devices and gathering empirical results on how drives reacted under different discard patterns and workloads.
Although it was a relatively small project, its utility came from providing reproducible results across SSD models and firmware versions — insights that were hard to obtain from existing ad hoc tests or from theoretical expectations. These results helped reveal that:
- TRIM support varies significantly by SSD and controller, even when the device advertises support.
- Some devices exhibit poor synchronous discard performance (high latency when processing small, frequent TRIMs).
- Others only benefit when discards are grouped into larger, coalesced ranges.
Why it mattered
The findings from test-discard directly influenced the design of
batched/background discard support in the Linux kernel and ext4 . Rather than issuing a discard on every delete
(the traditional realtime -o discard mount behavior, which can be
prohibitively expensive), the kernel and userspace adopted an approach where
free space is batched and reclaimed periodically via the FITRIM ioctl and
the fstrim utility. This method significantly improves performance and aligns
with modern SSD controller behavior.
In other words, test-discard helped demonstrate that:
- Inline discard on every operation was not a good default.
- Drives benefit from bulk free-space notifications.
- Filesystem-level batch trim (FITRIM) provides a better trade-off between performance and device health.
The results informed not just ext4’s FITRIM implementation but were also referenced in broader discussions about block discards across layers (filesystems, LVM, RAID) and for tuning discard strategies in user environments.