Operation Manual

3.1.6.1
Using swap
Swap is used to extend the available physical memory. It is then possible to use more
memory than physical RAM available. The memory management system of kernels
before 2.4.10 needed swap as a safety measure. Then, if you did not have twice the size
of your RAM in swap, the performance of the system suffered. These limitations no
longer exist.
Linux uses a page called “Least Recently Used” (LRU) to select pages that might be
moved from memory to disk. Therefore, running applications have more memory
available and caching works more smoothly.
If an application tries to allocate the maximum allowed memory, problems with swap
can arise. There are three major scenarios to look at:
System with no swap
The application gets the maximum allowed memory. All caches are freed, and thus
all other running applications are slowed. After a few minutes, the kernel's out-of-
memory kill mechanism activates and kills the process.
System with medіum sized swap (128 MB–512 MB)
At rst, the system slows like a system without swap. After all physical RAM has
been allocated, swap space is used as well. At this point, the system becomes very
slow and it becomes impossible to run commands from remote. Depending on the
speed of the hard disks that run the swap space, the system stays in this condition
for about 10 to 15 minutes until the out-of-memory kill mechanism resolves the
issue. Note that you will need a certain amount of swap if the computer needs to
perform a “suspend to disk”. In that case, the swap size should be large enough to
contain the necessary data from memory (512 MB–1GB).
System with lots of swap (several GB)
It is better to not have an application that is out of control and swapping excessively
in this case. If you use such application, the system will need many hours to recover.
In the process, it is likely that other processes get timeouts and faults, leaving the
system in an undened state, even after killing the faulty process. In this case, do
a hard machine reboot and try to get it running again. Lots of swap is only useful
if you have an application that relies on this feature. Such applications (like
databases or graphics manipulation programs) often have an option to directly use
hard disk space for their needs. It is advisable to use this option instead of using
lots of swap space.
Advanced Disk Setup 79