Sunday, August 12, 2012

Linux SSD optimalization

Since the SSD prices are dropping and it's still summer vacation so I have a more spare time than usual, I decided to upgrade one of my servers with an SSD. Since the server I upgraded is very multifunctional it could benefit a lot from optimization, it functions mainly as NAS (CrashPlan for Windows, Time Machine for OS X) but is also used as Home Theatre PC (XBMC).

Luckily there are a lot of resources about optimizing your SSD in Linux.

Very helpful resources were:
https://wiki.archlinux.org/index.php/Solid_State_Drives
http://www.void.gr/kargig/blog/2012/01/11/linux-ssd-partition-alignment-tips/

I ended up doing the following:

  • Partitioning the hard disk with gdisk, which helps me align the partitions
  • Use Logical Volume Management (lvm) 
    • Using the --dataalignment option (see also void.gr link) for the physical volume
    • Creating an ext4 partition on the logical volume with adjusted block size and stripe/stride-parameters
  • Mounting the ext4 partition with noatime and discard options
  • Using noop scheduler for the ssd's only (see script below)
  • Mounting /var/tmp and /var/log in ramdisk
  • Enable writeback (see script below)
  • Make the "swappiness" as low as possible
  • Use ionice to give XBMC priority over netatalk/crashplan when watching movies
    This is not because of the SSD, but I moved one of my RAID-0 harddisks from S-ATA600 to S-ATA300 because I expect the SSD will use the higher throughput better but apparently this caused problems (stuttering in movies) when a computer was backing up and watching a movie at the same time..
To set the scheduler and writeback to the right disks I modified the rc.local-script I found on the ArchLinux wiki:

declare -ar SSDS=(
        'ata-OCZ-AGILITY4_OCZ-xxxxx',
        'ata-SAMSUNG_SSD_830_Series_xxxxx'
)

for SSD in "${SSDS[@]}" ; do
  BY_ID=/dev/disk/by-id/$SSD

  if [[ -e $BY_ID ]] ; then
    DEV_NAME=`ls -l $BY_ID | awk '{ print $NF }' | sed -e 's/[/\.]//g'`
    SCHED=/sys/block/$DEV_NAME/queue/scheduler

    #scheduler
    if [[ -w $SCHED ]] ; then
      echo noop > $SCHED
    fi
   #writeback
   hdparm -W1 /dev/$DEV_NAME
  fi
done

I also used this opportunity to switch to UEFI and LVM. Especially the UEFI took a whole lot more than I expected. I will write an article about that later.

No comments:

Post a Comment