SSD and TRIM

This forum is dedicated to advanced help and support :

Ask here your questions about advanced usage of Mageia. For example you may post here all your questions about network and automated installs, complex server configurations, kernel tuning, creating your own Mageia mirrors, and all tasks likely to be touchy even for skilled users.

SSD and TRIM

Postby BlueDragon » Feb 25th, '17, 06:58

Hi all,

I would like to implement TRIM for performance and lifespan purposes of my SSD. I found this interesting article about how to do it in Linux. What is the proper way to have a script run once a week to fstrim in Mageia 5.1? (NB: I'm very newbie in Linux command line.) Note: I have no encryption or LVM, just btrfs.

Thanks for your help.
BlueDragon
 
Posts: 54
Joined: Feb 22nd, '17, 20:47

Re: SSD and TRIM

Postby gohlip » Feb 25th, '17, 10:39

just btrfs.


This also reminds me. Do you get an error message when booting up? Something about "sparse file not found"?
If this is the error message you get, it is 'spurious' error; meaning that's okay and typing any key will continue to boot up.
There are ways to get rid of this error message (which I forgot and I don't use btrfs anymore, except one for my data partition).

[edit] - back to your original point on ssd and trim -
I think it's okay the way Mageia installs to ssd, but I'll let others answer this.
Why do we live? To prove not everything in nature has a purpose.
gohlip
 
Posts: 573
Joined: Jul 9th, '12, 10:50

Re: SSD and TRIM

Postby alf » Feb 25th, '17, 17:38

can simply be done by enabling the systemd fstrim timer(as described in the linked article)

as root in a console
Code: Select all
systemctl enable fstrim.timer


this will trim your ssd once a week.
for windows problems reboot; for linux problems be root
alf
 
Posts: 326
Joined: Apr 1st, '11, 23:07
Location: DE Paderborn

Re: SSD and TRIM

Postby jiml8 » Feb 25th, '17, 17:57

I have two SSDs in my system, sdc and sdd.

Sdc1 contains /, sdc5 contains miscellaneous things including a bunch of virtual machines, and sdd5 contains /home and another bunch of virtual machines. Sdd1 is swap, and I don't trim it.

I have installed several files on my system for the SSDs. This includes a service that changes the I/O scheduler for the SSDs to account for their random access nature, a reduction in system swappiness (I do this because I have lots of RAM and don't want to swap unless it is really necessary), and of course the program that does the trim.

I probably only gain 1 or 2 percent in performance by doing these things, but why not?

To handle setting the I/O scheduler and set the swappiness, I have created a service which is located in /etc/systemd/system and named configSSD.service:
Code: Select all
[Unit]
Description = Configure system for SSD drives

[Service]
ExecStart = /usr/local/bin/configSSD

[Install]
WantedBy = basic.target

This service calls the function /usr/local/bin/configSSD:
Code: Select all
#!/bin/bash
#  configure for SSDs
echo deadline > /sys/block/sdc/queue/scheduler
echo deadline > /sys/block/sdd/queue/scheduler
echo 10 > /proc/sys/vm/swappiness


In /etc/cron/daily, I have placed this script named fstrim (which I did not write; I found it and it works perfectly for me so I use it):
Code: Select all
#!/bin/sh
#
# To find which FS support trim, we check that DISC-MAX (discard max bytes)
# is great than zero. Check discard_max_bytes documentation at
# https://www.kernel.org/doc/Documentation/block/queue-sysfs.txt
#
LOG=/var/log/trim.log
echo "*** $(date -R) ***" >> $LOG
for fs in $(lsblk -o MOUNTPOINT,DISC-MAX,FSTYPE | grep -E '^/.* [1-9]+.* ' | awk '{print $1}'); do
        fstrim -v "$fs" >> $LOG
done
jiml8
 
Posts: 1253
Joined: Jul 7th, '13, 18:09

Re: SSD and TRIM

Postby BlueDragon » Feb 26th, '17, 07:30

alf wrote:can simply be done by enabling the systemd fstrim timer(as described in the linked article)

as root in a console
Code: Select all
systemctl enable fstrim.timer


this will trim your ssd once a week.


Just did it (simplest way for me now) and the system replied with "created symlink..."

Is there a way to verify that it will be running? Any log or something?

What about swapiness reduction (presently no swap but I will correct that)? Any simple way to tell the kernel to "reasonably" reduce the swapping?

Thanks!
BlueDragon
 
Posts: 54
Joined: Feb 22nd, '17, 20:47

Re: SSD and TRIM

Postby alf » Feb 26th, '17, 11:10

If you didn't do a reboot after enabling the timer you can start the timer with
Code: Select all
systemctl start fstrim.timer
(also as root).
To check the timer is running do
Code: Select all
systemctl status fstrim.timer
(need no root rights).
for windows problems reboot; for linux problems be root
alf
 
Posts: 326
Joined: Apr 1st, '11, 23:07
Location: DE Paderborn

Re: SSD and TRIM

Postby BlueDragon » Feb 27th, '17, 05:13

Thanks a lot alf for these advises. Easy and exactly what was needed.

Using the above status command, first the system replied "Loaded: loaded" but "Active: inactive (dead)" After the start command it changed to "Active: active (running) since..." So I guess now it should be executed weekly, though of course it would be interesting to know how to find out when exactly.

For those interested to read more about it, there is some good information here.
BlueDragon
 
Posts: 54
Joined: Feb 22nd, '17, 20:47

Re: SSD and TRIM

Postby BlueDragon » Feb 27th, '17, 05:59

About swappiness I found here this very useful code:

To temporarily set the swappiness in Linux, write the desired value (e.g. 10) to /proc/sys/vm/swappiness using the following command, running as root user:
Code: Select all
# Set the swappiness value as root
echo 10 > /proc/sys/vm/swappiness

# Alternatively, run this
sysctl -w vm.swappiness=10

# Verify the change
cat /proc/sys/vm/swappiness
10

# Alternatively, verify the change
sysctl vm.swappiness
vm.swappiness = 10

Permanent changes are made in /etc/sysctl.conf via the following configuration line (inserted, if not present):
Code: Select all
vm.swappiness=10
BlueDragon
 
Posts: 54
Joined: Feb 22nd, '17, 20:47

Re: SSD and TRIM

Postby marchugo » Dec 12th, '19, 17:52

BlueDragon wrote:
Using the above status command, first the system replied "Loaded: loaded" but "Active: inactive (dead)" After the start command it changed to "Active: active (running) since..." So I guess now it should be executed weekly, though of course it would be interesting to know how to find out when exactly.[/url].


If you execute this command in a konsole, then you see when the trigger is to be be triggered:

Code: Select all
# systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
   Loaded: loaded (/usr/lib/systemd/system/fstrim.timer; enabled; vendor preset: disabled)
   Active: active (waiting) since Thu 2019-12-12 16:46:36 CET; 4s ago
  Trigger: Mon 2019-12-16 00:00:00 CET; 3 days left
     Docs: man:fstrim
Last edited by doktor5000 on Dec 12th, '19, 19:06, edited 1 time in total.
Reason: added code tags
marchugo
 
Posts: 57
Joined: Sep 7th, '17, 13:55

Re: SSD and TRIM

Postby johnpenguin » Dec 14th, '19, 15:52

alf wrote:If you didn't do a reboot after enabling the timer you can start the timer with
Code: Select all
systemctl start fstrim.timer
(also as root).

Does this work with encrypted LVM setups? Then it would be far easier than the solution at https://forums.mageia.org/en/viewtopic.php?f=7&t=9732&p=65452#p65451.

Also is it possible to run this on demand? (For example you may wish to run it once per couple of months)
johnpenguin
 
Posts: 37
Joined: Feb 28th, '19, 02:15

Re: SSD and TRIM

Postby doktor5000 » Dec 15th, '19, 07:22

johnpenguin wrote:Does this work with encrypted LVM setups?

As far as I'm aware, it should, although you need to edit /etc/crypttab manually and add allow-discards option for each encrypted device.
See https://wiki.archlinux.org/index.php/Dm ... rives_(SSD)

And yes, you can also run fstrim manually.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17659
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany


Return to Advanced support

Who is online

Users browsing this forum: No registered users and 1 guest