rc-local & troubleshooting

Most perf settings in linux can be set from sysctl but there are a few that cant, and i would like to list a few and the best way to apply them. On occassion i have found my rc.local script not executing with upstart on ubuntu 14.04, this can be annoying as usually its executing important performance tweaks. For example readahead on block devices or transparent pages.

sudo blockdev --setra 4096 /dev/sda

This runs to set readahead on your disks. But if rc.local fails silently you can have machines running without your performance tweaks. This can be applied consistently across reboots with udev rules as below.

$ cat /etc/udev/rules.d/99-block_read_ahead.rules
SUBSYSTEM=="block", ACTION=="add", KERNEL=="sda", ATTR{bdi/read_ahead_kb}="1024"

Transparent huge pages also are common to be disabled in via rc.local.

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

A better more robust way to do this is to add it to your /etc/default/grub so that its disabled in grub at boot. This will stop any huge pages from being allocated before rc.local is executed, if it even is..

transparent_hugepage=never

This also applies to something like numa, it can be disabled in the BIOS of your machine. But you can also disable it from grub with similar appened option

numa=off