Solaris 2.5.1, Swap Space and You


REFERENCE: man swap, man mkfile, man vfstab

What is Swap

If the world were a kind and just place you would not have to know what swap is. Unfortunately, it isn't and you do. Swap is sort of a scratch disk on UNIX systems. When you install the OS and partition your disk drive you usually designate some area as "swap". The OS will use this area and many applications will use this area without you ever realizing it. The rule of thumb is to make the swap size twice as big as your memory size. So if you have 64 MB of RAM, have at least 128 MB of swap.

To find out how much swap you have:

        swap -l
This will list out your swap space. Usually it will just give something like.
        /dev/dsk/c0t0d0s1   32,1      16 132960  84864
You can also do
	swap -s
This will tell you your swap size. Mine says this.
	total: 50280k bytes allocated + 10136k reserved = 60416k used, 143328k availabl

Symptoms of too little swap

When I ran out of swap, my compiler started barfing all over the place, giving me seg faults and core dumps and telling me to mail the manufacturer with a bug report. Other programs may also crash. If you start noticing this, you can do a "df -k" occassionally or the aforementioned "swap -s" to keep an eye on how much swap space you have left. If you notice it getting really full, and then you have a crash, you are probably running out.

Adding More Swap

The hard way to do this is to reinstall your OS. The easy way is to make a big file using the mkfile command and then use that file as additional swap space. Make this big file on a partition with lots of room. Never make this file on the root partition! Do a "df -k" to find a partition with lots of room.
	mkfile 100m swap.file
The above command will make a 100 MB swap file called "swap.file" if you leave off the m, it will default to 100 bytes. You probably don't want this.

	swap -a swap.file
The above command will add the "swap.file" to your swap area. Verify this with a "swap -s" and a "swap -l"

Final Step

You don't want to do this every time you reboot, so you need to do one more thing. The swap file will stay there through a reboot but it won't be automatically added to the swap area. To do this you need to edit the /etc/vfstab file.

/etc/vfstab

#device              device   mount     FS     fsck    mount   mount
#to mount            to fsck  point    type    pass    at boot options
/dev/dsk/c0t0d0s1       -       -       swap    -       no      -
/export/home/swap.file  -       -       swap    -       no      -

The above is two lines from my vfstab file. There should be more, but these are the two lines that show how swap works. The first line is standard swap from the OS installation. The second is a swap file that I added to make more room for the swap.

The vfstab file indicates in the first column the name of the swap file, in the second column a - indicating that no fsck is required, the third column is for the mount point and again no entry is required. The FS type is the next column and for that you say "swap". Again a - for fsck pass which says do not do fsck, a "no" for mounting at boot and a - for mounting options.

Return to Gene's Home Page
Return to Gene's Random Unix Crap