Organization of the Swap Area

Swapped-out pages are held either on a dedicated partition without a filesystem or in a file of fixed size in an existing filesystem. As every system administrator knows, several such areas can be used in parallel. It is also possible to assign priorities based on the speed of the various swap areas. These priorities can then be adopted by the kernel when it uses the swap areas.

Each swap area is subdivided into a number of continuous slots, each of which is precisely the size of one page frame in the system. On most processors this is still 4 KiB. However, larger pages are commonly used on newer systems.

Basically, any page in the system can be accommodated in any slot of a swap area. However, the kernel also uses a structuring method referred to as clustering to handle accesses to swap areas as quickly as possible. Consecutive pages in the memory area of a process (or at least pages that are swapped out consecutively) are written to the hard disk one after the other, with a particular cluster size — normally 256 pages. If no further memory space is available in the swap area for clusters of this size, the kernel adds the pages at any positions that are currently free.

If several swap areas with the same priority are used, the kernel uses a round robin process to ensure that they are utilized as uniformly as possible. If the swap areas have different priorities, the kernel fills the ones with higher priority first before gradually moving on to the ones with lower priority.

To keep track of which pages are where in which swap partition, the kernel must retain some data structures that hold this information in memory. The most important structure element is a bitmap that tracks the used and free state of the slots in a swap area. Other elements yield data to support selection of the slot to be used next and to help implement clustering.

Two userspace tools are available to create and enable swap areas; these are mkswap (for ''formatting'' a swap partition/file) and swapon (for enabling a swap area). As these programs are crucial to a functioning swap subsystem, they are described (and the system call for swapon) below.

Continue reading here: Checking Memory Utilization

Was this article helpful?

0 0