Solaris Performance and Tools: DTrace and MDB Techniques for Solaris 10 and OpenSolaris

6.4. Physical Memory Allocation

You can use the standard Solaris tools to observe the total physical memory configured, memory used by the kernel, and the amount of "free" memory in the system.

6.4.1. Total Physical Memory

From the output of the Solaris prtconf command, you can ascertain the amount of total physical memory.

# prtconf System Configuration: Sun Microsystems i86pc Memory size: 2048 Megabytes System Peripherals (Software Nodes):

6.4.2. Free Memory

Use the vmstat command to measure free memory. The first line of output from vmstat is an average since boot, so the real free memory figure is available on the second line. The output is in kilobytes. In this example, observe the value of approximately 970 Mbytes of free memory.

# vmstat 3 kthr memory page disk faults cpu r b w swap free re mf pi po fr de sr cd cd f0 s0 in sy cs us sy id 0 0 0 1512468 837776 160 20 12 12 12 0 0 0 1 0 0 589 3978 150 2 0 97 54 0 0 1720376 995556 1 13 27 0 0 0 0 20 176 0 0 1144 4948 1580 1 2 97 0 0 0 1720376 995552 6 65 21 0 0 0 0 22 160 0 0 1191 7099 2139 2 3 95 0 0 0 1720376 995536 0 0 13 0 0 0 0 21 190 0 0 1218 6183 1869 1 3 96

The free memory reported by Solaris includes the cache list portion of the page cache, meaning that you can expect to see a larger free memory size when significant file caching is occurring.

In Solaris 8, free memory did not include pages that were available for use from the page cache, which had recently been added. After a system was booted, the page cache gradually grew and the reported free memory dropped, usually hovering around 8 megabytes. This led to some confusion because Solaris 8 reported low memory even though plenty of pages were available for reuse from the cache. Since Solaris 9, the free column of vmstat has included the cache list portion and as such is a much more useful measure of free memory.

6.4.3. Using the memstat Command in MDB

You can use an mdb command to view the allocation of the physical memory into the buckets described in previous sections. The macro is included with Solaris 9 and later.

sol9# mdb -k Loading modules: [ unix krtld genunix ip ufs_log logindmux ptm cpc sppp ipc random nfs ] > ::memstat Page Summary Pages MB %Tot ------------ ---------------- ---------------- ---- Kernel 53444 208 10% Anon 119088 465 23% Exec and libs 2299 8 0% Page cache 29185 114 6% Free (cachelist) 347 1 0% Free (freelist) 317909 1241 61% Total 522272 2040 Physical 512136 2000

The categories are described as follows:

  • Kernel. The total memory used for nonpageable kernel allocations. This is how much memory the kernel is using, excluding anonymous memory used for ancillaries (see Anon in the next paragraph).

  • Anon. The amount of anonymous memory. This includes user-process heap, stack, and copy-on-write pages, shared memory mappings, and small kernel ancillaries, such as lwp thread stacks, present on behalf of user processes.

  • Exec and libs. The amount of memory used for mapped files interpreted as binaries or libraries. This is typically the sum of memory used for user binaries and shared libraries. Technically, this memory is part of the page cache, but it is page cache tagged as "executable" when a file is mapped with PROT_EXEC and file permissions include execute permission.

  • Page cache. The amount of unmapped page cache, that is, page cache not on the cache list. This category includes the segmap portion of the page cache and any memory mapped files. If the applications on the system are solely using a read/write path, then we would expect the size of this bucket not to exceed segmap_percent (defaults to 12% of physical memory size). Files in /tmp are also included in this category.

  • Free (cachelist). The amount of page cache on the free list. The free list contains unmapped file pages and is typically where the majority of the file system cache resides. Expect to see a large cache list on a system that has large file sets and sufficient memory for file caching. Beginning with Solaris 8, the file system cycles its pages through the cache list, preventing it from stealing memory from other applications unless there is a true memory shortage.

  • Free (freelist). The amount of memory that is actually free. This is memory that has no association with any file or process.

If you want this functionality for Solaris 8, copy the downloadable memory.so library into /usr/lib/mdb/kvm/sparcv9 and then use ::load memory before running ::memstat. (Note that this is not Sun-supported code, but it is considered low risk since it affects only the mdb user-level program.)

# wget http://www.solarisinternals.com/si/downloads/memory.so # cp memory.so /usr/lib/mdb/kvm/sparcv9 # mdb -k Loading modules: [ unix krtld genunix ip ufs_log logindmux ptm cpc sppp ipc random nfs ] > ::load memory > ::memstat

Категории