Tuesday, July 10, 2012

Swap summary

Listing swap information is easy, but interpreting it is difficult.
So far I believe the tools aren't precise and just give rough approximations.
 
Traditionally, swap used to mean only the "disk portion" of the virtual memory.
At some point  Solaris has changed that to: swap = "traditional swap" + "unused RAM".
And by doing this, it turned out that swap somehow became the virtual memory itself.
It's also called virtual swap causing a great deal of confusion and obscurity.

I apologize in advance if I incidentally get caught by what I just stated above.

The general virtual swap usage is reported by option -s (summary).
For example:

S swap -s
total: 872608k bytes allocated + 165044k reserved = 1037652k used, 12709624k available

As immediately perceived (k), all output is in terms of 1024 bytes units.
Of course the important fields are:

  • allocated: amount of "asked" virtual swap (virtual memory) already written to.
    Note that it doesn't mean that any portion of it has to be necessarily on disk.
    Essentially, it corresponds to memory pages effectively used by processes.
     
    On the given example:
    872608k = 0.832 GB of virtual memory are already in use.
      
  • reserved: amount of "asked" virtual swap (virtual memory) not yet written to.
    This consumes absolutely no space (no memory pages are set aside).

    On the given example:
    165044k = 0.157 GB of virtual memory is yet to be used.
      
  • available: virtual swap (virtual memory) that can be provided to processes.
    On a fresh system this figure is generally almost equal to free from swap -l.
    Disk-based virtual swap space, if present, contributes to it, of course.
    RAM-based virtual swap space may contribute to this figure
    in case swap -l itself shows reserved > blocks.
     
    On the given example:
    12709624k = 12.120 GB of virtual memory is available.
      
The /usr/bin/swap from a Solaris 11 and its -sh option works fine on a Solaris 10.
Of course the binary needs to be of the same architecture (X86 or SPARC).
That's great because -h is very useful.