Linux OS Tuning/Optimizations

Change to ‘deadline’ I/O scheduler

  • From command line (change the device ‘sda’ to appropriate device):
echo "deadline" > /sys/block/sda/queue/scheduler
  • kernel parameter, change /boot/grub/menu.lst, add kernel parameter

Change VM parameters

There are two variables which control the behaviour of VM flushing and allocation and affect network and disk performance

  • vm.dirty_background_ratio
  • vm.dirty_ratio

To set these values from command line

echo 20 > /proc/sys/vm/dirty_background_ratio
echo 60 > /proc/sys/vm/dirty_ratio

to make it permanent, edit /etc/sysctl.conf:

vm.dirty_background_ratio = 20
vm.dirty_ratio = 60


Increase readahead

To get current readahead value:

$ blockdev --getra /dev/sda 256

To increase it to a higher value like 16K:

$ blockdev --setra 16384 /dev/sda

Disable updating access time stamp for file system

Edit /etc/fstab, remove “atime” attribute if there is, add “noatime” attribute. The noatime change can significantly improve your server’s file i/o performance.

#sample /etc/fstab line before change
LABEL=/                 /                       ext3    defaults        1 1

#sample /etc/fstab line after noatime change
LABEL=/                 /                       ext3    defaults ,noatime       1 1

Kernel Network Tuning

Add the follwing to /etc/sysctl.conf

#increase local ports
net.ipv4.ip_local_port_range = 1024 65535

#reduce the number of time_wait connections
#these 3 lines can reduce your time_wait count by several hundred percent.
#however you should not use the following lines in a NATed configuration.
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30

Then call sysctl to make them active

sysctl -p 
Linux OS Tuning/Optimizations

3 thoughts on “Linux OS Tuning/Optimizations

  • October 11, 2012 at 8:49 pm

    Can you elaborate on why you chose those values for the vm.* tunnables?


  • October 12, 2012 at 6:10 am

    vm.dirty_background_ratio, which is a percentage of total system memory, the number of pages at which the pdflush background writeback daemon will start writing out dirty data. However, for fast RAID based disk system this may cause large flushes of dirty memory pages. If you increase this value from 10 to 20 (a large value) will result into less frequent flushes

    which a process which is generating disk writes will itself start writing out dirty data. This is nothing but the ratio at which dirty pages created by application disk writes will be flushed out to disk.

  • March 8, 2014 at 4:13 pm

    An important note for blockdev –getra /dev/sda 256, being a block device this value is set in blocks. The man page says 512 byte sectors but it may be in fact reporting 4k sectors on a modern disk (if –getpbsz returns 4096).


Leave a Reply

Your email address will not be published. Required fields are marked *

Fork me on GitHub