Do I really need a swap partition?

Nirjonadda

Well-Known Member
May 8, 2013
759
28
78
cPanel Access Level
Root Administrator
I have 50 GB RAM Do I need swap Memory? I read many places that the rule of thumb for swap space is to double the amount of physical RAM. I am using KVM, 10 CPUs and 50 GB RAM with SSD. Do I need still swap Memory at all with this high amount of physical RAM? Do you swap recommendation for performance ?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
Hello,

That type of question is better asked on a website such as StackOverflow where discussions of system performance tuning occur. You can also find a list of system administration services should you decide to consult with a qualified system administrator at:

System Administration Services | cPanel Forums

Thank you.
 

Nirjonadda

Well-Known Member
May 8, 2013
759
28
78
cPanel Access Level
Root Administrator
Hello,

That type of question is better asked on a website such as StackOverflow where discussions of system performance tuning occur. You can also find a list of system administration services should you decide to consult with a qualified system administrator at:

System Administration Services | cPanel Forums

Thank you.
Then how to create swap Memory in CENTOS 7 (KVM virtualization) ? I need At least 4 GB Swap Space from 50GB of RAM.
 

sparek-3

Well-Known Member
Aug 10, 2002
2,173
280
388
cPanel Access Level
Root Administrator
I read an article once (but I can't find it now, not sure where I read it at) that argued against using swap space, especially when you have gobs of RAM.

The logic seemed pretty sound to me. Basically if you run out of memory and the kernel starts using swap space, this is just going to generate a lot of disk thrashing. But if you have no swap space and you start running out of memory, the kernel will start killing processes. Disk thrashing is typically what leads to unresponsive servers, because all of the kernel time is spent with disk i/o.

I'm not really going to argue one way or another, but I think there is some truth to this line of thinking.
 

Michael-Inet

Well-Known Member
Feb 20, 2014
134
20
68
Nashville, TN, USA
cPanel Access Level
Root Administrator
At least one reason to have swap on a CentOS system is that without some amount of swap MySQL will crash tables constantly.

This is from personal experience, we had a fairly similar setup, high RAM and figured we could turn off swap for a performance increase.

We created 4GB of swap, MySQL became happy.

ymmv,
Michael
 

Greg M

Well-Known Member
May 26, 2016
50
16
58
Glasgow, Scotland
cPanel Access Level
Root Administrator
I would recommend always having SWAP enabled even as a precaution, MySQL can be troublesome without it as Michael-Inet mentioned and should you ever run out of RAM having SWAP may just save you some trouble or give you some time before the system fails on you especially with an SSD drive your swap partition will respond very fast compared to standard disk and again especially if you have like cloud-based SSDs or something.

Also, Linux usually has a default swappiness of 60 which means it will generally start using swap once your ram is 40% used. Set yourself at least 2 or 4GB of SWAP and set your swappiness to something like 30 or if you want to be extreme 5. With this, you are telling your OS / Kernel to only use the SWAP when you have ran out of RAM.



Hope this helps a little

Regards
Greg
 

Nirjonadda

Well-Known Member
May 8, 2013
759
28
78
cPanel Access Level
Root Administrator
At least one reason to have swap on a CentOS system is that without some amount of swap MySQL will crash tables constantly.

This is from personal experience, we had a fairly similar setup, high RAM and figured we could turn off swap for a performance increase.

We created 4GB of swap, MySQL became happy.

ymmv,
Michael
Then how to create swap Memory in CENTOS 7 (KVM virtualization) ?