Table of Contents
Introduction
This tutorial covers how to manage and monitor swap on Linux, including how to determine the amount of swap space available and how much is currently in use.
Swap space plays an important role in system performance, so it’s crucial to understand how to manage it effectively.

How much swap on Linux do you need?
The recommendation is to swap the space used to double your RAM. If your system has a lot of memory, you may never need to use swap space.
RAM         Swap        Swap (with hibernation)
256MB       256MB       512MB
512MB       512MB       1GB
1GB         1GB         2GB
2GB         1GB         3GB
3GB         2GB         5GB
4GB         2GB         6GB
6GB         2GB         8GB
8GB         3GB         11GB
12GB        3GB         15GB
16GB        4GB         20GB
24GB        5GB         29GB
32GB        6GB         38GB
64GB        8GB         72GBTo determine if your system can hibernate
$ which pm-hibernateYou can test it by running this command:
$ sudo pm-hibernateView the amount of swap space on Linux
$ swapon --show
$ free -m 
$ sar -S 1 3
$ lsblkThe output terminal is as follows
[vagrant@localhost ~]$ swapon --show
NAME      TYPE SIZE USED PRIO
/swapfile file   2G   9M   -2
[vagrant@localhost ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:            486         146          93           2         247         325
Swap:          2047           9        2038
[vagrant@localhost ~]$ sar -S 1 3
Linux 3.10.0-1127.el7.x86_64 (localhost.localdomain)    09/13/2021      _x86_64_        (1 CPU)
09:51:08 PM kbswpfree kbswpused  %swpused  kbswpcad   %swpcad
09:51:09 PM   2087884      9264      0.44       416      4.49
09:51:10 PM   2087884      9264      0.44       416      4.49
09:51:11 PM   2087884      9264      0.44       416      4.49
Average:      2087884      9264      0.44       416      4.49
[vagrant@localhost ~]$ lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda      8:0    0  40G  0 disk
ββsda1   8:1    0  40G  0 part /
[vagrant@localhost ~]$Creating a swap file
$ sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon -a
$ swapon --showTurn to swap off.
$ sudo swapoff -v /swapfile
# The output terminal
[vagrant@localhost ~]$ sudo swapoff -v /swapfile
swapoff /swapfile
[vagrant@localhost ~]$Turn to swap on Linux.
$ sudo swapon -v /swapfile
$ swapon --showConclusion
You have a Managing and monitoring swap on Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!
