In Ubuntu Server environments utilizing the ZFS file system, the zfs-trim.service is a systemd unit responsible for automatically executing periodic TRIM operations (also known as discard) on ZFS pools. TRIM informs the underlying solid-state drives (SSDs) which data blocks are no longer in use, allowing the drive’s firmware to perform garbage collection and maintain optimal write performance. While periodic TRIM is generally recommended for consumer workloads, it can be highly detrimental in high-performance, I/O-intensive enterprise database servers. A sudden, massive TRIM operation scheduled during peak hours can saturate the storage controller, leading to severe latency spikes and degraded application performance. In these scenarios, administrators prefer to manage TRIM manually during designated maintenance windows, or rely on continuous autotrim (zpool set autotrim=on) which issues smaller, less disruptive commands.
This guide explains how to completely disable the scheduled zfs-trim.service (and its associated systemd timer) in Ubuntu Server.
Stop and Mask the zfs-trim Service and Timer
Because this service is triggered periodically by a systemd timer rather than running continuously in the background, we must disable both the timer and the service unit itself to ensure it never executes.
- Log into your Ubuntu Server via SSH using an account with
sudoprivileges. - First, stop and disable the timer that schedules the execution:
sudo systemctl stop zfs-trim.timersudo systemctl disable zfs-trim.timer - Next, stop and disable the underlying service unit:
sudo systemctl stop zfs-trim.servicesudo systemctl disable zfs-trim.service - Finally, to guarantee that the service cannot be accidentally triggered manually or by another dependency, mask both units:
sudo systemctl mask zfs-trim.timersudo systemctl mask zfs-trim.service
Verify the Service Lockdown
By masking the units, you have instructed systemd to symlink them to /dev/null, effectively neutralizing the scheduled TRIM operations.
To verify the lockdown is successful, run the following commands:
systemctl status zfs-trim.timer
systemctl status zfs-trim.service
The output for both will clearly state that they are masked. Furthermore, running systemctl list-timers will confirm that the ZFS trim timer is no longer listed in the schedule. You have successfully taken manual control over your SSD garbage collection routines.