Chapter 4. Tuning the operating system 111
Draft Document for Review May 4, 2007 11:35 am 4285ch04.fm
parameter stored in /proc/sys/vm/dirty_ratio the system administrator can define at
what level the actual disk writes will take place. The value stored in dirty_ratio is a
percentage of main memory. A value of 10 would hence mean that data will be written into
system memory until the file system cache has a size of 10% of the server’s RAM. As in
the previous two examples, the ratio at which dirty pages are written to disk can be altered
as follows to a setting of 20% of the system memory:
Example 4-9 Altering the dirty ratio
# sysctl -w vm.dirty_ratio=20
4.5.2 Swap partition
The swap device is used when physical RAM is fully in use and the system needs additional
memory. Linux also uses swap space to page memory areas to disk that have not been
accessed for a significant amount of time. When no free memory is available on the system, it
begins paging the least-used data from memory to the swap areas on the disks. The initial
swap partition is created during the Linux installation process with current guidelines stating
that the size of the swap partition should be two times physical RAM. Linux kernels 2.4 and
beyond support swap sizes up to 24 GB per partition with an 8 TB theoretical maximum for
32-bit systems. Swap partitions should reside on separate disks.
If more memory is added to the server after the initial installation, additional swap space must
be configured. There are two ways to configure additional swap space after the initial install:
򐂰A free partition on the disk can be created as a swap partition. This can be difficult if the
disk subsystem has no free space available. In that case, a swap file can be created.
򐂰If there is a choice, the preferred option is to create additional swap partitions. There is a
performance benefit because I/O to the swap partitions bypasses the file system and all of
the overhead involved in writing to a file.
Another way to improve the performance of swap partitions and files is to create multiple swap
partitions. Linux can take advantage of multiple swap partitions or files and perform the reads
and writes in parallel to the disks. After creating the additional swap partitions or files, the
/etc/fstab file will contain such entries as those shown in Example4-10.
Example 4-10 /etc/fstab file
/dev/sda2 swap swap sw 0 0
/dev/sdb2 swap swap sw 0 0
/dev/sdc2 swap swap sw 0 0
/dev/sdd2 swap swap sw 0 0
Under normal circumstances, Linux would use the /dev/sda2 swap partition first, then
/dev/sdb2, and so on, until it had allocated enough swapping space. This means that perhaps
only the first partition, /dev/sda2, will be used if there is no need for a large swap space.
Spreading the data over all available swap partitions improves performance because all
read/write requests are performed simultaneously to all selected partitions. Changing the file
as shown in Example 4-11 assigns a higher priority level to the first three partitions.
Example 4-11 Modified /ertc/fstab to make parallel swap partitions
/dev/sda2 swap swap sw,pri=3 0 0
/dev/sdb2 swap swap sw,pri=3 0 0
/dev/sdc2 swap swap sw,pri=3 0 0