How to increase swap space in Linux Redhat?

How to increase swap space in Linux Redhat?

Table of Contents

]My server swap is full. Is there a way to add additional space to swap without wiping the partitions?

That was a recent support request received in our Infrastructure Management Services.

Swap space can be useful when you are facing temporary memory crunch on the server. But, when it comes to a live server, increasing swap can affect the existing data.

Today, we’ll see how our Support Engineers increase swap in Linux RedHat servers without causing downtime.



The role of swap space

Before proceeding further, we’ll first see the importance of swap memory on the servers.

Basically, swap file is a space on the hard disk of the server that is used as an extension of memory. Storing frequently accessed data in the swap space allows easy execution of processes. In short, swap allows the  efficient use of physical memory.

Ideally, when your server have sufficient memory, there is not much to worry about swap space. But, when you have a server with low memory and applications are memory intensive, swap can definitely help.


How to increase swap space in Linux?

Recently, one of our customers contacted us for increasing swap space on his server. He was typically concerned whether that would affect the existing disks of the server.

Although, there are different ways to increase swap space like creating a new swap partition, extending swap partition, etc., it can corrupt the existing website data.

That’s why, our Dedicated Engineers chose to increase the swap space by creating a new swap file. Let’s now see how we did this for the customer on his RedHat server.


1. Analyzing current swap usage

As the first step, we checked the swap usage on the server and found that swap usage was full. The exact details were:

[root@server2]# free -mh
     total used free shared buff/cache available
Mem:  31G  6.0G 2.1G 958M 23G 24G
Swap: 1.0G 1.0G 6.8M
Swap Use was 99.39% (1,040,128 of 1,046,520)

We found that the server was having only 6.8M free swap space.


2. Create swap file

Unfortunately, the server did not have an unused partition. And, modifying existing partition was not an option too. That’s why, our Support Engineers created a file using the mkfile command and configured swap on it.

To create a new file “/home/swap_file_do_not_delete” having filesystem type as SWAP, we used:

mkfile 5g /home/swap_file_do_not_delete

Later, to make the swap available for use, we issued the command

swap -a /home/swap_file_do_not_delete


3.Add new swap to fstab

Finally, to make the swap available on the server even after every server reboot, we make changes to the fstab file. The /etc/fstab file contains information of the server partition and how they get mounted on the server.

We added the entry as :

/home/swap_file_do_not_delete swap swap defaults 0 0

The final memory status of the server showed the following details.

[root@server2 ~]# free -mh
              total        used        free      shared  buff/cache   available
Mem:            31G        6.1G        3.0G        938M         22G         24G
Swap:          6.0G        868M        5.2G  

Thus, our Server Administrators helped customer to increase swap space to 6G on the server.

[Trouble adding swap on your live server? We can increase swap space for you.]



In short, adding swap space on the server helps to solve memory crunch on the server to certain extent. But, increasing swap on live server can affect existing disks. Today, we saw how our Support Engineers increased swap space on RedHat Linux server without causing downtime on the server.

Leave a Comment

Your email address will not be published. Required fields are marked *

Social Share


Cheapest Web Hosting

Fasters Web Hosting Promo
Scroll to Top

Launch your Website at RS599

Create a professional website yourself with our domain hosting combo. Get Extra benefits at this Year end Sale with 10% OFF and Enjoy Amazing Deels on Shared Hosting!

Starting at Only RS599/Year

Year End Sale


Use Code STARTBIZ at Checkout.

Create an earning opportunity with A Web Hosting Business

Become reseller and start reselling domains, web hosting, ssl certificates and More.

45% OFF

Starting at RS399/Month


Use coupon: at the checkout.