Swap space in Solaris or any UNIX host is a vital disk space that is used for the swapping process from physical memory (RAM) to disk. Virtual memory allows a process to run even if physical memory gets full by using swap space (which is located on your hard disk) to swap out memory pages that are not currently in use. This is a very important concept which every programmer and Linux user should know. It is even more important if you are working in IT support or as a system admin because if swap space is full then swapping will fail and no new process will be able to start.
In this UNIX command tutorial, we will see some Solaris commands to find configured and current usage of swap space. Remember if your machine runs out of swap space then you can not start a new process and also an old process that will try to expand itself will likely fail.
Another interesting point about swap space is that every process reserved swap space, equivalent to its physical memory requirement so that it can swap out completely when required. Which means current usage of swap space denotes total memory used by all process at that time. This UNIX command tutorial is next in our series of articles like UNIX command to find links, grep command examples in UNIX, and 10 most popular Linux Interview questions, if you haven't check them then you should check them to learn essential Linux commands and interview questions.
Solaris command to find Swap memory
Here is an example of the Solaris “swap” command to find how much swap memory is left on the server. Remember if your host runs out of swap you can not start a new process, so be careful with how much swap space you set, and your process doesn’t eat all swap memory available in Solaris host. And, if you need a refresher about virtual memory in Linux, Linux System Programming Techniques & Concepts course on Udemy has two wonderful chapters on virtual memory.
Anyway, here is the output of the swap command with both swap -l and swap -s option to see how much swap space is left in the machine:
test ~ $ swap -l swapfile dev swaplo blocks free /dev/sd/dsk/swap 181,2 8 134217720 134217720 test ~ $ swap -s total: 22189856k bytes allocated + 8594616k reserved = 30784472k used, 80563112k available
That’s all on how to find swap space usage in Solaris or How much swap space is used currently, how much swap space is available now etc. There are a couple of more Solaris commands which display information about swap space, like vminfo and sar. You can also look on the internet on How to use them to find swap space and then cross-check with the output of the swap command. By the way, I always prefer the swap command to find swap usage in the Solaris operating system.
The Tech Platform