How to Implement Trim on SSD Drives


Recommended Posts

See below for a better implementation in unRAID 6.

 

Currently unRAID does not support mounting cache drives with trim support.  The trim support when mounting a drive is with the 'discard' switch.  I have done some research on trim in Linux and there are those that believe that mounting a drive with trim may cause the drive to do too much work whenever a file is written to the drive and that once a day issuing a 'fstrim' will suffice.

 

There is also some feeling that trim support when mounting a drive with a file system other that ext4 or BTRFS may not be ready for everyday use.

 

Trim lets the SSD know what the OS using the drive thinks is available space on the drive.

 

I have come up with a solution to support trim in unRAID until LT gets native trim support implemented for cache drives.  There is currently an open feature request for trim support here: http://lime-technology.com/forum/index.php?topic=34409.msg320174#msg320174

 

Put the following file on your flash drive in the 'custom' directory.

 

Trim script named 'DailyCacheTrim':

#
# Trim the SSD cache drive.
#
/sbin/fstrim -v /mnt/cache | logger

 

go file entry:

#
# Set up daily SSD cache trim for unRaid cron.
#
fromdos < /boot/custom/DailyCacheTrim > /etc/cron.daily/DailyCacheTrim
chmod +x /etc/cron.daily/DailyCacheTrim

 

With the output piped to logger ('| logger') the output of the fstrim will show in the log.  It simply displays the number of bytes trimmed.  This is normal operation and is the correct output.

 

The fromdos command is used to copy a file to Linux and insure the carriage return characters are removed and the output file is in Linux line feed format.  It prevents issues with editing a file with an editor that is not Linux file format compatible.

 

While the chmod +x may not be required, it just insures that the Linux file is executable.

 

A better method for unRAID 6

 

Dynamix has a built in cron system that is a better way to implement the SSD Trim.

 

Create a file called "trim.cron" and put it in the /flash/config/plugins/dynamix folder:

30 5 * * * /boot/custom/DailyCacheTrim &> /dev/null

 

This will be added to the cron events when unRAID is booted, or you can manually start it without a reboot by:

/usr/local/emhttp/webGui/scripts/notify cron-init

 

Remove the trim entries from the go file and delete the DailyCacheTrim file from /etc/cron.daily.

 

The SSD trim will be run at 5:30 AM daily.  You can adjust this for a different time of day, or once an hour as you see fit.  I think daily is sufficient.

Link to comment

After running 2 consecutive times:

fstrim -v /mnt/cache | logger

I get this log:

Jan 9 17:46:19 Tower logger: /mnt/vm: 60644368384 bytes were trimmed
Jan 9 17:52:11 Tower logger: /mnt/vm: 60644368384 bytes were trimmed

60644368384 bytes equals 56.479469299 GB. My hdd is 120GB.

Can anyone comment this output?

Should the secong run not be cero?

 

Link to comment

No.  I think that trim might be a bit of a misnomer.  Nothing is actually 'trimmed'.  The number shown from the fstrim operation is the number of available bytes on the SSD.  If no write operations have occurred between the two fstrim operations, then the number should be the same each time.  Your output on each fstrim is the expected output.

 

It looks like 60GB is available on your drive.

  • Like 1
Link to comment

It looks like 60GB is available on your drive.

 

You are right:

root@Tower:/boot# df -k
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1        7800304   101100   7699204   2% /boot
/dev/loop0          1843       97      1536   6% /etc/libvirt
[b]/dev/sdf1      117162564 57972240  59190324  50% /mnt/vm[/b]
/dev/md3       732216852    32928 732183924   1% /mnt/disk3

Link to comment
  • 2 months later...

I recently replaced my cache drive with a spare samsung ssd i had laying around and formatted it for BTRFS thinking that had trim support built in, is this incorrect?

My limited understanding (and hopefully someone else will chime in) is that XFS and BTRFS both support TRIM, but it either needs to be set upon mount or invoked with the fstrim command.

Link to comment

I recently replaced my cache drive with a spare samsung ssd i had laying around and formatted it for BTRFS thinking that had trim support built in, is this incorrect?

My limited understanding (and hopefully someone else will chime in) is that XFS and BTRFS both support TRIM, but it either needs to be set upon mount or invoked with the fstrim command.

 

I'm no expert on this matter, but that is my understanding as well.

Link to comment

Anyone know why I would get the following error?

 

fstrim: /mnt/cache: FITRIM ioctl failed: Operation not supported

 

Samsung SSD is formatted XFS.

 

Thanks!

 

Edit: Ugh.  Is this because it's hooked up to my M1015?

 

It's possible.  From what I understand (as I don't own an M1015) is that if you are running the IT firmware and the card is basically just an HBA, it should support TRIM.  That said, hopefully someone who has one can chime in as to whether or not they have an SSD attached to one and TRIM is working.  Another possibility would be to move the SSD to a motherboard SATA port and move the existing disk to the M1015?

 

Another thing to note is that even though we all feel better at night with TRIM support, a large majority of SSD's these days (including Samsung) do background garbage collection which largely negates the need for TRIM.

Link to comment

It's possible.  From what I understand (as I don't own an M1015) is that if you are running the IT firmware and the card is basically just an HBA, it should support TRIM.  That said, hopefully someone who has one can chime in as to whether or not they have an SSD attached to one and TRIM is working.  Another possibility would be to move the SSD to a motherboard SATA port and move the existing disk to the M1015?

 

Another thing to note is that even though we all feel better at night with TRIM support, a large majority of SSD's these days (including Samsung) do background garbage collection which largely negates the need for TRIM.

Hmm, well then I'm at a loss what could be preventing fstrim from running.  Perhaps its also because I'm running ESXi and the M1015 is being PCI passthrough to the unRAID VM.  Because of my ESXi setup, there's no way for me to pass through a single mobo SATA port, so I'm stuck on the M1015.

 

Some review site did a comparison of speeds of SSDs (including Sammys) with only garbage collection in use and then with TRIM.  TRIM'd drives were magnitudes faster.  But maybe I just need to accept the fact I won't be able to TRIM my cache drive.

Link to comment

One way to test if it's the ESXi passthrough would be to setup a fresh flash drive with unraid and try the SSD and fstrim as a normal drive without passthrough. That would be a good way of either confirming or eliminating ESXi's involvement.

That's a good idea.  But I don't even need to do a fresh flash.  I should be able to just remove the ESXi flash drive and boot from the unRAID flash.  I will probably unplug my ESXi datastore drives from the mobo first, however.

 

I'm kind of surprised, given the amount of people here who run a similar Atlas build clone haven't tried trimming their SSD cache drive.  Or haven't posted about it...

Link to comment

Some review site did a comparison of speeds of SSDs (including Sammys) with only garbage collection in use and then with TRIM.  TRIM'd drives were magnitudes faster. 

 

Hadn't come across that before.  Did a quick search and you are 100% correct.  Thanks for the info!

 

I can't seem to find this article. Your Google-Foo is better than mine (or you're more patient :)). Any chance someone could link to the specific article svp?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.