I need to show physical memory statistics in Solaris, like total memory, used and free memory. Don't want to create a script, so is it possible to get all these details using commandline only?
To see installed memory you can use this command:
$ prtconf | grep Memory Memory size: 65408 Megabytes
prtdiag -v | grep Memory.
Additional methods are shown here: Used memory on Solaris 10.
root@solaris11:~# vmstat -p
memory page executable anonymous filesystem swap free re mf fr de sr epi epo epf api apo apf fpi fpo fpf 3430236 2679108 67 533 0 0 127 0 0 0 0 0 0 0 0 0
Memory management is complicated. For example in vmstat you will see a column
sr, which is the scan rate. When a Solaris server starts running out of memory it starts scanning for pages and that value shows how quickly it's scanning. If you have a memory-critical application then that must be 0, if it isn't then you need to add more memory.
To come back to your original question, this is what you're looking for, it needs to be run as root:
root@vru-ws1 # echo "::memstat" | mdb -k Page Summary Pages MB %Tot ------------ ---------------- ---------------- ---- Kernel 677215 5290 16% ZFS File Data 2280669 17817 55% Anon 1004294 7846 24% Exec and libs 39636 309 1% Page cache 4279 33 0% Free (cachelist) 20806 162 0% Free (freelist) 101869 795 2% Total 4128768 32256 root@vru-ws1 #
But as with all memory matters, that needs interpretation. For example ZFS is using 55% of RAM, but to be honest it could get away with a lot less, it's just taking it because it can. If something else needs it then the OS will reduce ZFS's file data; to a point, beyond which it will affect ZFS performance. If anyone wants me to further elaborate I'd be happy to do so.
Lastly, Oracle has an excellent article which covers this and more besides. You'll need a login on Oracle support, but not a subscription.