Unix Swap Space Myths


When trying to figure out how much swap space to give a machine (when you're first setting up the partitions), the general rule of thumb has been to give it double the space of whatever your available physical RAM is...i.e., if you have 32mb RAM, you should have a 64mb swap parition.

However...Swap and physical RAM together make what's known as a total sum of virtual memory, so if you have 32mb RAM and a 64mb swap, you have 96mb total RAM via the virtual memory scheme. As your computer swaps out pages of RAM to disk, you will only run out of memory if your total needs exceed 96mb at some point.

Whatsmore, the old "double the RAM" rule only really held for SunOS 4, and not absolutely even then.

The modern rule is "however much you need". With 192MB swap and 128MB RAM you will have 320MB of virtual memory total. If this isn't running out then there is no reason to worry about it.

SunOS 4 used a different virtual memory model where every page of physical memory had to be backed by swap. Therefore, 192M of swap and 128MB of RAM would yield only 192MB of virtual memory.

Keep in mind that /tmp pulls memory out of the virtual memory pool directly. If you require the ability to manipulate very large files in /tmp then you should either add more swap space or add an on-disk /tmp partition. Using the size option in vfstab is advisable if you continue to use tmpfs as this will prevent /tmp from starving the rest of the system for memory.

Although using raw partitions and striping swap across disks yields optimal performance, other methods really do not take much of a hit. Rather than reinstalling if you need more swap space I would advise making swap files with mkfile in partitions on each disk and adding them to the swap pool.