Search code examples
memory-managementsolaris

Physical Memory Utilization in Solaris


From previous questions on the topic I've found two ways of getting the memory usage:

  1. echo "::memstat" | mdb -k
  2. a=$(/usr/sbin/prtconf | /usr/bin/awk '/Memory/ {print $3*1024}'); vmstat 1 2 | tail -1 | awk "{print 100 - (\$5 / $a) * 100}"

I opted for the first one since I'd rather rely on existing tooling rather than calculating it on my own. However, on some systems the output of "::memstat" is formatted slightly differently than others (Header starts with "Usage Type/Subtype" instead of "Page Summary" etc). This is a bit of an issue since I'm parsing it in code.

I could just fix the parser to deal with both variants, hoping that there are no other variants in hiding.

Could anyone suggest a better way that won't be as brittle?


Solution

  • Eventually found the answer in the Solaris documentation.

    sysconf offers _SC_PHYS_PAGES for total pages and _SC_AVPHYS_PAGES for available pages