Displaying Solaris kernel memory usage

The mdb utility that ships with Solaris 10 is amazing, and allows you to view a wide array of kernel data. Mdb ships with numerous commands (also referred to as dcmds) to view information, and one of my personal favorites is ‘::memstat’:

$ mdb -k

> ::memstat
Page Summary                Pages                MB  %Tot
------------     ----------------  ----------------  ----
Kernel                      13834               108   11%
Anon                        15663               122   12%
Exec and libs                2040                15    2%
Page cache                   7827                61    6%
Free (cachelist)            14248               111   11%
Free (freelist)             75882               592   59%

Total                      129494              1011
Physical                   127634               997

As you can probably tell by it’s name, memstat displays how a system is using memory, and is typically the first place I look to see how memory is allocated. To see how the kernel is using the memory listed in the ‘::memstat’ output, you can use the ‘::kmastat’ dcmd:

$ mdb -k
> ::kmastat

cache                        buf    buf    buf    memory     alloc alloc
name                        size in use  total    in use   succeed  fail
------------------------- ------ ------ ------ --------- --------- -----
kmem_magazine_1               16   3371   3556     57344      3371     0
kmem_magazine_3               32  16055  16256    524288     16055     0
kmem_magazine_7               64  29166  29210   1884160     29166     0
kmem_magazine_15             128   6711   6741    876544      6711     0
kmem_magazine_31             256      0      0         0         0     0
kmem_magazine_47             384      0      0         0         0     0
kmem_magazine_63             512      0      0         0         0     0
kmem_magazine_95             768      0      0         0         0     0
kmem_magazine_143           1152      0      0         0         0     0
kmem_slab_cache               56   7204   7250    409600      7204     0
kmem_bufctl_cache             24  33904  34239    827392     33904     0
kmem_bufctl_audit_cache      128      0      0         0         0     0

If you are trying to figure out how mdb works, check out the sample mdb chapter from the next revision of Solaris kernel internals.

4 Comments

Jacob Sam  on September 17th, 2008

Please add for the benefit of thos trying to use this on earlier releases of Solaris.
mdb is available in earlier versions of solaris (9 and 8) and memstat can be made to work on Solaris 8 by copying memory.so [http://www.solarisinternals.com/si/downloads/index.php] to /usr/lib/mdb/kvm/sparcv9, and then using ::load memory prior to running ::memstat.

Matt Bryant  on February 14th, 2009

Jolly useful post – thanks! :)

Barry Tait  on April 29th, 2009

Very useful – Thanks

Rahul  on December 22nd, 2009

Hi, kernel usage of my server is high, and when i do sar it show %sys high. how do i check which process is eating kernel resources

—cut—
CPU states: 69.8% idle, 10.8% user, 19.4% kernel, 0.0% iowait, 0.0% swap
Memory: 96G phys mem, 73G free mem, 31G total swap, 31G free swap
—cut—

Leave a Comment