fstrim command, and it matters for SSDs (where the device can reclaim the blocks for wear levelling)
and for thin-provisioned storage (where the freed blocks are returned to the backing pool).
Trimming is controlled by the FilesystemTrimConfig document,
which sets the global trim interval, and by an optional per-volume trim section which overrides it.
Default behavior
Trimming is enabled by default for clusters created with Talos v1.14 or later.talosctl gen config emits a FilesystemTrimConfig document with a one week interval
as part of the default machine configuration:
Configure the trim interval
Theinterval field of the FilesystemTrimConfig document sets the interval for all eligible volumes on the machine:
24h0m0s for a day or 168h0m0s for a week.
Removing the document, or setting interval: 0s, disables trimming for every volume which does not enable it explicitly.
The document is applied without a reboot: the schedule is rebuilt as soon as the new configuration is applied.
Override the interval per volume
Trimming can be adjusted for a single volume with atrim section on the volume document.
It is supported by VolumeConfig,
UserVolumeConfig and
ExistingVolumeConfig:
- Without a
trimsection, the volume follows the globalFilesystemTrimConfiginterval. - A
trimsection enables trimming for the volume unlessenabled: falseis set explicitly. trim.interval, when set, overrides the global interval for this volume only.
trim section must set interval as well.
enabled: true on its own leaves the interval at zero, and trimming stays disabled for the volume:
enabled: false:
Which volumes are trimmed
A volume is trimmed on a schedule when all of the following hold:- Trimming is enabled for the volume with a non-zero interval.
- The volume is of type
diskorpartition, and is in thereadyphase. Volumes of the other types (directory,symlink,overlay,tmpfs,external) are never trimmed. - The filesystem supports discarding unused blocks:
xfs,ext4orbtrfs. - For encrypted volumes,
allowDiscardsis set in the encryption section. Without it the discard requests never reach the underlying device, so Talos does not schedule the trim at all. Passing discards through an encrypted volume leaks information about the amount and location of used blocks, so this is opt-in.
Trim schedule
Talos does not trim all volumes at once, and it does not trim on a fixed wall-clock time such as midnight. Instead, each volume gets its own offset within the interval, derived by hashing the node ID together with the volume ID. This has two consequences:- The schedule is stable for a given machine: the same volume on the same node is always trimmed at the same points in time, and a reboot or does not shift or reset the schedule.
- The schedule is spread out across the cluster: because the node ID is part of the hash, every machine trims a given volume at a different time, and different volumes on one machine are trimmed at different times. A cluster-wide I/O spike from all nodes trimming simultaneously is avoided without any manual staggering.
Check the trim status
TheVolumeTrimSchedule resource exists for every volume which is scheduled to be trimmed, and shows the next trim time:
controller-runtime logs, including the amount of space discarded:
Related
- Filesystem Scrub applies the same scheduling model to online filesystem checks.
- Disk Encryption documents the
allowDiscardsencryption option.