Frequently Asked Questions for FreeBSD 2.X : System Administration : How can I add more swap space?
Previous: Will a ``dangerously dedicated'' disk endanger my health?
Next: I'm having problems setting up my printer.

8.11. How can I add more swap space?

The best way is to increase the size of your swap partition, or take advantage of this convenient excuse to add another disk. The general rule of thumb is to have around 2x the swap space as you have main memory. However, if you have a very small amount of main memory you may want to configure swap beyond that. It is also a good idea to configure sufficient swap relative to anticipated future memory upgrades so you do not have to futz with your swap configuration later.

Adding swap onto a separate disk makes things faster than simply adding swap onto the same disk. As an example, if you are compiling source located on one disk, and the swap is on another disk, this is much faster than both swap and compile on the same disk. This is true for SCSI disks specifically.

When you have several disks, configuring a swap partition on each one is usually beneficial, even if you wind up putting swap on a work disk. Typically, each fast disk in your system should have some swap configured. FreeBSD supports up to 4 interleaved swap devices by default. When configuring multiple swap partitions you generally want to make them all about the same size, but people sometimes make their primary swap parition larger in order to accomodate a kernel core dump. Your primary swap partition must be at least as large as main memory in order to be able to accomodate a kernel core.

IDE drives are not able to allow access to both drives on the same channel at the same time (FreeBSD doesn't support mode 4, so all IDE disk I/O is ``programmed''). I would still suggest putting your swap on a separate drive however. The drives are so cheap, it is not worth worrying about.

Swapping over NFS is only recommended if you do not have a local disk to swap to. Swapping over NFS is slow and inefficient in FreeBSD releases prior to 4.x, but reasonably fast in releases greater or equal to 4.0. Even so, it will be limited to the network bandwidth available and puts an additional burden on the NFS server.

Here is an example for 64Mb vn-swap (/usr/swap0, though of course you can use any name that you want).

Make sure your kernel was built with the line

        pseudo-device   vn 1   #Vnode driver (turns a file into a device)
      

in your config-file. The GENERIC kernel already contains this.

  1. create a vn-device
              cd /dev
              sh ./MAKEDEV vn0
            
    
  2. create a swapfile (/usr/swap0)
              dd if=/dev/zero of=/usr/swap0 bs=1024k count=64
            
    
  3. enable the swap file in /etc/rc.conf
              swapfile="/usr/swap0"   # Set to name of swapfile if aux swapfile desired.
            
    
  4. reboot the machine

To enable the swap file immediately, type

        vnconfig -ce /dev/vn0c /usr/swap0 swap
      


Frequently Asked Questions for FreeBSD 2.X : System Administration : How can I add more swap space?
Previous: Will a ``dangerously dedicated'' disk endanger my health?
Next: I'm having problems setting up my printer.