.comment-link {margin-left:.6em;}

IntTech

Saturday, February 28, 2015

Linux Swap Files

This technique for adding swap space was used in the early days of linux on adhoc home systems.  It is not used much anymore, but maybe helpful with small cloud server systems.  Swap usage could be monitored as a way to detect low memory situations and buy the system a few seconds longer to alert or trigger a response before crashing from being out of memory.  

Pulled from this old RedHat documentation. Below is an example of creating a 512MB swap file. 

dd if=/dev/zero of=/var/swap bs=4096 count=131072
mkswap /var/swap

Then Add the following to /etc/fstab:
/var/swap     swap    swap   defaults  0 0 

On reboot the system will use the file as swap space.  To use it immediately issue the command: 
swapon /swapfile 

I know this works on Centos and Amazon linux, I expect it to work on all flavors of Linux. 


Bookmark and Share

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home


Google