Swap-Space Management in Operating SystemA computer has a sufficient amount of physical memory, but we need more, so we swap some memory on disk most of the time. Swap space is a space on a hard disk that is a substitute for physical memory. It is used as virtual memory, which contains process memory images. Whenever our computer runs short of physical memory, it uses its virtual memory and stores information in memory on a disk. This interchange of data between virtual memory and real memory is called swapping and space on disk as swap space. Swap space helps the computer's operating system pretend that it has more RAM than it actually has. It is also called a swap file. Virtual memory is a combination of RAM and disk space that running processes can use. Swap space is the portion of virtual memory on the hard disk, used when RAM is full. Swap space can be useful to computers in the following various ways, such as:
Operating systems such as Windows, Linux, etc. systems provide a certain amount of swap space by default which users can change according to their needs. If you don't want to use virtual memory, you can easily disable it together. Still, if you run out of memory, then the kernel will kill some of the processes to create a sufficient amount of space in physical memory so that it totally depends upon the user whether he wants to use swap space or not. What is Swap-Space Management?Swap-space management is another low-level task of the operating system. Virtual memory uses disk space as an extension of main memory. Since disk access is much slower than memory access, using swap space significantly decreases system performance. The main goal for the design and implementation of swap space is to provide the best throughput for the virtual memory system. Swap space is used in various ways by different operating systems, depending on the memory-management algorithms in use. For example, systems that implement swapping may use swap space to hold an entire process image, including the code and data segments. Paging systems may simply store pages that have been pushed out of the main memory. The amount of swap space needed on a system can vary depending on the amount of physical memory, the amount of virtual memory it is backing, and how it is used. It can range from a few megabytes of disk space to gigabytes. Note that it may be safer to overestimate than to underestimate the amount of swap space required because if a system runs out of swap space, it may be forced to abort processes or may crash entirely. Overestimation wastes disk space that could otherwise be used for files, but it does no other harm. Some systems recommend the amount to be set aside for swap space. Solaris, for example, suggests setting swap space equal to the amount by which virtual memory exceeds page-able physical memory. Previously, Linux suggested setting swap space to double the amount of physical memory, although most Linux systems now use considerably less swap space. There is currently much debate in the Linux community about whether to set aside swap space at all. Some operating systems, including Linux, allow multiple swap spaces. These swap spaces are usually put on separate disks so the load placed on the I/O system by paging and swapping can be spread over the system's I/O devices. Uses of Swap SpaceThe different operating system uses Swap-space in various ways. The systems that are implementing swapping may use swap space to hold the entire process, including image, code, and data segments.
It is safer to overestimate than to underestimate the amount of swap space required because if a system runs out of swap space, it may be forced to abort the processes or may crash entirely. Overestimation wastes disk space that could be used for files, but it does not harm others. The following table shows different systems using the amount of swap space:
Solaris setting swap space equal to the amount by which virtual memory exceeds page-able physical memory. Previously, Linux has suggested setting swap space to double the amount of physical memory. Today, this limitation is gone, and most Linux systems use considerably less swap space. Including Linux, some operating systems allow the use of multiple swap spaces, including both files and dedicated swap partitions. The swap spaces are placed on the disk, so the load on the I/O by the paging and swapping will spread over the system's bandwidth. Where does the Swap Space Reside?Swap space can reside in one of these two places: The normal file system or Separate disk partition. If the swap space is simply a large file within the file system, normal file-system routines can be used to create, name, and allocate its space. This approach, though easy to implement, is inefficient. Navigating the directory structure and a disk-allocation data structure takes extra disk access.
Some operating systems are flexible and can swap both in raw partitions and file-system space, such as Linux. The policy and implementation are separate, allowing the machine's administrator to decide which type of swapping to use. The trade-off is between the convenience of allocation and management in the file system and swapping performance in raw partitions. Allocation of Swap SpaceManagement appliances allocate a specific amount of swap space based on the size of the appliance's memory and are restricted by the amount of available disk space. The amount of swap space that a virtual machine requires is double the size of its RAM. This amount provides enough space for data that is no longer required by RAM to be placed in the swap space. In addition, there is enough space for emergencies where RAM needs to be cleared due to hypervisor demands. The Management appliance cannot allocate all of the space from a data disk to swap space, as space is required for databases. The Management appliance follows a specific set of conditions when it allocates swap space. These conditions are as follows:
Example of Swap Space ManagementThe traditional UNIX kernel started with swapping that copied the entire process between contiguous disk regions and memory. UNIX later evolved to a combination of swapping and paging as paging hardware became available. In Solaris 1, the designers changed standard UNIX methods to improve efficiency.
More changes were made in later versions of Solaris. The biggest change is that Solaris now allocates swap space only when a page is forced out of physical memory rather than when the virtual memory page is first created. This scheme gives better performance on modern computers, which have more physical memory than older systems. Linux is almost similar to the Solaris system. The swap space is used only for anonymous memory or for regions of memory shared by several processes in both systems. In the Linux system, one or more swap areas can be established.
|