top output and swap -s output are differing

Solaris experts,

Am struggling, and wondering for the past more than one week that, how to calculate the total available and used memory/swap space.

Finally installed and used top & got some understanding, but while cross-checking, there are mismatches.

Main Memory

  • top o/p - 2GB
  • prtdiag -v : also shows 2 GB

No issue with the main memory ( both shows same o/p ). But with Swap Memory, there are issues.

Swap Memory

  • top o/p - 2GB
  • swap -s
    [list]
  • total: 318072k bytes allocated + 38008k reserved = 356080k used, 2440920k available
  • 2797000k / 1024 = 2731M which goes more than 2 GB
    [/list]

What is wrong ? Which output is right.

By the way, it SPARC solaris 10 machine, having more than 2 zones in it now.

They are both right.
Top is telling the on-disk used and total swap sizes while "swap -s" is telling the virtual memory (swap+RAM) usage.

Can you please explain it further ? Unable to get what you are conveying.

"swap" has different meanings depending on the context.
The whole swap space (a.k.a. virtual memory) is including part of the RAM.
This RAM usage isn't reported as swap by the top command which only cares about disk usage; On the other hand, this RAM usage is included in "swap -s" statistics.

The top O/P is:
Memory: 64G real, 21G free, 48G swap in use, 144G swap free
The swap -s O/P is:
30893840k bytes allocated + 19781416k reserved = 50675256k used, 151396096k available
The 151396096k = 144G
What I don't understand is the difference between "allocated" and "reserved."
Also, does the 144G represent the total amount of swap space?

reserved memory is memory processes have asked for but haven't accessed yet (if ever).

Why would it ? The command reports 144 GB free. The total amount of swap space is 144 + 48 = ~192 GB.

@jlliagre : Thanks for your explanations, i understand better now.

So it is,

The used plus available figures equals total swap space on the system, which includes a portion of physical memory and swap devices (or files).

Though, i have the following question.

Why does the swap space includes a portion of RAM, it should only be SWAP. There may be some reason for including it, what is that ?

Is there any reason behind that ?

Update: BTW, this may be useful for somebody who refers this in future: http://forums.hyperic.com/jiveforums/thread.jspa?threadID=10016&tstart=105

1 Like

That's a pure semantic issue. What the "swap -s" command reports are accurate virtual memory statistics. "Total swap space" has always been used to describe the whole virtual memory under Solaris so this usage is consistent.

No particular reason. The "swap" command behaves as documented in its manual page.

1 Like