Published on: January 14, 2019 by Daniel Wren
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. Swap space is located on hard drives, which have a slower access time than physical memory and is often calculated as twice the RAM (for less than 32Gb RAM). Swap space need not exceed more than 16Gb or maximum physical memory.
Why do we need swap ?
When certain applications need more memory than that can be allocated physically
Hibernation or suspend action would flush the entire RAM to the swap space
What is swappiness and how do I change it?
The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. As disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory. It is better to have a value somewhere in the middle.
1. swappiness can have a value of between 0 and 100
2. swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible
3. swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache
Is it paging or swapping happening in Linux ?
Letʼs take a look at a few important concepts related to memory starting with the concept of virtual memory. Operating system uses capabilities of the CPU to make it appear as though you have more memory than you really do. This is the concept of virtual memory which is nothing but an abstraction of the main memory. Linux implements this concept of virtual memory using something called page. It extends the available memory of the computer by storing the inactive pages of the RAM on a disk. Whenever the pages are required, it is brought back to the RAM.
Swap memory or swap space is a part of the hard disk drive that is used as virtual memory. Thus, both terms are also used interchangeably. Each page is 4Kb in size and is considered as the basic unit of memory. The CPU also helps the kernel by recognising when the process tries to access a page that is not yet in memory. It is the kernel’s job to figure out which process it was, what page it was, and to load the appropriate page. Kernel locates each page in the physical memory or in the swap space. The kernel transfers data between the RAM and the disk and updates the paging tables as it goes along so that the entry for the virtual address points to a physical page in memory and this is called Paging.
The pages that have not been accessed since a long time are sent to the swap space area. The process is referred to as swapping out. In case the same page is required, it is swapped in physical memory by swapping out a different page. Thus, one can conclude that swap memory and virtual memory are interconnected as swap memory is used for the technique of virtual memory.
Swapping refers to the case where the on-disk data is in a swap disk or swap area. Paging can also be done between RAM and a file, and in this case it’s usually not referred to as swapping.
The answer to the question is Linux does the both. To make it better, Linux does swapping in addition to paging.
Let us take care of your servers 24/7/365. Get rid of all the hassles of Server Management.
Category : Linux, server, Sever management
Add new commentSIGN IN