How to Create a Swap File and Make It Available
-
Become superuser.
You can create a swap file without root permissions. However, to avoid accidental overwriting, root should be the owner of the swap file.
-
Create a directory for the swap file, if needed.
-
# mkfile nnn[k|b|m] filename
The swap file of the size nnn (in Kbytes, bytes, or Mbytes) and filename you specify is created.
-
Activate the swap file.
# /usr/sbin/swap -a /path/filename
You must use the absolute path name to specify the swap file. The swap file is added and available until the file system is unmounted, the system is rebooted, or the swap file is removed. Keep in mind that you can't unmount a file system while some process or program is swapping to the swap file.
-
Add an entry for the swap file to the /etc/vfstab file that specifies the full path name of the file, and designates swap as the file system type, as follows:
/path/filename - - swap - no -
-
Verify that the swap file is added.
$ /usr/sbin/swap -l
Example—Creating a Swap File and Making It Available
The following examples shows how to create a 100–Mbyte swap file called /files/swapfile.
# mkdir /files
# mkfile 100m /files/swapfile
# swap -a /files/swapfile
# vi /etc/vfstab
(An entry is added for the swap file):
/files/swapfile - - swap - no -
# swap -l
swapfile dev swaplo blocks free
/dev/dsk/c0t0d0s1 136,1 16 1638608 1600528
/files/swapfile - 16 204784 204784
How to Remove Unneeded Swap Space
-
Become superuser.
-
Remove the swap space.
# /usr/sbin/swap -d /path/filename
The swap file name is removed so that it is no longer available for swapping. The file itself is not deleted.
-
Edit the /etc/vfstab file and delete the entry for the swap file.
-
Recover the disk space so that you can use it for something else.
# rm /path/filename
If the swap space is a file, remove it. Or, if the swap space is on a separate slice and you are sure you will not need it again, make a new file system and mount the file system.
For information on mounting a file system, see Chapter 39, Mounting and Unmounting File Systems (Tasks).
-
Verify that the swap file is no longer available.
# swap -l
Example—Removing UnneededSwap Space
The following examples shows how to delete the /files/swapfile swap file.
# swap -d /files/swapfile |
While searching about swap, I found a very good blog post Myths and Facts about Solaris swap space on Jim Laurent's blog.
Jim says that the rule of thumb for swap size is 30% of RAM. He has given many other links like Solaris Internals Wiki which are a must visit.
Swap works differently in Solaris 2 as compared with other Unix systems, including SunOS 4. These systems must always have some swap space, and it must be bigger than RAM. Every program in RAM has its total size reserved on the swap disk in case it needs to be swapped out to disk. Since there are systems with 5 gigabytes (SPARCcenter 2000) or more of RAM, it seems ridiculous that systems that already have huge RAM capacity would need huge swap disks that would probably not be used. Solaris 2 changes the rules by adding the RAM and the disk space. If you can buy enough RAM for your workload, you can run with no swap disk at all! In practice common database applications that are sized to run in a few gigabytes of RAM will actually need many gigabytes of disk allocated as swap space.
No comments:
Post a Comment