# What's the status of TRIM for Linux?

## chix4mat

Hi all: 

http://en.wikipedia.org/wiki/TRIM

I've been following the status of TRIM on Linux for a little while, but I haven't been able to find up-to-date information to know whether or not using the feature is even an option today. Looking back through some kernel patches, it looks as though initial support for TRIM was included in the 2.6.28 kernel, but looking through 'makemenu config', I can't spot anything related to TRIM or SSD's in general.

I have an SSD here that's capable of TRIM, and I'd like to get it installed within the next few weeks, but knowing whether or not TRIM would even work would be nice. I'm willing to image and restore the drive to original settings every so often to regain initial performance, but that's less-than-ideal for obvious reasons. 

If anyone has any idea, I'd appreciate it. 

Thanks!

----------

## disi

Just what I found on the internet:

There seems to be one option in ATA "trim white blocks" (or something) 2.6.32-rc3, because there seems to be a patch for it.

To do it manually you could use hdparm... so they say.

I haven't tried it myself (still 2.6.30-r8 )   :Embarassed: 

----------

## the.root

Yeah i havent tried it yet either, waiting anxiously for a more stable kernel that supports it. You can still use your SSD in the meantime though, i'm sure you'll enjoy the speed  :Smile: 

----------

## disi

This is what man hdparm says about it:

 *Quote:*   

> --trim-sector-ranges
> 
>               For Solid State Drives (SSDs).  EXCEPTIONALLY DANGEROUS. DO  NOT  USE
> 
>               THIS  FLAG!!   Tells the drive firmware to discard unneeded data sec‐
> ...

 

----------

## the.root

 *disi wrote:*   

> This is what man hdparm says about it:
> 
>  *Quote:*   --trim-sector-ranges
> 
>               For Solid State Drives (SSDs).  EXCEPTIONALLY DANGEROUS. DO  NOT  USE
> ...

 

Sounds safe! Wanna test it out? lol

----------

## eccerr0r

I don't think this is what you want (hdparm trim).  The filesystem needs to be able to tell the underlying disk which sectors are now unused and available for TRIMming.  So really, it would be an ext2fs or whatever filesystem option to post the command to the disk.

This sort of is weird, basically a new mechanism needs to be added to vfs to hint to the disk which "sectors" could be discarded... retrofitting old filesystems seems to be a bit tricky...

----------

## Skotlex

I feel it is time for a bump, because it has been rather difficult to figure out the state of TRIM support on the kernel!

From what I've searched around, many sources hint at basic TRIM support in 2.6.33 , but there is nearly no documentation at all on how to use/enable it.

Some mention you are supposed to use the "discard" mount option, but the kernel documentation says this is only valid for Ext4 (look at Documentation/filesystems/ext4.txt), no other filesystem mentions this.

So should I believe there really isn't any TRIM support yet in 2.6.33?

----------

## gringo

 *Quote:*   

> Some mention you are supposed to use the "discard" mount option, but the kernel documentation says this is only valid for Ext4 (look at Documentation/filesystems/ext4.txt), no other filesystem mentions this. 

 

FYI btrfs has support for this too, in case you want to have a look to it :

http://btrfs.wiki.kernel.org/index.php/Changelog#Discard_support_for_SSD_devices

cheers

----------

## pigeon768

 *eccerr0r wrote:*   

> I don't think this is what you want (hdparm trim).  The filesystem needs to be able to tell the underlying disk which sectors are now unused and available for TRIMming.  So really, it would be an ext2fs or whatever filesystem option to post the command to the disk.
> 
> This sort of is weird, basically a new mechanism needs to be added to vfs to hint to the disk which "sectors" could be discarded... retrofitting old filesystems seems to be a bit tricky...

  Yes, it is a bit tricky. It requires involvement from the fs driver, the vfs, the hardware driver, and who knows what else. I know ext4 and the vfs support it, but I don't know to what extent, and I don't know how to enable it.

I'm guessing the hdparm option is part of the hardware portion of this capability.

----------

## Flow__

Seems like TRIM is know as "discard" in the ext4 options: https://sites.google.com/site/lightrush/random-1/howtoconfigureext4toenabletrimforssdsonubuntu

Flow

----------

## haarp

The Archlinux wiki tells me that the discard option in ext4 might be dangerous if it's enabled without proper support (AHCI + SSD with trim), so I've been reluctant to enable it. Is there a way to check whether my Intel SSD is attached via AHCI?

----------

## Flow__

Not sure, but I would try a 

```
dmesg | grep ahci
```

 after a fresh boot.

Flow

----------

## the.root

 *haarp wrote:*   

> The Archlinux wiki tells me that the discard option in ext4 might be dangerous if it's enabled without proper support (AHCI + SSD with trim), so I've been reluctant to enable it. Is there a way to check whether my Intel SSD is attached via AHCI?

 

A lot of motherboards BIOS' have the option to choose which way you want to emulate your hardrives. It might give you the option between things like: legacy, ahci, and sata. I also know you have "CONFIG_SATA_AHCI" in your kernel config. You could also spec dmesg as Flow suggested, lspci might tell you too `lspci |grep -i ahci`.

I'm not sure about ext4+ssd/TRIM needing AHCI for stability, havent read up on it.

----------

## lexming

Beware that not all the SSD drives have TRIM implemented. You should check with `hdparm -I`if your drive supports it. If it does then you can go ahead and add the discard flag.

----------

## ssteinberg

"discard" mount option for EXT4. Safe and working. Nothing new, been around since 2.6.32. Using it on my SSD for months. And yes, set your SATA to AHCI and not IDE, otherwise no TRIM.

----------

## bornmw

I have AHCI, Intel 320, and Ext4 with discard option.

But still my system doesn't pass the TRIM test:

https://sites.google.com/site/lightrush/random-1/checkiftrimonext4isenabledandworking

Does it mean TRIM isn't working? Where to look?

PS:

I've just rebooted and re-run hdparm --read-sector ADDR /dev/sda

Now it's zeroed

Is that normal? When TRIM should actually erase blocks - immediately or on restart?

Thanks!

----------

## Flow__

IIRC ATA TRIM is just there to inform the underlying block device that the data is not longer needed. So that, for example, an SSD can use this information for wear-leveling. Zeroing the data is not mandatory. It don't think that the HOWTO you mentioned is correct on its assumptions. Correct me if I am wrong.

Flow

----------

## Dammital

 *ssteinberg wrote:*   

> "discard" mount option for EXT4. Safe and working. Nothing new, been around since 2.6.32.

 

How does lvm2 complicate matters?  I have several ext4 filesystems on logical volumes.

----------

## Flow__

 *Dammital wrote:*   

> How does lvm2 complicate matters?  I have several ext4 filesystems on logical volumes.

 

As of http://comments.gmane.org/gmane.linux.lvm.general/12854, it seems that LVM passes the discard/TRIM information. The thread has also some interesting facts about the "TRIM functionality test":

If discard in ext4 is not working, you will see a message in dmesg.

It's up to the SSD to zero blocks that got trimed or not

----------

