Wednesday, November 28, 2007

Add swap space on a running system

I found a few systems that were setup with low swap [= to original RAM] on the system and now all my alerts for swap usage are going off.

On debian the steps to add a regular file for swapping were as follows:


  1. make the swap file - create a contiguous file and label it as such


  2. dd if=/dev/zero of=fourGfile count=4000000 bs=1024
    chmod 0600 fourGfile
    mkswap fourGfile

  3. Mount it as a swap partition


  4. swapon -v fourGfile

  5. Add it to /etc/fstab


  6. /var/cache/swapfile/fourGfile none swap sw 0 0



This was it and now we have enough swap on the systems,


bash-3.1# free -l
total used free shared buffers cached
Mem: 8180284 7866476 313808 0 84660 7323408
Low: 8180284 7866476 313808
High: 0 0 0
-/+ buffers/cache: 458408 7721876
Swap: 7951784 95304 7856480

NOTE: Swapping on a system is not a good thing for performance but it adds to total virtual memory that a process can access on the system.