Optimizing Usage of Swap Space

One of the items that is important for memory management is swap space. The primary reason is not because swap is used if you are running out of memory but because you can use swap to park chunks of memory that aren't needed at that moment. This also makes sure that a system that is almost running out of memory will continue to function properly. In the "old days," it was a good idea to allocate twice as much swap space as the amount of physical memory. In modern days where servers can have multiple gigabytes of RAM, this doesn't make sense; a 64GB swap partition would become a large bottleneck. Therefore, you shouldn't configure more swap space than 2GB.

On Linux, swap is ordinarily configured as a partition. You can configure it as a file as well, but for performance reasons this really is not a good idea. As an administrator you don't even have to think about it; the swap partition is set up automatically when installing SUSE Linux Enterprise Server. To set up swap for optimal performance, different swap partitions can be created and load balanced on the system; this allows the swapping to take place in parallel on all those partitions at the same time, which leads to better performance. If you want to do that, you can use the pri option in /etc/fstab to indicate how the swap partition should be mounted. If the pri setting is not used, the first swap partition that is defined on your server is used first, then the second partition is used, and so on. In Listing 28-1 you can see how to set up /etc/fstab for the load balancing of swap activity.

Listing 28-1. Configuring/etc/fstab for Swap Load Balancing

/dev/sda2 swap swap pri=1 0 0

/dev/sdb2 swap swap pri=1 0 0

/dev/sdc2 swap swap pri=1 0 0

Was this article helpful?

0 0

Post a comment