Wednesday, April 11, 2007

IO Performance

My laptop is becoming older and older. It's 512Mb of system memory are becoming insufficient for most uses but it's the slow hard disk (a FUJITSU disk, rotating at 5400 rpm, slow, slow, slow... but silent and no so hot) that is really making the system go down.

I use a main partition where the most of the system is installed with reiserfs 3.6. Some performance benchmark say it's a fast filesystem, other say that JFS has a smaller weight on CPU usage. I can't tell. But I needed to improve the way the system was using the hard disk.

Getting the most out of the hard disk

Using hdparm can get the hard disk to perform at it's most efficient level. Here are the parameter I'm using with for my hard disk:

-A1 -a128 -W1 -c1 -m16 -M254 -u1 -d1 -Xudma5 -B254 
With this parameters I set the disk to use Ultra DMA mode 5, 32 bits access, multi sector count, interrup unmask, write cache and read lookahed.

Tuning the memory management of Linux VM

The first thing was trying to use swap space as less as possible, as swapping means accessing the hard disk, the slow hard disk. That means using light applications, with small memory footprints. But I'm talking Linux here.. it was obvious that the behaviour of the system is be tunable For the virtual machine (the part of the operating system kernel responsible for managing the memory for programs - actually processes) the configuration is done by changing the values of files located in the directory /proc/sys/vm. One way is to actually write to the files, another way is to use sysctl. The latest is by far more elegant, unless you are just testing the parameters to use.

This are the parameter that I found provided my machine with some "interaction" speed, meaning that the machine might not be faster, but it feels so by not stopping so much because of waiting for the hard disk. This parameter are written to the file /etc/sysctl.conf.

# how strongly should the kernel try to swap out pages? [0-100]
# or, more simple, do we want mem for apps ou for cache.
vm.swappiness = 10

# Try to keep the inodes in mem (faster access to files)
vm.vfs_cache_pressure = 10

# This machine has a slow disk, so we want the kernel to do small swaps
#   force processes to starting writing to disk rather than to memory
vm.dirty_ratio = 2
#   the same as dirty_ratio but for pdflush
vm.dirty_background_ratio = 1

# let's try to have 2Mb of memory free all the time
# free memory = memory not used ;)
vm.min_free_kbytes = 2048

# this machine has little memory, so lot's of swapping.
# so we try to use a small value for page clustering
# (remember that's it's a logarithmic value, 0=1, 1=2, 2=4, 3=8, ...)
vm.page_cluster = 2

After having added this I used the following command to update all the parameters that I have defined:

sysctl -p

Tuning access to the hard disk device

All this increase my chances of not having the machine trashing. Also access to the hard disk can be configured by, again, changing the values of files. This time this files are located in /sys/block/<device>/. This time we need to write to the files to change the values of the parameters (no fancy sysctl now). There are several ways to do write to files, but a easy way is to use the command "echo value > filename".

  • setting the queue scheduler to CFQ (Complete Fair Queuing), a good choice for desktop systems:
    echo cfq > sys/block/<device>/queue/scheduler
  • increasing the number of request that can be in the queue to 1024:
    echo 1024 > /sys/block/<device>/queue/nr_requests
  • setting the maximum number of requests move in each round of service:
    echo 4 > /sys/block/<device>/queue/iosched/quantum

Now the access to the physical hard disk should be a little bit more efficient.

ReiserFS tuning

Although a great filesystem, ReiserFS (version 3.6) lacks documentation on the available mount options. The mount man page provides the possible choices, but their description doesn't help to know what are they intended function.

What I could find out is that using the the options noatime and notail the performance increased at least a little bit.

  • noatime - don't update the inode access times
  • notail - disable ReiserFS from packing files intro it's tree

And that's it. My system is now a tiny little bit more usable.

No comments: