How to extend the swap memory in centos 7

Hi All,

I have created swap file by using dd command in /var directory from the root disk, now there is a requirement to increase the swap size.
Can we increase the size of that existing swap file or we should create a new one?

we are using centos 7 server.

If you can reboot the server, then just create a new swap file and add entry in fstab and comment old swap entry in fstab, just reboot the server and you will be using the latest swap file.

Hi Nagendra,

We can not restart the server, its a production one.


If you can not reboot the server .you should create a new file…

Check the System for Swap Information
swapon -s
current memory and swap usage
free -m
Check Available Storage Space
df -h
Create a Swap File
sudo fallocate -l 4G /swapfile
ls -lh /swapfile
Enable a Swap File
sudo chmod 600 /swapfile
ls -lh /swapfile
sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=b99230bb-21af-47bc-8c37-de41129c39bf
sudo swapon /swapfile
swapon -s
Now Check:-
free -m
Output Example :-
total used free shared buffers cached
Mem: 3953 315 3637 8 11 107
-/+ buffers/cache: 196 3756
Swap: 4095 0 4095

add this file in /etc/fstab


Hi Nitin,

Thanks for your support, it worked for me…
Thank you…