LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 05-24-2018, 05:17 AM   #1
nigelc
Member
 
Registered: Oct 2004
Location: Sydney, Australia
Distribution: Mageia 7
Posts: 406
Blog Entries: 4

Rep: Reputation: 80
How often should I use use fstrim?


My first drive is an ssd drive which contains the system + /var etc. Not much other data ever gets put there so I hardy ever run fstrim.

The question is How often should I run fstrim?



Code:
 df shows this
df
Filesystem Size Used Avail Use% Mounted on
devtmpfs 12G 0 12G 0% /dev
tmpfs 12G 3.1M 12G 1% /dev/shm
tmpfs 12G 1.1M 12G 1% /run
/dev/sda1 102G 7.5G 89G 8% /
tmpfs 12G 0 12G 0% /sys/fs/cgroup
tmpfs 12G 4.0K 12G 1% /tmp
/dev/sdb1 1.8T 480G 1.3T 28% /home
tmpfs 2.4G 0 2.4G 0% /run/user/983
tmpfs 2.4G 44K 2.4G 1% /run/user/500
[nigel@localhost ~]

[/code]

Last edited by nigelc; 05-24-2018 at 05:20 AM.
 
Old 05-24-2018, 06:21 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,131

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Did you consider that the manpage might be a good place to start ?.
 
Old 05-26-2018, 01:13 AM   #3
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
fstrim runs automatically on most ditros.
 
Old 05-26-2018, 07:28 AM   #4
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,664

Rep: Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710
What format is your file system and is it mounted using the "discard" option?

This is not distribution specific, but file system specific.

If you are using a file system that understands SSD and has the "discard" option then it does "trim" dynamically and automagicly as blocks are allocated and deallocated. For those file systems you might never need fstrim, but running it once per week or month will not hurt.

If your file system does not understand and detect SSD, and does not mount with "discard", then you might want to run fstrim on a schedule, but how often will depend upon your priorities and usage patterns.

So, how have you formatted your file systems?
 
1 members found this post helpful.
Old 05-26-2018, 08:34 AM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by AwesomeMachine View Post
fstrim runs automatically on most ditros.
does it not require an entry in fstab to tell it where to run each time it boots up? I put a script in my cron.weekly to gett'er done.
 
1 members found this post helpful.
Old 05-27-2018, 06:22 AM   #6
nigelc
Member
 
Registered: Oct 2004
Location: Sydney, Australia
Distribution: Mageia 7
Posts: 406

Original Poster
Blog Entries: 4

Rep: Reputation: 80
Hello,

Quote:
What format is your file system and is it mounted using the "discard" option
The drive is formatted as an ex4 file system and is not mounted using the discard option.
mount says:

Code:
/dev/sda1 on / type ext4 (rw,relatime,data=ordered)
Cheers Nigel

Last edited by nigelc; 05-27-2018 at 06:27 AM. Reason: Mistake
 
1 members found this post helpful.
Old 05-27-2018, 09:47 AM   #7
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,664

Rep: Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710Reputation: 2710
Quote:
Originally Posted by nigelc View Post
Hello,



The drive is formatted as an ex4 file system and is not mounted using the discard option.
mount says:

Code:
/dev/sda1 on / type ext4 (rw,relatime,data=ordered)
Cheers Nigel
EXT4 is a great file system, but it does not autodetect SSD and does not add "discard" by default. You can change the mouont to include that option, as it is supported in the newer ext4 drivers. Check your man pages for detail.

If you do NOT add the option, or if it is not supported at your level, then run fstrim either on boot or a safe schedule for your usage profile. (Your usage profile is based upon how often files change allocations on your disk. The more often you change the disk allocation the more often you should trim the fs. )

NOT adding the discard option is valid, as dynamic trim can impact performance. If you need the maximum I/O speed from the SSD, do not enable discard on mount, but do run fstrim.

Note that there is not much advantage in doing trim on only one level. Someone using crypt, lvm, and ext4 would have to enable trim at three different levels to resolve all of the allocation repair. If you keep things simple life is easier, and this is very doable.

See interesting discussion here http://blog.neutrino.es/2013/howto-p...m-and-dmcrypt/ and here https://sites.google.com/site/easylinuxtipsproject/ssd


Using a file system (btrfs for example) that has SSD autodetection and handling might work for you.
 
1 members found this post helpful.
Old 05-28-2018, 12:14 AM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
thanks for the info; i had a look at the "easylinuxtips" link, but then also had a look at my native https://wiki.archlinux.org/index.php/SSD - it had this to say about discard:

Quote:
Warning: Unfortunately, there are wide quality gaps of SSD's bios' to perform continuous TRIM, which is also why using the discard mount flag is recommended against generally by ext filesystem developer Theodore Ts'o. If in doubt about your hardware, apply #Periodic TRIM instead.
since i bought the cheapest SSD available, i did that:

Quote:
The util-linux package provides fstrim.service and fstrim.timer systemd unit files. Enabling the timer will activate the service weekly.
the arch wiki does not mention noatime, but i think i'll try it at least.
 
1 members found this post helpful.
Old 05-28-2018, 12:30 AM   #9
nigelc
Member
 
Registered: Oct 2004
Location: Sydney, Australia
Distribution: Mageia 7
Posts: 406

Original Poster
Blog Entries: 4

Rep: Reputation: 80
Thanks for the info:
It seems to be there in systemctl, but not enabled.

Code:
 systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
   Loaded: loaded (/usr/lib/systemd/system/fstrim.timer; enabled; vendor preset:
   Active: inactive (dead)
     Docs: man:fstrim
Half an hour later

The question is How I enable it?

I may have got it now. I think it runs on Monday morning.

Code:
 systemctl start fstrim.timer
[root@localhost ~]# systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week    {The dot thing is now green}
   Loaded: loaded (/usr/lib/systemd/system/fstrim.timer; enabled; vendor preset:
   Active: active (waiting) since Mon 2018-05-28 15:38:51 AEST; 6s ago
     Docs: man:fstrim
cheers.

Last edited by nigelc; 05-28-2018 at 12:45 AM. Reason: To add in more stuff:
 
1 members found this post helpful.
Old 05-28-2018, 01:26 AM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
you also need to enable it (otherwise it won't restart upon systemd restart, reboot that is):
Code:
systemctl enable fstrim.timer

Last edited by ondoho; 05-28-2018 at 07:24 PM.
 
2 members found this post helpful.
Old 05-28-2018, 06:00 AM   #11
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
here is a web page that explains trim and discard, and shows how to set up either one of them.

http://www.webupd8.org/2013/01/enabl...te-drives.html


(I posted this somewhere, I thought it was in here, now I wonder which thread it is in)
 
1 members found this post helpful.
Old 05-29-2018, 01:58 AM   #12
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Quote:
Originally Posted by BW-userx View Post
does it not require an entry in fstab to tell it where to run each time it boots up? I put a script in my cron.weekly to gett'er done.
Ideally, I guess it's best to check before assuming.
 
Old 05-29-2018, 06:58 AM   #13
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by AwesomeMachine View Post
Ideally, I guess it's best to check before assuming.
to run trim at boot up : fstab : on a time schedule cron : or command line using a calendar to keep track of time past. forming a question eliminates the assumption and puts the burden on the second party. And from what @ondoho posted it looks like their is even another option now out there that I did not know about, as I don't systemD (much).

systemctl enable fstrim.timer
 
2 members found this post helpful.
Old 06-06-2018, 02:52 AM   #14
nigelc
Member
 
Registered: Oct 2004
Location: Sydney, Australia
Distribution: Mageia 7
Posts: 406

Original Poster
Blog Entries: 4

Rep: Reputation: 80
Hi,
I think it has worked now..

Code:
 ~]# journalctl -u fstrim
-- Logs begin at Sun 2018-01-14 16:00:11 AEDT, end at Wed 2018-06-06 17:35:28 AEST. --
Jun 04 11:01:49 localhost.localdomain systemd[1]: Starting Discard unused blocks...
Jun 04 11:01:51 localhost.localdomain systemd[1]: Started Discard unused blocks.
Thanks for the help
 
1 members found this post helpful.
  


Reply

Tags
fstrim



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 09:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration