Swap

From Hackepedia
Revision as of 01:24, 18 October 2007 by Franks (talk | contribs)
Jump to navigationJump to search

Swap is a secondary storage for memory that is swapped or paged out, usually residing on your hard disk. Hard drives are a lot slower to read and write to than RAM, so ideally you will want to increase your RAM if financially possible if you see that your swap is being used, assuming speed as priority.

It is also used for saving the kernel corefile when the system panics. Some systems compress their corefile to swap and others don't (such as BSD), this is why it's a good idea to have 1.5 to 2 times as much swap as physical memory in a machine (as a rule of thumb), so that you can get a good corefile.

Don't forget to ensure there is always enough room in your swap if your RAM is being used to its maximum capacity:

# swapinfo
Device          1K-blocks     Used    Avail Capacity
/dev/ad0s1b        105288    68596    36692    65%

otherwise you'll start getting errors to syslog, running applications will be killed, and it will create a general mess of things:

Oct 27 09:51:38 mail swap_pager_getswapspace(9): failed
Oct 27 09:51:38 mail swap_pager_getswapspace(5): failed
Oct 27 09:51:38 mail swap_pager_getswapspace(16): failed
Oct 27 09:51:40 mail pid 95400 (perl5.8.7), uid 125, was killed: out of swap space

If you are running out of swapspace frequently, or just want to increase the capacity, you can add a swapfile very easily on FreeBSD.



Encrypting swap in FreeBSD has existed since version 5.3



Encrypting your swap in GNU/Linux

This was done on Ubuntu feisty fawn. If you're doing this on your live system, first deactivate your current swap:

# swapoff -a

I added this to /etc/crypttab:

swap /dev/sda2  /dev/urandom  cipher=aes-cbc-essiv:sha256,hash=sha256,size=256,swap

and then added the following to /etc/fstab:

/dev/mapper/swap       none    swap     0    0

finally, I ran:

$ sudo  /etc/init.d/cryptdisks start
$ swapon -a

to see if it's working:

$ swapon -s 

or

$ cat /proc/swaps


Encrypting swap in MacOSX

System Preferences -> Security pane and choose "Use secure virtual memory"