2021-12-17 09:49:39 +00:00
|
|
|
Trim/discard
|
|
|
|
============
|
2021-11-30 15:00:48 +00:00
|
|
|
|
2021-12-17 09:49:39 +00:00
|
|
|
Trim or discard is an operation on a storage device based on flash technology
|
|
|
|
(SSD, NVMe or similar), a thin-provisioned device or could be emulated on top
|
|
|
|
of other block device types. On real hardware, there's a different lifetime
|
|
|
|
span of the memory cells and the driver firmware usually tries to optimize for
|
|
|
|
that. The trim operation issued by user provides hints about what data are
|
|
|
|
unused and allow to reclaim the memory cells. On thin-provisioned or emulated
|
|
|
|
this is could simply free the space.
|
|
|
|
|
|
|
|
There are three main uses of trim that BTRFS supports:
|
|
|
|
|
|
|
|
synchronous
|
|
|
|
enabled by mounting filesystem with ``-o discard`` or ``-o
|
|
|
|
discard=sync``, the trim is done right after the file extents get freed,
|
|
|
|
this however could have severe performance hit and is not recommended
|
|
|
|
as the ranges to be trimmed could be too fragmented
|
|
|
|
|
|
|
|
asynchronous
|
|
|
|
enabled by mounting filesystem with ``-o discard=async``, which is an
|
|
|
|
improved version of the synchronous trim where the freed file extents
|
|
|
|
are first tracked in memory and after a period or enough ranges accumulate
|
|
|
|
the trim is started, expecting the ranges to be much larger and
|
|
|
|
allowing to throttle the number of IO requests which does not interfere
|
|
|
|
with the rest of the filesystem activity
|
|
|
|
|
|
|
|
manually by fstrim
|
2023-04-26 23:48:47 +00:00
|
|
|
the tool :command:`fstrim` starts a trim operation on the whole filesystem, no
|
2021-12-17 09:49:39 +00:00
|
|
|
mount options need to be specified, so it's up to the filesystem to
|
|
|
|
traverse the free space and start the trim, this is suitable for running
|
|
|
|
it as periodic service
|
|
|
|
|
|
|
|
The trim is considered only a hint to the device, it could ignore it completely,
|
|
|
|
start it only on ranges meeting some criteria, or decide not to do it because of
|
|
|
|
other factors affecting the memory cells. The device itself could internally
|
|
|
|
relocate the data, however this leads to unexpected performance drop. Running
|
|
|
|
trim periodically could prevent that too.
|
|
|
|
|
2023-06-28 17:55:08 +00:00
|
|
|
When a filesystem is created by :doc:`mkfs.btrfs` and is capable
|
2023-08-23 15:58:06 +00:00
|
|
|
of trim, then it's by default performed on all devices. Since kernel 6.2 the
|
|
|
|
*discard=async* mount option is automatically enabled on devices that support
|
|
|
|
that.
|