A system’s virtual memory is a combination of RAM and disk space.
Portions of the virtual memory are reserved as swap space.
Swap space can be defined as a temporary storage location that is used when the system’s memory requirements exceed the size of available RAM.
# swap -s ==> to list a summary of the system’s virtual swap space
# swap -l ==> to list the details of the system’s physical swap areas
Note – There can be a discrepancy in available and free swap space size
between the swap -s and swap -l outputs. The swap -s output does not take into account pre-allocated swap space that has not yet been used by a process.
Adding Swap Space
Adding Swap Slices
1. Edit the /etc/vfstab file to add information describing the swap slice
# vi /etc/vfstab
2. Add the following line to create the swap slice
/dev/dsk/c1d0s1 - - swap - no -
3. Use the swap -a command to add additional swap area
# swap -a /dev/dsk/c1d0s1
Note – When the system is subsequently rebooted, the new swap slice
/dev/dsk/c1t3d0s1 is automatically included as part of the swap space as a result of adding the entry to the /etc/vfstab file.
Adding Swap Files
1. Identify a file system that has adequate space to create an additional swap file, preferably on another drive.
2. Make a directory to hold the swap file.
# mkdir -p /usr/local/swap
3. Create a 20-Mbyte swap file named swapfile in /usr/local/swap directory.
# mkfile 20m /usr/local/swap/swapfile
4. Add the swap file to the system’s swap space.
# swap -a /usr/local/swap/swapfile
5. List the details of the modified system swap space.
# swap -l
6. List a summary of the modified system swap space.
# swap -s
7. To use a swap file when the system is subsequently rebooted, add an entry for the swap file in the /etc/vfstab file.
# vi /etc/vfstab
/usr/local/swap/swapfile - - swap - no -
Removing Swap Space
Removing Swap Slices
1. Delete a swap slice from the current swap configuration.
# swap -d /dev/dsk/c1d0s1
2. To prevent the swap slice from being configured as part of the swap configuration during a reboot or change of run level, edit the /etc/vfstab file, and remove the swap slice entry from the file.
Removing Swap Files
1. Delete a swap file from the current swap configuration.
# swap -d /usr/local/swap/swapfile
2. Remove the file to free the disk space that it is occupying.
# rm /usr/local/swap/swapfile
3. To prevent the swap file from being configured as part of the swap configuration during a reboot or change of run level, edit the /etc/vfstab file, and remove the swap file entry.
Note – The output of the df -h command shows the space used by the
swap file until it is removed.