LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-09-2011, 11:17 AM   #1
ITPhoenix
Member
 
Registered: Mar 2011
Location: Northeast USA
Distribution: Debian Squeeze
Posts: 47

Rep: Reputation: 1
SSD Trim simple bash script program


Hi folks, I wrote this script which works but it should run automatically about once per week.

I hunted and experimented with KDE Task Scheduler (no dice and no help anywhere) and cron (confusing instructions and cannot edit crontab -e with vim, and cannot enter cron folders/files).

I would settle for a desktop shortcut to run the script but found no help for that.

Script:
Code:
#!/bin/bash
xterm -hold -e fstrim -v /
Machine:

OS: openSUSE 11.4 x86_64
Kernel: Linux 2.6.37.6-0.5-desktop
Desktop: KDE 4.6.00 rel 6
Machine: HP xw9400 AMD 64 Opteron
Chipset: nVidia nForce Pro 3600 and 3050 (proprietary Tyan Thunder)
Drive: OCZ Vertex 60 GB dedicated system--single boot
RAM: 4 GB ECC

Video: nVidia GT200 (GeForce 210) 512 MB
2D Driver: nouveau
3D Driver: swarst (no 3D acceleration) (7.10)

Audio: Creative Titanium Fatal1ty Pro
Driver: ALSA (No-frills. Must use open source controls)

I am not asking anyone to write code, I could use some pointers, though.

Thanks.
 
Old 07-09-2011, 12:20 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,744
Blog Entries: 1

Rep: Reputation: 224Reputation: 224Reputation: 224
cron would be the easiest. You should add your average, everyday user to the cron group to gain access to the necessary directories. Set EDITOR to vim and you will be able to edit crontabs with vim.
 
Old 07-09-2011, 12:23 PM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,592
Blog Entries: 2

Rep: Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047
I have some questions:
1. Which file-system do you use and what mount-options do you have for the partitions on your SSD?
2. Does the SSD have native TRIM support in its firmware?
 
Old 07-09-2011, 05:10 PM   #4
ITPhoenix
Member
 
Registered: Mar 2011
Location: Northeast USA
Distribution: Debian Squeeze
Posts: 47

Original Poster
Rep: Reputation: 1
Quote:
cron would be the easiest. You should add your average, everyday user to the cron group to gain access to the necessary directories. Set EDITOR to vim and you will be able to edit crontabs with vim.
Yes, this was not done and I suspect is why I cannot open some of the cron folders. I still do not understand how to edit in vim. There is a ghost entry from testing with KDE's Task Scheduler which I prefer to remove. The entry is not active--I grepped it and checked the cron folders for the entry. It was set for every minute to see if it worked, and it is apparent nothing is happening (at least to me).

Quote:
I have some questions:
1. Which file-system do you use and what mount-options do you have for the partitions on your SSD?
2. Does the SSD have native TRIM support in its firmware?
1. Ext4

Mount options: Default Mount by Device ID

2. Yes the drive has trim support. Here is the output of my script:

Code:
/: 16767717376 bytes was trimmed
I think I know where you are going. I saw something that erases useless data but I did not understand it.

Thanks for the input everyone.

Last edited by ITPhoenix; 07-09-2011 at 05:18 PM.
 
Old 07-09-2011, 05:17 PM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,592
Blog Entries: 2

Rep: Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047
If you use ext4 and your device has TRIM support you don't need your script to do the trimming. Just add the mount-option discard in your /etc/fstab to the partitions on the SSD. Now every-time a sync-command is launched (which is at least every shutdown/reboot) your partitions will automatically be trimmed.

You don't need to use vim for editing the crontab, you can use your favorite editor for that. Have a look at the crontab-command for learning how to make use of cron.
 
1 members found this post helpful.
Old 07-09-2011, 06:00 PM   #6
ITPhoenix
Member
 
Registered: Mar 2011
Location: Northeast USA
Distribution: Debian Squeeze
Posts: 47

Original Poster
Rep: Reputation: 1
Okay. This is what openSUSE recommends:
Quote:
As of 11.4, fstrim is part of the linux-util package and is the recommended choice for invoking trim for most users......To use the kernel realtime discard feature, you must mount with the "mount -o discard" option. openSUSE will not automatically set this option, so you must either mount the partition manually or update your /etc/fstab file to do so.

The kernel implementation of realtime trim in 11.2, 11.3, and 11.4 is not optimized. The spec. calls for trim supporting a vectorized list of trim ranges, but as of 2.6.39 trim is only invoked by the kernel with a single discard / trim range and with current late 2010 SSDs this has proven to cause a performance degradation instead of a performance increase. There are few reasons to use the kernels realtime discard support with pre 3.0.0 kernels. It is not known when the kernels discard functionality will be optimized to work beneficially with current generation SSDs.
The OCZ Vertex model I have is not a 2010 model but I plan on obtaining a RevoDrive when I can afford it. So I can use mount -0 discard now and appears to be the easiest solution. I saw mention that trimming the swap partition is not advised. This is irrelevant to my situation because of the 4GB RAM present (at least for now).

Here is the fstab file:
Code:
/dev/disk/by-id/ata-OCZ-VERTEX_MG05KW6J9686Z397B4P1-part1 swap                 swap       defaults              0 0
/dev/disk/by-id/ata-OCZ-VERTEX_MG05KW6J9686Z397B4P1-part2 /                    ext4       acl,user_xattr        1 1
/dev/disk/by-id/ata-OCZ-VERTEX_MG05KW6J9686Z397B4P1-part3 /home                ext4       defaults              1 2
/dev/disk/by-id/ata-WDC_WD1500HLFS-01G6U1_WD-WXD0CB984225-part1 /windows/C           ntfs-3g    users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0
proc                 /proc                proc       defaults              0 0
sysfs                /sys                 sysfs      noauto                0 0
debugfs              /sys/kernel/debug    debugfs    noauto                0 0
usbfs                /proc/bus/usb        usbfs      noauto                0 0
devpts               /dev/pts             devpts     mode=0620,gid=5       0 0
/dev/disk/by-id/ata-WDC_WD1500HLFS-01G6U1_WD-WXD0CB984225-part2 /local               ext4       defaults              1 2
Any pointers on how to add the mount -0 discard option?
 
Old 07-09-2011, 06:19 PM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,592
Blog Entries: 2

Rep: Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047
Simply add it after the other options, in your case that it looks like
Code:
/dev/disk/by-id/ata-OCZ-VERTEX_MG05KW6J9686Z397B4P1-part2 /                    ext4       acl,user_xattr,discard        1 1
/dev/disk/by-id/ata-OCZ-VERTEX_MG05KW6J9686Z397B4P1-part3 /home                ext4       defaults,discard              1 2
 
1 members found this post helpful.
Old 07-09-2011, 07:19 PM   #8
ITPhoenix
Member
 
Registered: Mar 2011
Location: Northeast USA
Distribution: Debian Squeeze
Posts: 47

Original Poster
Rep: Reputation: 1
This is good. I was just in the man page for fstab (as I should have been) and it gives:
Quote:
use default options: rw, suid, dev, exec, auto, nouser, and async
I see that you want to modify the options for /. I am wondering why the defaults are kept for home/ and not /

man mount (8) gives:
Quote:
discard/nodiscard
Controls whether ext4 should issue discard/TRIM commands to the underlying block device
when blocks are freed. This is useful for SSD devices and sparse/thinly-provisioned
LUNs, but it is off by default until sufficient testing has been done.
I will test it!
 
Old 07-09-2011, 07:32 PM   #9
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,592
Blog Entries: 2

Rep: Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047
Quote:
Originally Posted by ITPhoenix View Post
I see that you want to modify the options for /. I am wondering why the defaults are kept for home/ and not /
Sorry, but I don't understand that sentence. I simply have added the discard options to all partitions on that SSD, except the swap-partition. All other options are as given by you, I didn't modify them.
 
Old 07-09-2011, 08:00 PM   #10
ITPhoenix
Member
 
Registered: Mar 2011
Location: Northeast USA
Distribution: Debian Squeeze
Posts: 47

Original Poster
Rep: Reputation: 1
Sorry, I got confused. Ok, I will run with this. No news is good news; otherwise I will report back.

Thank you.
 
Old 07-10-2011, 11:03 AM   #11
ITPhoenix
Member
 
Registered: Mar 2011
Location: Northeast USA
Distribution: Debian Squeeze
Posts: 47

Original Poster
Rep: Reputation: 1
There was a false alarm with the last IFL backup. The backup image failure was a fluke (the disk is a little beat up).

So it appears adding

Code:
,discard
to fastab mount options is a workable way to go.

If an application would benefit from more frequent trims, then cron is the way to go.

One question, however. The script command I have is

Code:
xterm -hold -e fstrim -v /
Obviously the -v should go as well as the call for x-term in my original script. But will just the

Code:
 /
argument trim all the partitions?

There are two in fstab (disregarding swap, which should researched further).

In fact, the question which partition needs trimming has not been definitively answered AFAIK.
 
Old 07-10-2011, 11:47 AM   #12
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,592
Blog Entries: 2

Rep: Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047
All partitions on that SSD should need trimming, so I would do it for /home also.
If you do trimming with your script in crontab I wouldn't use xterm for that, unless you want that this window pops up every time cron trims the SSD.
 
1 members found this post helpful.
Old 07-10-2011, 06:16 PM   #13
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,287

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
Here's a reasonable guide to crontabs http://adminschoice.com/crontab-quic...Crontab%20file
 
1 members found this post helpful.
Old 07-11-2011, 12:05 AM   #14
ITPhoenix
Member
 
Registered: Mar 2011
Location: Northeast USA
Distribution: Debian Squeeze
Posts: 47

Original Poster
Rep: Reputation: 1
Thanks. The more the better.
 
  


Reply

Tags
kde, opensuse, ssd, trim


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] RAID 1 SSD drives with TRIM grolendaves Linux - Hardware 2 06-05-2011 08:44 AM
[SOLVED] TRIM on SSD mira.mikes Linux - Kernel 8 01-08-2011 06:36 PM
[SOLVED] Fedora 13 SSD TRIM Support Potatos Linux - Hardware 6 06-14-2010 03:17 PM
SSD TRIM support on Linux Thoreau Linux - Kernel 2 03-25-2009 04:05 AM
Simple Bash Shell Program frankblack Programming 2 02-14-2003 11:59 PM


All times are GMT -5. The time now is 01:44 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration