Trim cronjobs versus discard on SSDs

Post your tutorials and howtos here.
Fargo
Posts: 896
Joined: 17 Sep 2013 14:40

Trim cronjobs versus discard on SSDs

Postby Fargo » 09 Dec 2013 02:18

I tried to do it using discard in fstab, but when I went to check if it was working it was not.

There are some good writeups here:
http://crunchbang.org/forums/viewtopic.php?id=13129
and here:
https://wiki.archlinux.org/index.php/SSD

Hopefully, Solyd will soon have some info like this available too.

Anyway, I finally decided to just use a different option and setup fstrim to run as a scheduled task. I have seen both methods recommended. So I don't know which is better. I suppose it varies on a persons needs. From what I read in this article, http://www.howtogeek.com/176978/ it sounds like Ubunty is going to implement the fstrim option in future releases. So its probably an ok method.

This webpage is the page that I used for a guide in setting up my TRIM job.
http://www.webupd8.org/2013/01/enable-t ... rives.html
The page has some good info. It shows both ways of setting up trim and even shows code to check if your SSD supports trim. Using that page as my guidelines, I decided that setting up my system to run TRIM on a weekly basis was sufficent. So here is how I set mine up:
To use a weekly cron job (so the trimming will occur once a week) for TRIM (fstrim), open /etc/cron.weekly/trim as root with a text editor (/etc/cron.daily/trim doesn't exist so this will create the file):

Code: Select all

gksu kate /etc/cron.weekly/trim
 and paste this:

Code: Select all

#!/bin/sh
LOG=/var/log/trim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG
fstrim -v /home >> $LOG

The last two commands in the code above perform the actual trimming for the root (/) and home (/home) partition and you need to edit them: here, add the SSD partitions for which you want to enable the daily TRIM job (usually, you must add "/" if the root partition is on the SSD and "/home" if you've set up a separate home partition).

Before saving the file, you can check if the fstrim command works:

Code: Select all

sudo fstrim -v /
The output should look similar to this:
andrei@ubuntu-desktop:~$ sudo fstrim -v /
/: 8158715904 bytes were trimmed
Once you've added your SSD partitions, save the file and make it executable using the following command:

Code: Select all

sudo chmod +x /etc/cron.weekly/trim
You can check the /var/log/trim.log log file to see the fstrim output.
I don't really know much about coding. I just picked this up from my research. Hopefully someone else can chime in if their are any errors in here. But I cross referenced the sites listed above so I think this should work.

EDIT: I also wanted to add that consideration could also be given to setting the swappiness of the harddrive. Along with changing things like the disk scheduler and noatime, nodiratime. But I really don't know enough about this stuff. So I didn't change any of that.

MOre info can be found here
http://chriseiffel.com/everything-linux ... -on-linux/

User avatar
wisemagic
Posts: 303
Joined: 13 May 2013 03:05
Location: New Iberia, Louisiana USA

Re: Solydxk installation on ssd

Postby wisemagic » 18 Jan 2014 06:45

Here is a quick how to on making a cron job for trim

Open a text editor and paste this code in it


#!/bin/sh
LOG=/var/log/trim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG


To ease confusion, save this file to your desktop for now as,
trim
( No .abc extension is needed )

Trim doesn't need to run more than once a month. Forget what you know about traditional spinning hard drives, SSD's have no moving parts. If you have discard in your fstab, remove it. discard in fstab is not recommended.

As root, copy the trim file you just made to /etc/cron.monthly ( a monthly trim is fine )
Start a terminal
sudo mv /home/YOUR USER NAME/Desktop/trim /etc/cron.monthly/
sudo chmod +x /etc/cron.monthly/trim ( This makes the trim script executable )

You can test it like this.

In a terminal
sudo /etc/cron.monthly/trim

You may not get any output for a minute. Just wait till it completes and returns you a command prompt.

You can view the log it produces by browsing to /var/log and look for trim.log. Open trim.log with a text editor.
If everything goes well, you can forget about trim from now on. It will run once a month automatically.

There are other things to consider such as alignment of the partition(s) on the SSD, disk scheduler, noatime, and swappiness.

There is a lot of discussion on writes to an SSD. An SSD cannot over write data. It has to erase the data and then write it. Some say this is additional wear on the drive. As that may be true, to a certain extent, it seems to be a bit of an over exaggeration. Using the drive as you would any spinning HDD, you should still get 8+ years out of it. By then you will want the next latest and greatest SSD or what ever they come out with in the future.

Mine is a Corsair 240 Gb and I spoke to the techs at Corsair before the purchase, because they are expensive! :shock:
I wanted to get an expert opinion and my build was for max performance. It took me a while to decide to go SSD vs Sata3 but I am happy I did. I use the noop scheduler, noatime in fstab.
I do not have a swap partition at all, and since I compile my own kernels and tweak them to only support my hardware, i also disable swap support in the kernel. Some say you have to have a swap partition. Not really, if you have enough ram. The machine will be 2 years old in June. Never had a memory issue, and actually never have used all of the ram. To hibernate you have to have a swap partition equal to the amount of installed ram, minimum. When I first set it up, I did a 16Gb swap partition. In the first 6 months, swap was never used. So I removed the partition and recompiled the kernel with swap support disabled. No need for me to waste 16 Gb of SSD, and I can live without hibernating.

I pre formatted my SSD before installation of SolydX with PartedMagic. The alignment was good and no adjustment was needed.

I run /home in a separate partition, so pre formatting was easier to do before installing the OS.

Hope this helps. :)

EDIT:
One other thing to consider with your fstab and only do this if you have the memory to spare...

If you browse a lot of pictures in thumbnail view with Thunar, the thumbnails are placed in your home folder in .thumbnails
Unless you use bleach bit or manually delete these thumbnails they stay there forever. And the folder grows and grows.
Add this to fstab puts them in memory
tmpfs /home/your-user-name/.thumbnails tmpfs defaults,noatime,mode=1777 0 0
On reboot they are wiped out automatically as the ram is initialized. ;)
E5-2690 Xeon - 16GB PC12800 DDR3 1600 Quad Channel -
Chinese HUANAN MB - GeForce GTX 960 4GB PCI Express 16X HDMI
Dual 480.0 GB SSD Corsair - Corsair H60 Liquid CPU Cooler - Blu-ray / DVD LightScribe Recorder
Debian Sid - Kernel 4.17.2-zen

Fargo
Posts: 896
Joined: 17 Sep 2013 14:40

Re: Solydxk installation on ssd

Postby Fargo » 18 Jan 2014 20:17

wisemajic - your directions look very similar to what I had posted direclty above them. Some minor differences in the commands but I think the end result should be pretty much the same.

I choose to use a weekly cron job. The site I initially got my info from was doing it daily, but I figured that was overkill. I think monthly is probably sufficient as well.

User_1
Posts: 9
Joined: 17 Mar 2017 04:14

Re: Solydxk installation on ssd

Postby User_1 » 01 Aug 2017 07:26

I have tried the two Trim scripts as recommended, and in each case, get an error message reporting that
fstrim: /: the discard operation is not supported
. In this case, it is SolydK 9 installed on an SSD. I was under the impression that this script explicitly avoided the DISCARD command in favour of TRIM. Is this no longer relevant on version 9?

Thanks, u1

User avatar
wisemagic
Posts: 303
Joined: 13 May 2013 03:05
Location: New Iberia, Louisiana USA

Re: Solydxk installation on ssd

Postby wisemagic » 01 Aug 2017 14:25

Can you run the trim command in a terminal ?
E5-2690 Xeon - 16GB PC12800 DDR3 1600 Quad Channel -
Chinese HUANAN MB - GeForce GTX 960 4GB PCI Express 16X HDMI
Dual 480.0 GB SSD Corsair - Corsair H60 Liquid CPU Cooler - Blu-ray / DVD LightScribe Recorder
Debian Sid - Kernel 4.17.2-zen

User avatar
ScottQuier
Posts: 1781
Joined: 18 Jul 2013 15:55
Location: Newport News, VA

Re: Solydxk installation on ssd

Postby ScottQuier » 01 Aug 2017 14:46

Might want to also run the command

Code: Select all

hdparm -I /dev/sdX
where "X" is the letter for the drive in question and then look through the results for the hard drive parameters for either a "discard" parameter or a line that reads "Data Set Management TRIM supported."
Scott
Quoting zerozero, "The usage of PPA's in debian-based
systems is risky at best and entails serious compatibility
problems; usually it's the best way to destroy an install"

User_1
Posts: 9
Joined: 17 Mar 2017 04:14

Re: Solydxk installation on ssd

Postby User_1 » 01 Aug 2017 20:35

Thanks.

Running the Trim in the terminal produces the same error.

The parameter check does indicate: "Data Set Management TRIM supported (limit 8 blocks)". I see no mention of "discard" in the results.

Is microcode a potential issue?

User avatar
wisemagic
Posts: 303
Joined: 13 May 2013 03:05
Location: New Iberia, Louisiana USA

Re: Solydxk installation on ssd

Postby wisemagic » 01 Aug 2017 21:29

Is your file system ext4? Do you have "Discard" in your fstab for this ssd?
E5-2690 Xeon - 16GB PC12800 DDR3 1600 Quad Channel -
Chinese HUANAN MB - GeForce GTX 960 4GB PCI Express 16X HDMI
Dual 480.0 GB SSD Corsair - Corsair H60 Liquid CPU Cooler - Blu-ray / DVD LightScribe Recorder
Debian Sid - Kernel 4.17.2-zen

srq2625
Posts: 29
Joined: 24 Feb 2016 13:39

Re: Solydxk installation on ssd

Postby srq2625 » 02 Aug 2017 02:23

User_1 wrote:Thanks.

Running the Trim in the terminal produces the same error.
The command is

Code: Select all

# fstrim -a -v
which, for me, produced

Code: Select all

/mnt/Data: 244.4 MiB (256258048 bytes) trimmed
/: 2.2 GiB (2367049728 bytes) trimmed
User_1 wrote: The parameter check does indicate: "Data Set Management TRIM supported (limit 8 blocks)". I see no mention of "discard" in the results.
This demonstrates that your SSD does, in fact, support the TRIM function.
User_1 wrote: Is microcode a potential issue?
Microcode is not going to be an issue. But, the firmware for you SSD might.
Just Scott

Remember that life is not measured by the number of breaths we take,
but by the moments that take our breath away!
-- Vicki Corona (Tahitian Choreographies, 1989)

User_1
Posts: 9
Joined: 17 Mar 2017 04:14

Re: Solydxk installation on ssd

Postby User_1 » 02 Aug 2017 06:22

Many thanks Scott.

Some success with this command. However, the operation seems to be limited to /boot. Perhaps on the fresh install there is simply nothing to trim. However, I did try it on another well used system, and similarly, only /boot received the operation. Can you suggest any reasons why?

User avatar
wisemagic
Posts: 303
Joined: 13 May 2013 03:05
Location: New Iberia, Louisiana USA

Re: Solydxk installation on ssd

Postby wisemagic » 02 Aug 2017 12:20

You are set up with a separate boot partition? If so, and the command is working on / boot, it is not trimming the root partition /. And if you have a separate home partition, /home, you'll need to run the trim command on it as well or use --all.

Check etc/fstab for "Discard" and take it out. Discard in fstab runs trimming in real time and will slow the system. Every change to files or any newly copied files will envoke trim with Discard in fstab. In essence, trim will run constantly, and that will wear on an SSD hard.

What brand SSD is this? You have AHCI set in your EFI, UEFI (Bios)??

Have you tried checking firmware for the SSD? Update it if there is a newer one. See if the manufacturer has a support forum to see if others have had to figure out a fix.

Also try
fstrim --all
If it returns 0 (all succeeded), 32 (all failed) or 64 (some failed, some succeeded).
E5-2690 Xeon - 16GB PC12800 DDR3 1600 Quad Channel -
Chinese HUANAN MB - GeForce GTX 960 4GB PCI Express 16X HDMI
Dual 480.0 GB SSD Corsair - Corsair H60 Liquid CPU Cooler - Blu-ray / DVD LightScribe Recorder
Debian Sid - Kernel 4.17.2-zen

User avatar
ScottQuier
Posts: 1781
Joined: 18 Jul 2013 15:55
Location: Newport News, VA

Re: Solydxk installation on ssd

Postby ScottQuier » 02 Aug 2017 13:38

User_1 wrote:Many thanks Scott.

Some success with this command. However, the operation seems to be limited to /boot. Perhaps on the fresh install there is simply nothing to trim. However, I did try it on another well used system, and similarly, only /boot received the operation. Can you suggest any reasons why?
If you've done anything, there will be something to trim. So, there's something else going on here...

The command as I posted above (fstrim -a -v) performs the operation on all mounted partitions for which TRIM is supported. The "-v" gives a one-line report on each partition.

In addition to what wisemagic has suggested, the output from these three commands

Code: Select all

sudo parted -l
inxi -Frzxx
cat /etc/fstab

would help us to know what storage hardware you have installed and how it's configured.
Scott
Quoting zerozero, "The usage of PPA's in debian-based
systems is risky at best and entails serious compatibility
problems; usually it's the best way to destroy an install"

User avatar
ilu
Posts: 2193
Joined: 09 Oct 2013 12:45

Re: Trim cronjobs versus discard on SSDs

Postby ilu » 02 Aug 2017 14:35

Since this very old thread originally had another topic I split it into the tutorial section to discuss trimming methods.

@topic: I had discard on in my fstab and thought that would sufficiently solve the problem. So just for testing purposes I entered

Code: Select all

~$ sudo fstrim -v /
/: 5,6 GiB (6021443584 bytes) trimmed
~$ sudo fstrim -v /someotherdir
/someotherdir: 61,6 GiB (66083008512 bytes) trimmed
Oops. this doesn't look as if discard worked, does it? So I might change tack.

User avatar
wisemagic
Posts: 303
Joined: 13 May 2013 03:05
Location: New Iberia, Louisiana USA

Re: Trim cronjobs versus discard on SSDs

Postby wisemagic » 02 Aug 2017 15:04

From fstrim manpage

"Running fstrim frequently, or even using mount -o discard, might negatively affect the lifetime of poor-quality SSD devices. For most desktop and server systems a sufficient trimming frequency is once a week. Note that not all devices support a queued trim, so each trim command incurs a performance penalty on whatever else might be trying to use the disk at the time"

I don't think running fstrim as root (sudo) works or is recommended.
E5-2690 Xeon - 16GB PC12800 DDR3 1600 Quad Channel -
Chinese HUANAN MB - GeForce GTX 960 4GB PCI Express 16X HDMI
Dual 480.0 GB SSD Corsair - Corsair H60 Liquid CPU Cooler - Blu-ray / DVD LightScribe Recorder
Debian Sid - Kernel 4.17.2-zen

User avatar
ilu
Posts: 2193
Joined: 09 Oct 2013 12:45

Re: Trim cronjobs versus discard on SSDs

Postby ilu » 02 Aug 2017 16:49

wisemagic wrote:I don't think running fstrim as root (sudo) works or is recommended.
I copy-pasted this from fargo's original post. It seemed to work and my system did not suffer - but you might be right.

User avatar
ScottQuier
Posts: 1781
Joined: 18 Jul 2013 15:55
Location: Newport News, VA

Re: Trim cronjobs versus discard on SSDs

Postby ScottQuier » 02 Aug 2017 16:54

wisemagic wrote: I don't think running fstrim as root (sudo) works or is recommended.
I've not been able to run fstrim except with elevated privs. Attempting to run from non-priv position, the command is not found.
Scott
Quoting zerozero, "The usage of PPA's in debian-based
systems is risky at best and entails serious compatibility
problems; usually it's the best way to destroy an install"

User avatar
wisemagic
Posts: 303
Joined: 13 May 2013 03:05
Location: New Iberia, Louisiana USA

Re: Trim cronjobs versus discard on SSDs

Postby wisemagic » 02 Aug 2017 17:40

Ok, .... trying to work from memory here. I'm using an Android tablet, 800 miles away from home. I'm a cross country truck driver layed over at a truck stop today.
Haven't done anything with trim in a few years since setting it up as a cron job. I only get a system email when it completes.
E5-2690 Xeon - 16GB PC12800 DDR3 1600 Quad Channel -
Chinese HUANAN MB - GeForce GTX 960 4GB PCI Express 16X HDMI
Dual 480.0 GB SSD Corsair - Corsair H60 Liquid CPU Cooler - Blu-ray / DVD LightScribe Recorder
Debian Sid - Kernel 4.17.2-zen

User avatar
ScottQuier
Posts: 1781
Joined: 18 Jul 2013 15:55
Location: Newport News, VA

Re: Trim cronjobs versus discard on SSDs

Postby ScottQuier » 02 Aug 2017 17:59

A bit off-topic: I purchased an Acer W500 for just such circumstances - wanting to be on a Linux box while on the road (traveling on vacation, I drive a desk for my 9-5). This thing is a couple of years old, has only 32GB SSD, but it has an i3 (I think, maybe i5) and seems to do quite well. Won't process photos or anything really requiring muscles, but it's a nice little toy.
Scott
Quoting zerozero, "The usage of PPA's in debian-based
systems is risky at best and entails serious compatibility
problems; usually it's the best way to destroy an install"

User avatar
wisemagic
Posts: 303
Joined: 13 May 2013 03:05
Location: New Iberia, Louisiana USA

Re: Trim cronjobs versus discard on SSDs

Postby wisemagic » 02 Aug 2017 18:51

ScottQuier, I'm working with an 10" ASUS Zenpad running Android Lolipop. I bought it simply because it's not Windows, and was cheaper than an iPad. Sadly .....it has made me quite aware that I despise Android. I've been doing battle with it to root it. It has a hidden partition with Windows ( .exe ) utilities for Windows users that plug it into a Windows machine USB slot. That partition is seen as a read only CD.
I'll bite the bullet and buy an iPad pretty soon, and this tablet will be a side project as far as rooting... lol
I did purchase a 64 gig memory card for it. Sometimes it sees it, and sometimes it doesn't.... not real reliable. And, there is no upgrades to newer Android versions. I basically use it when I'm hung up somewhere, like today, simply because it has a bigger screen than my iPhone. :D
E5-2690 Xeon - 16GB PC12800 DDR3 1600 Quad Channel -
Chinese HUANAN MB - GeForce GTX 960 4GB PCI Express 16X HDMI
Dual 480.0 GB SSD Corsair - Corsair H60 Liquid CPU Cooler - Blu-ray / DVD LightScribe Recorder
Debian Sid - Kernel 4.17.2-zen


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 1 guest