Reduce disk I/O for small reads using memory

Many applications that are used on a standard server perform quite a few of small writes to the disk (like MySQL or Apache). These writes can pile up and limit the performance of your applications. If you have kernel 2.6.9 or later, you can adjust how these small writes are handled to allow for better performance.

There's two main kernel variables to know:

vm.dirty_ratio - The highest % of your memory that can be used to hold dirty data. If you set this to a low value, the kernel will flush small writes to the disk more often. Higher values allow the small writes to stack up in memory. They'll go to the disk in bigger chunks.

vm.dirty_background_ratio - The lowest % of your memory where pdflush is told to stop when it is writing dirty data. You'll want to keep this set as low as possible.

These might confuse you. In short, when your memory begins filling with little pieces of data that needs to be written to the disk, it will keep filling until it reaches the dirty_ratio. At that point, pdflush will start up, and it will write data until it reduces the dirty data to the value set by dirty_background_ratio.

Stock 2.6.9 kernels have a dirty_background_ratio of 10% and a dirty_ratio of 40%. Some distributions tweak these defaults to something different, so you may want to review the settings on your system. On a system with heavy disk I/O, you can increase the dirty_ratio and reduce the dirty_background_ratio. A little experimentation may be necessary to find the perfect setting for your server.

If you want to play with the variables, just use your standard echo:

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

Once you've found the right setting, you can set it permanently by adding lines to your /etc/sysctl.conf:

vm.dirty_background_ratio = 5
vm.dirty_ratio = 60

If you have a reliable server with a good RAID card and power supply, you could set the dirty_ratio to 100 and the dirty_background_ratio to 1. This was recommended by a buddy of mine who runs quite a few servers running virtual machines.

Printed from: http://rackerhacker.com/2008/08/07/reduce-disk-io-for-small-reads-using-memory/ .
© Major Hayden 2012.

2 Comments   »

  • Ramon says:

    Thanks for this useful post. Do you have any experience with kernel 2.6 and Citrix XenServer? Myself and a many more people on the Citrix XenServer forum have problems with Ubuntu 10.04 (2.6.32-23-server #37-Ubuntu SMP) and there is no idea to have a right host (dom0) configuration. If you have an idea please contact me.

  • Major Hayden says:

    Ramon -

    I know that Ubuntu 10.04 uses grub 2, but XenServer 5.5 doesn't support grub 2. There are a few guides on there about some workarounds to get it working.

Trackbacks/Pingbacks

  1. Flushing Cache to Disk under Linux « *nix Shell
  2. Debian tuning for increasing read/write buffer.

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this