Tuesday, January 5, 2016

SSD tweaks for Ubuntu

SSD's have no moving parts which makes them faster and superior to HDD's, providing more bandwith , performance and response time . They stay cooler , use less power , are lighter more reliable and completely silent . If you have a low end system an SSD upgrade would speed things up significantly (RAM upgrade would be recommended as well in order to keep the system from using swap , which will wear down the SSD) .



These settings have been tested  on the a system with the following specs :

- AMD Quad Core APU-A6
- 8 GB RAM
- AMD Radeon HD 6520G
- Kingston SSD NOW 30GB
- Kingston SV300 120GB

We are going to begin this tutorial by checking the the Health of the SSD. Search for "Disks" in Unity Dash and launch it . 






Editing and making rc.local executable :
sudo gedit /etc/rc.local  
 ##Add the following above "exit 0"##
echo 0 > /sys/block/sda/queue/add_random (prevents the I/O of your SSD from cotributing to the entropy pool)

echo 0 > /sys/block/sda/queue/rotational (informs Ubuntu your are using an SSD)
echo 2 > /sys/block/sda/queue/rq_affinity (only use when you have a powerful CPU , if you experience lagging while gaming you can undo the changes by removing this line)
Save the file and make it executable by running : 

chmod +x /etc/rc.local

Moving Temporary Files to Memory (RAM):
Before starting this process it’s a good idea to backup the fstab file:

sudo cp /etc/fstab /etc/fstab.bak


The next step is to edit fstab:

gksudo gedit /etc/fstab 

Add the following 


"discard" - "Enables
 TRIM to help manage disk performance over the long-term."

"noatime" "Disables the updating of access time for both files and directories so that reading a file does not update their access time." 
"nodiratime" - "Disables updating of access time when opening directories so that the access time is not modified when enumerating directories. This routine also checks that the object is a directory, which slows down the routine."

 for "/" and add the next lines at the end of the file , as shown in the screenshot below:

tmpfs /tmp tmpfs defaults,noatime,size=1G,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0 
tmpfs /var/log/apt tmpfs defaults,noatime 0 0





The first line mounts /tmp in memory with a size limit of 1 gig. This may be larger than you need. If you exceed this limit the swap area will be used.
The second line mounts /var/tmp into memory. The third mounts the logfiles in /var/log–note this means that a reboot will clear your log files which may not be what you want. The fourth line mounts the temporary files associated with apt into memory.
The new mount points will become active on your next reboot.

Switching I/O Schedulers

First, list which options you have available with the following command, replacing “X” with the letter of your root drive:
cat /sys/block/sdX/queue/scheduler

To change the scheduler one must edit the grub entries :

sudo gedit /etc/default/grub


sudo update-grub
sudo reboot

If you happen to have tlp installed skip the previous step and edit tlp configuration to use "deadline" or "noop" scheduler :

sudo gedit /etc/default/tlp 

Uncomment the line and replace "cfq cfq" with "noop noop" (for SSD/SSD) or "noop cfq" (for SSD/HDD). 
"Deadline" and "noop" are recommended for SSD's and "cfq" is recommended to be used with HDD.






While these settings will improve performance the most noticeable gain can be achieved by installed linux-ck (Linux Kernel with the ck3 patchset featuring the Brain Fuck Scheduler) . We will go into more detail about linux-ck and the BFS in a different article . 

Tune Swappiness

You can check what the value of vm.swappiness is set to by:

sysctl -a | grep vm.swappiness


If you have a lot of RAM this tweak is for you .The swappiness value controls the Linux kernel’s tendency to swap – that is, move information out of RAM and onto the swap file on the disk. It accepts a value between 0 and 100. In order to change swappines value we need to /etc/sysctl.conf:


sudo gedit /etc/sysctl.conf


Look for vm.swappiness in the file and change its value. If it doesn’t exist, add it to the end of the file on a new line.

vm.swappiness=1 (1” is the minimum possible “active swapping” setting while “0” means disable swapping completely and only revert to when RAM is completely filled. Using these settings in low-spec systems of 2GB RAM or less may cause freezes and make the OS completely unresponsive)

sudo sysctl -p