“Learn how to increase swap space in Linux to improve system performance and manage memory limitations. This step-by-step guide will walk you through the process, allowing you to maximize your system’s capabilities and enhance overall efficiency.”
To increase swap space in the Linux system, we first need to check if swap space is enabled.
$ sudo swapon --show
If you didn’t get any output, it means your system doesn’t have swap space available at the moment.
There is another way to check the memory and swap space information i-e using the “free -h” command.
$ free -h
In my case, RAM is less than 31 GB, so the allocated swap space memory would be around 49 GB.
(Note that all of the below-mentioned commands required sudo privileges to make changes).
In the terminal, write down the command to increase swap space:
$ sudo dd if=/dev/zero of=/swap_file bs=1GB count=10
You can set the value of bs and count according to the requirement.
Keep in mind:
bs🡪 sets of blocksize
count🡪 number of blocks
Now, set the permission access for the users as 600 so users couldn’t be able to read important data from the swap_file:
$ sudo chmod 600 /swap_file
To enable the swap area on the file “swap_file,” use the “mkswap” command utility:
$ sudo mkswap /swap_file
The next step is to enable the swap file “swap_file” using the command:
$ sudo swapon /swap_file
Run the “free -h” command to check if swap space has increased:
$ free –h
So, when we checked before, the swap space was 49 GB. And now it has been updated to 59 GB.