Swap space is utilized when the physical memory is full.
In a situation, when the system needs additional memory resources and RAM is full, the pages in the memory which are not active are shifted to the swap space.
The swap space can assist machines with a small portion of RAM. It is not an alternative to additional RAM. The swap space is present on hard drives that have a slower time to access than physical memory.
The commands to extend swap are
The swap size should be twice the size of RAM.
Let us take
M as the amount of RAM in GB.
S as the amount of swap in GB. Then,
If M<2 then S=M*2 Else S=M+2
If we do not have any additional disks, we can create a file somewhere on the filesystem, and utilize that file for the swap space.
/directory with size
1024MB, the command is:
dd if=/dev/zero of=/newswap bs=1M count=1024
if = read from FILE instead of stdin.
of = write to FILE instead of stdout.
bs = read and write BYTES at a time.
count = total size of the file.
chmod go-r /newswap
chmod 0600 /newswap
newswapfile as a swap file, run the command:
/newswap swap swap defaults 0 0
swapoff -a swapon -a
Myself Debomita Bhattacharjee, an IT employee with 6+ years of experience in Software industry. My area of interest is Automation testing and Front End Development.