Memory swapping is a computer technology that enables an operating system to provide more memory to a running application or process than is available in physical random access memory (RAM). When the physical system memory is exhausted, the operating system can opt to make use of memory swapping techniques to get additional memory.
Memory swapping is among the multiple techniques for memory management in modern systems. Physical memory alone is sometimes not sufficient, which is why there are different ways of augmenting RAM in a system with these additional options.
In this Enterprise Storage Forum article we define what swap usage is all about, along with the advantages and disadvantages of swapping in memory management.
How Memory Swapping Improves Performance
Memory swapping works by making use of virtual memory and storage space in an approach that provides additional resources when required. In short, this additional memory enables the computer to run faster and crunch data better. (For more background, see Memory vs. Storage.)
With memory swapping, the operating system makes use of storage disk space to provide the functional equivalent of memory storage execution space. The space on the storage device is referred to as “swap space” and is used to run processes that have been swapped out of main physical memory.
The process of memory swapping is managed by an operating system or by a virtual machine hypervisor. Swapping is often enabled by default, though users can choose to disable the capability.
The actual memory swapping process and the creation of a swap file is automatically managed by the operating system. It is initiated when needed as physical RAM is used and additional capacity is required by processes and applications. As additional RAM is required, the state of the physical memory page is mapped to the swap space, enabling a form of virtual (non-physical RAM) memory capacity.
In other words, the main purpose of swapping in memory management is to enable more usable memory than held by the computer hardware.
There are times when physical memory will be allocated and a process needs additional memory. Rather than limiting a system to only having memory that is based on physical RAM, memory swapping enables operating systems and their users to extend memory to disk.
Memory swapping is an essential component of modern memory management helping to ensure availability and overall system stability.
What is Swap Space or Swap File?
Swap space is storage space that is used as temporary memory capacity, when physical memory space is already exhausted. The swap file is the physical disk storage file for swap space that is used by an operating system to extend usable memory.
Understanding swap file and swap space is all about understanding memory management. Physical memory in a modern operating system is segmented in different ways, using virtual memory as an abstraction to combine both physical RAM and often swap space, as usable RAM for application processes. In memory management, operating systems make use of a page table to segment and define different memory locations. With memory swapping, the contents of memory stored in a physical element of the page table are copied to disk to maintain the same state for processes.
A swap file and its associated page of memory can be restored to different areas of a system’s virtual memory as physical memory is reclaimed over time by the operating system.
The process of how to check swap memory can vary based on operating system. In Microsoft Windows operating systems, information about swap memory is listed under task manager as virtual memory. In Linux, swap space can be checked from the command line with by typing ‘swapon-s’, which will show allocated swap space usage.
Advantages of Memory Swapping
- More Memory. Memory swapping is a critical component of memory management, enabling an operating system to handle requests that would otherwise overwhelm a system.
- Continuous Operations. Swap file memory can be written to disk in a continuous manner, enabling faster lookup times for operations.
- System Optimization. Application processes of lesser importance and demand can be relegated to swap space, saving the higher performance physical memory for higher value operations.
Limitations of Memory Swapping
- Performance. Disk storage space, when called up by memory swapping, does not offer the same performance as physical RAM for process execution.
- Disk Limitations. Swap files are reliant on the stability and availability of storage media, which might not be as stable as system memory.
- Capacity. Memory swapping is limited by the available swap space that has been allocated by an operating system or hypervisor.