Trim an SSD in macOS

Last Update: June 28th, 2023
Article ID: 1015395

Apple macOS enables Trim for internal Apple SSDs only.  Advanced users can also enable Trim for USB connected SSDs with Apple APFS formatted partitions.  Apple macOS runs Trim when the file system is detected by the operating system, this is either on device connection or system restart, Apple does not provide a manual Trim tool like with Windows or Linux.

Enabling Trim in macOS

Open a terminal (Finder > Go > Utilities > Terminal) and enter the following command:

sudo trimforce --enable

This requires administrative permissions to run and you will need to enter your password to continue.

A long warning will be presented, please read this fully.

Enter ‘Y’ to continue, or ‘N’ to cancel

Trim can be disabled with the following command:

sudo trimforce --disable

Verifying Trim on macOS

Apple macOS does not have a function to manually run a Trim command, instead it is run when a supported drive and supported file system is detected by the operating system.  We can check to verify Trim is running on a drive by performing the following:

Open a terminal (Finder > Go > Utilities > Terminal) and enter the following command:

log show --start $(date +%F) | grep -i spaceman_trim_free_blocks

This may take a moment to complete, I recommend expanding the window to full screen for easier reading.

Each output line represents a file system that has been trimmed on today’s date, here is an example line:

2021-08-13 07:16:07.556498-0700 0x2b2d Default 0x0 0 0 kernel: (apfs) spaceman_trim_free_blocks:3371: disk3 scan took 0.000614 s, trims took 0.000000 s

The specific drive is “disk3” in my example, we verify that disk3 matches the external drive by comparing to the output of this command:

diskutil list

/dev/disk3 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +160.0 GB   disk3
                                 Physical Store disk2s2
   1:                APFS Volume ⁨Intel160⁩                774.1 KB   disk3s1