Bobcares

How to increase swap space in Linux Redhat?

by | Feb 11, 2019

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.]

 

Conclusion

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.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF