# TRIM function on new install



## Terpentijn (Dec 8, 2020)

A fresh FreeBSD install on my SSD does not set the trim function. I know how to set it on an existing filesystem, but I would like to get some advice on enabling it or leave it disabled. What's best practise?


----------



## SirDice (Dec 8, 2020)

It should be on by default and has been the default for quite some time now. But I'm wondering why it would be off, perhaps your SSD doesn't support it? What brand/make/model is it?


----------



## ralphbsz (Dec 8, 2020)

Try "camcontrol identify adaX", and then look for the line that says "TRIM". Here's my 7- or 8-year old Intel SSD:

```
# camcontrol identify ada0 | egrep "Feature|TRIM"
Feature                      Support  Enabled   Value           Vendor
Data Set Management (DSM/TRIM) no
```
If your SSD hardware can do it, and it wasn't enabled during the install, that sounds like a bug in the installer, or some way you managed to override it. It can be pretty easily enabled after the fact. For UFS, it's one tunefs command, followed by running fsck with extra parameters.


----------



## Terpentijn (Dec 8, 2020)

ralphbsz said:


> Try "camcontrol identify adaX", and then look for the line that says "TRIM". Here's my 7- or 8-year old Intel SSD:
> 
> ```
> # camcontrol identify ada0 | egrep "Feature|TRIM"
> ...


I checked and the drive does support it (as I knew it would). What extra parameters does fsck need? It was a fresh install BTW.


----------



## Terpentijn (Dec 8, 2020)

SirDice said:


> It should be on by default and has been the default for quite some time now. But I'm wondering why it would be off, perhaps your SSD doesn't support it? What brand/make/model is it?


Don’t know why it is not set. I did install on a partition and not the whole disk. Maybe that fooled the installer. No idea. I’ll set it manually if I know the right options for the fsck afterwards.


----------



## ralphbsz (Dec 8, 2020)

Terpentijn said:


> I checked and the drive does support it (as I knew it would). What extra parameters does fsck need? It was a fresh install BTW.


Is this UFS? If yes, first enable trim with tunefs. Read the man page, and look for the section that discusses trim; I vaguely remember the -t option. From now on, when files are deleted, the underlying blocks will be trimmed. But the blocks of already deleted files will not be trimmed. For that, you need to also run fsck_ffs with the -E flag. Before running that, please read the man page. And if this is your root file system, it probably has to be done in single-user mode (not sure about that, if you do -E only, it might be possible to do when mounted read-write).

For ZFS: Look here in older discussions; I haven't done ZFS with SSDs yet, so I don't remember how Trim is done.


----------

