UFS Disable trim on ssd permanently

Hi,

I have a FreeBSD box which filesystem on ssd which has the trim-option enabled.

Sadly it's a cheap ssd which doesn't support trim. Of course, I could disable it with tunefs, but that doesn't last long. After the second reboot, the filesystem has it reenabled.

Is there a way - through sysctl or loader.conf.local etc. to disable it on every boot?

Thanks in advance!
 
It's a:
Code:
ada0 at ahcich0 bus 0 scbus0 target 0 lun 0
ada0: <FORESEE 64GB SSD V4.6> ACS-3 ATA SATA 3.x device
ada0: Serial Number K43581J014250
ada0: 600.000MB/s transfers (SATA 3.x, UDMA6, PIO 512bytes)
ada0: Command Queueing enabled
ada0: 61057MB (125045424 512 byte sectors)
😏
 
It will only use trim on devices that support it. Leave it on and you will be fine.

As to procedure, how did you disable trim? Did you run tunefs on a mounted filesystem? It only works on umounted filesystems because whatever is cached in the kernel's copy of the superblock will get written out again when the filesystem is unmounted.

Running tunefs on a mounted filesystem does nothing because the in-kernel copy of the superblock is what the kernel uses.

If you want to disable trim on a running system, boot single user. Make sure that / is mounted read-only. Run tunefs then either continue the boot or reboot.

But again, as I said above, if your device doesn't support trim, it won't use it.

BTW, trim doesn't incur any additional wear on the SSD. Each block can be written only once before it needs a trim. If you don't trim the device will erase (trim) the block itself, even if it doesn't support a trim function in the SCSI or ATA protocol. It still does trim on a block-by-block basis as needed. This is slow.
 
If you want to disable trim on a running system, boot single user. Make sure that / is mounted read-only. Run tunefs then either continue the boot or reboot.

Yes, that's what I did. After the reboot, trim was disabled and after another reboot, trim is enabled again.

The problem was, why I tried to disable trim, that I got the following error-messages:

Code:
ahcich0: Timeout on slot 16 port 0
ahcich0: is 00000000 cs 00000000 ss 00010000 rs 00010000 tfd 50 serr 00000000 cmd 0000cd17
(ada0:ahcich0:0:0:0): SEND_FPDMA_QUEUED DATA SET MANAGEMENT. ACB: 64 01 00 00 00 40 00 00 00 00 00 00
(ada0:ahcich0:0:0:0): CAM status: Command timeout
(ada0:ahcich0:0:0:0): Retrying command, 3 more tries remain

after disabling trim, the error-messages aren't thrown anymore.

And therefore, my idea was to disable trim...

My first try was to disable trim through /etc/fstab with a *notrim* as an option for the filesystem, but that options seems to be unknown and I had to repair the stab in single-user mode.

My second idea is now, if there's a loader.conf or sysctl entry ...
 
The device doesn't support queued trim command (SATA3.1) or it fail to return status after it. There's different trim types link and look line you are not alone with this drive with the same issue link

For UFS you need to boot into single user mod then use
tunefs -t disable / (where '/' is your root device filesystem)

Also check
fsck_ffs(8) with "-E" flag
 
Yes, that's what I did. After the reboot, trim was disabled and after another reboot, trim is enabled again.

The problem was, why I tried to disable trim, that I got the following error-messages:

Code:
ahcich0: Timeout on slot 16 port 0
ahcich0: is 00000000 cs 00000000 ss 00010000 rs 00010000 tfd 50 serr 00000000 cmd 0000cd17
(ada0:ahcich0:0:0:0): SEND_FPDMA_QUEUED DATA SET MANAGEMENT. ACB: 64 01 00 00 00 40 00 00 00 00 00 00
(ada0:ahcich0:0:0:0): CAM status: Command timeout
(ada0:ahcich0:0:0:0): Retrying command, 3 more tries remain

after disabling trim, the error-messages aren't thrown anymore.

And therefore, my idea was to disable trim...

My first try was to disable trim through /etc/fstab with a *notrim* as an option for the filesystem, but that options seems to be unknown and I had to repair the stab in single-user mode.

My second idea is now, if there's a loader.conf or sysctl entry ...
Ahh. Your device advertises to the kernel it supports trim where in fact it does not.

You're best to disable trim on the one filesystem. There is a reason there is no sysctl to disable trim globally. There is no need for it globally when it can be disabled on a filesystem-by-filesystem basis.

IIRC trim/notrim are mount options available on Linux for EXT4. The EXT4 fs doesn't have a trim bit in its superblock so Linux users are only left with a mount option.

Reading through the datasheet for that model of SSD, it says trim is supported. My guess is your SSD may be faulty or trim may not be correctly implemented in its firmware.

Simply boot into single user state. Make sure the root filesystem is mounted read-only: mount -u -oro /. Then disable trim using tunefs and reboot.
 
Simply boot into single user state. Make sure the root filesysm is mounted read-only: mount -u -oro /. Then disable trim using tunefs and reboot.

Thanks a lot, that's what I did.
And if I print the values with "tunefs -p /", it shows that trim is disabled. But after a reboot, trim is enabled again.

Is there a way to keep that permanent?
 
1. Boot into single-user
2. tunefs -p / /* trim is enabled */
3. tunefs -t disable /
4. tunefs -p / /* trim is disabled */
5. shutdown -r now /* standard boot */
6. reboot. /* standard boot */
7. tunefs -p /* trim is enabled */
 
i will try to reproduce it on my laptop.

Edit:
The steps that you perform are correct. I can enable/disable the trim and the settings are saved after reboot.
 
Thanks a lot, that's what I did.
And if I print the values with "tunefs -p /", it shows that trim is disabled. But after a reboot, trim is enabled again.

Is there a way to keep that permanent?
Well, I don't know. This works for me, and after testing the approach, just now on my sandbox machine, the method still works. You must be doing something wrong. Without actually standing over your shoulder and watching you type in the commands, I can't say what you're doing wrong.
 
What happens if the -A option is specified for tunefs?
tunefs(8)
Code:
     -A      The file system has several backups of the super-block.
               Specifying this option will cause all backups to be modified as
               well as the primary super-block.  This is potentially dangerous -
               use with caution.
 
What happens if the -A option is specified for tunefs?
tunefs(8)
Code:
     -A      The file system has several backups of the super-block.
               Specifying this option will cause all backups to be modified as
               well as the primary super-block.  This is potentially dangerous -
               use with caution.
You don't need to do this. Updating the main copy is simply enough.
 
:) I manage to "trim" my partition.
It's Good it's only testing laptop so no data was lost

Try to run fsck from the single user mode.
 
Thanks a lot for all your replies!

I ordered a new mSATA (Transcend) and switched the HD and everything works as expected now!
Why my *trim -t disable* isn't permanent, I don't know :-(

But everything works now, thanks a lot!
 
Back
Top