Do I need Swap memory?

tomwin

Verified User
Joined
Apr 23, 2020
Messages
77
Hi, I was wonder if I need to create an Swap memory on my Centos 8? Right now my server have 2gb of ram memory. Are there any easy step by step to set this up? And if needed how much Swap memory do I need?
 
Hi, sorry for asking but I did follow this steps in this link below but when I come to open
/etc/fstab and add the /swapfile swap swap sw 0 0 in to the /etc/fstab I used this command
vim /etc/fstab
but that command did not work on my terminal. How can I open /fstab ?
https://help.directadmin.com/item.php?id=2083
 
maybe you dont have vim in your system
yum install vim
should help
 
maybe you dont have vim in your system
yum install vim
should help
Yes that did work. Now I can se the file /fstab but maybe this is way to difficult for me. No idea how to add or save it.
 
Aren’t there any command to add this direct in to the /fstab file with out open it?
/swapfile swap swap sw 0 0
 
if you dont have any experince with editing I do not recommend to edit fstab anyway, you can destroy your system !
as @floyd mentioned you can also use another editor if you like
 
I personally find nano to be a more user friendly text editor.
Yes nano is more user friendly.
i wonder if anyone can show me how your /fstab look like if you have added
/swapfile swap swap sw 0 0
screenshot maybe?
 
I'm wondering how you got a server with 2GB ram installed without a swap partition, as it's pretty much always a standard setting. To skip swap, you'll have to use a custom disk partition layout, but I don't think you've done that because you don't know (yet) that you need it. So... kinda curious if this is default on CentOS 8.
 
I'm wondering how you got a server with 2GB ram installed without a swap partition, as it's pretty much always a standard setting. To skip swap, you'll have to use a custom disk partition layout, but I don't think you've done that because you don't know (yet) that you need it. So... kinda curious if this is default on CentOS 8.
I have my VPS at Digitalocean. Don’t think I have Swap there by default. If that was the case wouldn’t I have something in my /fstab ?
 
at least have swap on your vps is good way and safty

because when someone attack your web server you'll not enougth ram for mainternant in somecase
 
Hi, I was wonder if I need to create an Swap memory on my Centos 8? Right now my server have 2gb of ram memory. Are there any easy step by step to set this up? And if needed how much Swap memory do I need?
Now, i also using 2GB RAM 4 CPU Core using SSD
I ask my host provider about swap in advance,
They said "swap is important, but need less swap for SSD server, because large swap is not good for SSD cause writting huge data all the time".
Currently i using 512MB swap as they advice

Sure, 2GB RAM is small, when i use Apache the server start swaping fastly and touching maximum swap 512 MB .
Now i am using Nginx, the server start swapping, but not fast swaping as Apache
 
Last edited:
Swap is only needed if you don't have enough RAM. I have never allocated more than 512 MB for swap. If you don't have enough RAM and no swap the server could crash. There is a balance to be reached.
 
Swap is only needed if you don't have enough RAM. I have never allocated more than 512 MB for swap. If you don't have enough RAM and no swap the server could crash. There is a balance to be reached.
The OOM will kill processes when you're out of memory. Even tho the server could crash, things like mysql, apache will die first, freeing memory again. Not the best way to go, but on the other hand, if you're server really needs swap (being 10-1000 times slower than SSD) crashing might be a matter of seconds.
 
The OOM will kill processes when you're out of memory.

OOM Killer will not necessarily keep the server from crashing. There have been plenty of times I had a server stop responding even though OOM Killer had killed stuff. The only thing I could do was power cycle it. I couldn't even login through the console. I saw plenty of stuff being killed by OOM Killer on the screen. It still crashed.
 
Back
Top