Swap is a type of filesystem and is a virtual memory. Whenever your RAM is full, your operating system will look for further memory in your swap space. For this reason, you reserve some part of the hard disk to create a swap partition.
Identifying Current Swap Space Usage:
root@vishal-desktop:/# cat /proc/swaps
Filename Type Size Used Priority
/dev/sda7 partition 1951740 4 -1
Alternatively, use the swapon command:
root@vishal-desktop:/# swapon -s
Filename Type Size Used Priority
/dev/sda7 partition 1951740 4 -1
Finally, the free command may also be used:
root@vishal-desktop:/# free
total used free shared buffers cached
Mem: 895112 721656 173456 0 36592 310156
-/+ buffers/cache: 374908 520204
Swap: 1952736 4 1952732
root@vishal-desktop:/# dd if=/dev/zero of=/swap bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 17.4283 s, 61.6 MB/s
Configure the file as swap:
Change the permission of the swap file so that only root can access it
root@vishal-desktop:/# chmod 600 /root/swap
root@vishal-desktop:/# mkswap /swap
Setting up swapspace version 1, size = 1048572 KiB
Enable the newly created swapfile :
root@vishal-desktop:/# swapon /swap
# cat /etc/fstab
/swap none swap sw 0 0
root@vishal-desktop:/# swapon -s
Filename Type Size Used Priority
/dev/sda7 partition 1951740 142884 -1
/swap file 1048572 0 -2
root@vishal-desktop:/# free -k
total used free shared buffers cached
Mem: 895112 828484 66628 0 2144 539552
-/+ buffers/cache: 286788 608324
Swap: 3000312 142876 2857436
root@vishal-desktop:/# swapoff -a
root@vishal-desktop:/# swapon -a
root@vishal-desktop:/# swapoff /newswap
Thanks,
Vishal Vyas
Identifying Current Swap Space Usage:
root@vishal-desktop:/# cat /proc/swaps
Filename Type Size Used Priority
/dev/sda7 partition 1951740 4 -1
Alternatively, use the swapon command:
root@vishal-desktop:/# swapon -s
Filename Type Size Used Priority
/dev/sda7 partition 1951740 4 -1
Finally, the free command may also be used:
root@vishal-desktop:/# free
total used free shared buffers cached
Mem: 895112 721656 173456 0 36592 310156
-/+ buffers/cache: 374908 520204
Swap: 1952736 4 1952732
root@vishal-desktop:/# dd if=/dev/zero of=/swap bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 17.4283 s, 61.6 MB/s
Configure the file as swap:
Change the permission of the swap file so that only root can access it
root@vishal-desktop:/# chmod 600 /root/swap
root@vishal-desktop:/# mkswap /swap
Setting up swapspace version 1, size = 1048572 KiB
Enable the newly created swapfile :
root@vishal-desktop:/# swapon /swap
# cat /etc/fstab
/swap none swap sw 0 0
root@vishal-desktop:/# swapon -s
Filename Type Size Used Priority
/dev/sda7 partition 1951740 142884 -1
/swap file 1048572 0 -2
root@vishal-desktop:/# free -k
total used free shared buffers cached
Mem: 895112 828484 66628 0 2144 539552
-/+ buffers/cache: 286788 608324
Swap: 3000312 142876 2857436
root@vishal-desktop:/# swapoff -a
root@vishal-desktop:/# swapon -a
root@vishal-desktop:/# swapoff /newswap
Thanks,
Vishal Vyas
Tags
Linux