Swap space is used as virtual memory storage areas when the system does not have enough physical memory to handle current processes. You might have to add swap space to your system if it does not have enough swap space or if recommended by your software application vendor. Follow the steps below to add swap space to a Solaris system, this example is taken from a Solaris 10 system.
Step 1
While logged into the system as root, the ‘swap -s‘ command provides summary information of swap resources. The output displays the total number of allocated bytes currently in use, the number of bytes currently reserved, the total amount of swap space, both reserved and allocated, and the total amount of swap space available for future reservation and allocation.
# swap -s total: 44750504k bytes allocated + 3550360k reserved = 48300864k used, 143647648k available
Step 2
The status of the swap areas on disk are examined using the ‘swap -l‘ command. The output lists the physical swap area configured on your system, the total swap space, and the amount of available swap space in this device.
# swap -l swapfile dev swaplo blocks free /dev/zvol/dsk/swappool/swap 256,1 16 268435440 211978800
Step 3
It is determined by using the df -k command that the system has sufficient space to add a 20-Mbyte swap file for demonstration purposes. The output shows there is enough space available to add the swap space.
# df -k / Filesystem kbytes used avail capacity Mounted on rpool/ROOT/10u9S_144534 70189056 11505600 22912949 34% /
Step 4
For demonstration purposes, a 20-Mbyte swap file is added to the system. The /usr/local/swap directory is created with the mkdir -p command. Within this directory, a 20 Mbytes swap file is created with the mkfile command and it is added to the system’s swap space with the ‘swap -a‘ command.
# mkdir -p /usr/local/swap # mkfile 20m /usr/local/swap/newswap # swap -a /usr/local/swap/newswap
Verify
Afterwards, the new swap file availability is verified with the ‘swap -l’ command. Note the cumulative report of the ‘swap -s’ command is changed.
# swap -l # swap -s
Removing the swap file
1. If the swap resources are no longer in use, the swap file just created is removed with the ‘swap -d‘ and rm commands. Note that the swap -l command output shows the swap space is no longer available.
# swap -d /usr/local/swap/newswap
2. After displaying the cumulative report of swap with the swap -s command to verify available space, a disk partition is added as a swap slice to the existing swap space with the swap -a command.
# swap -l # swap -s