System Administration Guide, Volume 2

How to Check Kernel Memory Allocation (sar -k)

Use the sar -k command to report on the following activities of the Kernel Memory Allocator (KMA).

The KMA allows a kernel subsystem to allocate and free memory as needed. Rather than statically allocating the maximum amount of memory it is expected to require under peak load, the KMA divides requests for memory into three categories: small (less than 256 bytes), large (512 to 4 Kbytes), and oversized (greater than 4 Kbytes). It keeps two pools of memory to satisfy small and large requests. The oversized requests are satisfied by allocating memory from the system page allocator.

If you are investigating a system that is being used to write drivers or STREAMS that use KMA resources, then sar -k will likely prove useful. Otherwise, you will probably not need the information it provides. Any driver or module that uses KMA resources, but does not specifically return the resources before it exits, can create a memory leak. A memory leak causes the amount of memory allocated by KMA to increase over time. Thus, if the alloc fields of sar -k increase steadily over time, there may be a memory leak. Another indication of a memory leak is failed requests. If this occurs, a memory leak has probably caused KMA to be unable to reserve and allocate memory.

If it appears that a memory leak has occurred, you should check any drivers or STREAMS that may have requested memory from KMA and not returned it.


$ sar -k
00:00:00 sml_mem   alloc  fail  lg_mem   alloc   fail  ovsz_alloc  fail
01:00:00 2523136 1866512     0 18939904 14762364    0      360448     0
02:00:02 2523136 1861724     0 18939904 14778748    0      360448     0

Output from the -k option is described in the table below.

Table 36-12 Output From the sar -k Command

Field Name 

Description 

sml_mem

The amount of memory, in bytes, that the KMA has available in the small memory request pool (a small request is less than 256 bytes) 

alloc

The amount of memory, in bytes, that the KMA has allocated from its small memory request pool to small memory requests 

fail

The number of requests for small amounts of memory that failed 

lg_mem

The amount of memory, in bytes, that the KMA has available in the large memory request pool (a large request is from 512 bytes to 4 Kbytes) 

alloc

The amount of memory, in bytes, that the KMA has allocated from its large memory request pool to large memory requests 

fail

The number of failed requests for large amounts of memory 

ovsz_alloc

The amount of memory allocated for oversized requests (those greater than 4 Kbytes); these requests are satisfied by the page allocator--thus, there is no pool 

fail

The number of failed requests for oversized amounts of memory 

Example--Checking Kernel Memory Allocation (sar)

The following is an abbreviated example of sar -k output.


$ sar -k
SunOS venus 5.8 Generic sun4u    09/07/99

00:00:00 sml_mem   alloc  fail  lg_mem   alloc  fail  ovsz_alloc  fail
01:00:00 2523136 1866512     0 18939904 14762364     0      360448     0
02:00:02 2523136 1861724     0 18939904 14778748     0      360448     0
03:00:00 2523136 1865664     0 18939904 14745884     0      360448     0
04:00:00 2523136 1867692     0 18939904 14746616     0      360448     0
05:00:01 2523136 1867208     0 18939904 14763700     0      360448     0
06:00:00 2523136 1867772     0 18939904 14779444     0      360448     0

Average  2724096 1791806     0 20089344 15434591     0      360448     0