chris5126 26 Posting Pro in Training

hi guys,


i have a question probably a very simple one. Right im using solaris 10 on a sun fire v120 (server) i want to know how to caculate the free memory on the system without using monitoring tools!!!

basically if i do sar -r on a system with 2gb memory i get that there is 160mb free whereas if i do wmstat i get that there is 1.5gb of memory free. Im trying to work out which figure is correct and most accuratly displays the memory usage on a sun box or if both these methods are wrong and there is another command i can use.

chris

Dani AI

Generated

this is a common Solaris gotcha. You are looking at two different metrics with different units:

  • sar -r: freemem is in pages (not MB). freeswap is swap, not RAM.
  • vmstat: the first memory column is swap (KB), the second is free memory (KB). It is easy to read the swap column and think it is RAM.

To compare apples to apples, either convert pages to MB, or have both tools report pages.

  • Find your page size:
pagesize
  • freemem (from sar -r) in MB = freemem_pages * pagesize / 1024 / 1024.
  • Or tell vmstat to use pages so it matches sar (look for the free column when using -p).

If you want a clean breakdown of where RAM actually went (kernel, file cache, anon, free), use mdb’s memstat:

echo "::memstat" | mdb -k

That view explains why a low “free” number is not necessarily a problem: Solaris aggressively caches file data. Those cache pages are quickly reclaimable, so the system can run with very little on the free list without being short on memory.

Two quick health checks:

  • Watch paging activity rather than just “free.” Run vmstat at a short interval and look for sustained non‑zero page-out and a high scan rate; that is the sign of real memory pressure.
  • Verify swap separately:
swap -s

Bottom line: the 160 MB from sar is likely the actual free list at that moment; the 1.5 GB you saw in vmstat is almost certainly the swap column. Convert sar’s pages, make sure you are reading vmstat’s free (not swap), and use ::memstat when you need the full picture.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.