Thursday, February 14, 2013

Sar and vmstat in Linux & Solaris

Sar and vmstat utilities have been used to calculate the precise values of used/unused memory. Though there's a difference if we do so in UNIX based systems like solaris. Usually the linux operating system reports the same value for both sar and vmstat. The below screenshot shows the similarity of outputs of both sar and vmstat in Ubuntu 12.04.

where “free” and “kbmemfree” represent free unused memory. Both have equal values in case of linux.

Whereas as you can see in the below shown screenshot that on contrary to linux, solaris operating system gives different values for both commands.

This doesn't mean that sar or vmstat output is wrong. It's just that the “free” column in vmstat's output is represented in “kilobytes” whereas the “freemem” column in sar's output is represented in “number of pages”.
So in order to make both command outputs look similar, first we need to know exactly how many pages equals to 1 kilobyte. In order to do so we need to execute “pagesize” command to get the default size of a page in Solaris OS.

In my case I found the pagesize to be 4096 bytes (i.e. 4 kilobyte). Multiplying pagesize value (in kilobytes) with average freemem value of sar output, gives and output that is pretty much equal to vmstat free output. Refer below screenshot for more details.

There's a slight difference in output because I didnt run both the commands at exact same time.

Similarly, in case of swap in Solaris OS you will again find some difference in swap readings. The output vmstat command reports free swap memory in “swap” column and “freeswap” column in sar output. The only reason for both the outputs to be different is that sar reports the output in blocks whereas vmstat continues to report in kilobytes.
Since, the sar utility reports its swap in blocks, also we all know that one block is 512 bytes in size and two blocks will be 1024 bytes.
Hence, in order to convert the swap blocks to kilobytes we need to divide average freeswap output by 2 and we will get the freeswap size in kilobytes. Refer the below mentioned screenshot for more details.

No comments:

Post a Comment