HOWTO: Optimize Linux For SSDs
BE SURE TO USE EXT2 WITH NOATIME
Journaling adds writes. If possible, specify ext2 with the noatime option during install. If you specified ext3, you can switch over to ext2 with no hassle. If you didn’t specify ext2 and/or noatime at install, you can do it afterwards by editing /etc/fstab.
sudo nano /etc/fstab
Look at the line that contains partitions that are on the SSD. It should look something like this:
UUID=1eea26d7-6893-4779-827b-150412c94703 / ext2 relatime 0 1
Replace ext3
with ext2
and relatime
or defaults
with noatime
CHANGING THE TASK SCHEDULING ALGORITHM
sudo nano /boot/grub/menu.list
Press CTRL+W to find the string # kopt. It should look something like this:
# kopt=root=UUID=1eea26d7-6893-4779-827b-150412c94703 ro
Add the option elevator=noop
so that it looks like this:
# kopt=root=UUID=1eea26d7-6893-4779-827b-150412c94703 ro elevator=noop
Make the changes take effect.
sudo update-grub
SAVING WRITES WITH TMPFS
sudo gedit /etc/fstab
Insert these lines into the file:
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
This will cause some packages to fail mysteriously when they cannot access the log directories that were installed with the packages and then disappeared at reboot. To rebuild the directory structure inside /var/log on each reboot, add these lines to /etc/rc.local above the ‘exit 0’ line:
for dir in apache apparmor apt cups dist-upgrade fsck gdm installer news samba unattended-upgrades ; do
mkdir -p /var/log/$dir
done
MOVE FIREFOX’S CACHE TO RAM
Open Firefox, type about:config
in the address bar, and press Enter. In an empty space on the screen, right-click and create a new String value browser.cache.disk.parent_directory
and set it to /tmp
. This will have to be done for each user.
anonymous 10:17 am on July 1, 2009 Permalink |
thx very much.
works great!
Heiko 7:22 am on November 11, 2009 Permalink |
This will reduce writes, but at a cost:
a) A journal is nice to have, some operations are faster (since only done to the journal), and in particular you skip fsck if somethink crashes. But the ext3 journal is highly tuneable (and it can even be switched off, without moving to ext2)
b) tmpfs for /tmp and /var/tmp might be a good idea, but you loose the contents on reboot. YMMV
c) tmpfs for /var is a very bad idea. /var is there to keep track of changes to your system. How are you going to debug your system after a crash if all debug-info is volatile? What happens to your unread mail in /var/mail/ after a reboot? tmpfs for /var is a guarantee to get unhappy.
brainwreckedtech 4:01 pm on November 11, 2009 Permalink |
a) ext3 is backwards-compatible with ext2. You can literally tell Linux to mount an ext3 partition as ext2 and everything works fine. From my research, there has been no ext3 journal settings recommended for SSD. It’s always been “just turn of the journal.”
b) Nothing of value is supposed be to stored in /tmp and /var/tmp. If there is, the application doing the writing is doing it wrong.
c) tmpfs for /var IS a bad idea, which is why I recommended only /var/log and /var/tmpfs. /var/log is a touchy area because *so much* logging goes on in there that it really does bring up the question, “Is /var/log worth it?” When bringing up the debugging issue, one has to ask themselves, “How often did /var/log help me solve an issue that didn’t occur on every boot?” For me it was once in four years but it happened every time I booted. Hence, /var/log can be tmp’d.
Guest 11:13 am on August 15, 2010 Permalink |
Thanks!
I changed fstab to limit the memory allocated since I’m on an older 1GB T42:
tmpfs /var/log tmpfs defaults,noatime,mode=0755,size=75M 0 0
tmpfs /tmp tmpfs defaults,noatime,mode=1777,size=100M 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777,size=20M 0 0
Using ext4 on Lucid, but other than that I followed all your advice. Very nice info, TYVM!
Anonymous 11:00 pm on September 27, 2011 Permalink |
SSD is great, but not for /var IMHO. If possible, put /var on a HDD or other medium which doesn’t have write limitations.
Install and run GNU/linux Mint 11 from a usb memory stick « Anders Andreasen Blog 4:10 pm on November 19, 2011 Permalink |
[…] also considered adding some of the /var stuff into RAM, but I haven’t com so far […]
Aris 4:47 pm on September 22, 2012 Permalink |
Thanks for the great info, although I have found a -small- bug. You see, rc.local starts last in most distros when changing rc levels, while apache (or other services) might start first. This can be solved by prioritizing a new script that creates the folders in /var/log
In ubuntu (or any other debian based distro) one can create a file in /etc/init.d (bash script – maybe change apache to apache2 as well with exit 0 in the end of course) and then do a “sudo update-rc.d $THE_FILENAME_IN_INIT.D$ defaults 01” which creates all symlinks in rc0.d – rc6.d for your script. This way, the folders are created in /var/log and apache starts correctly on boot!