System Administration Guide

How to Check Kernel Memory Allocation (sar)

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
SunOS venus 5.6 Generic sun4m    08/20/96
00:00:03  sml_mem   alloc  fail   lg_mem    alloc  fail  ovsz_alloc  fail
01:00:02  1245184  955332     0  3661824  2786336    0      2412544     0

Output from the -k option is described in Table 64-12.

Table 64-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 example of sar -k output.


$ sar -k
SunOS skisun 5.6 Generic sun4m    08/20/96
 
14:28:12  sml_mem  alloc  fail  lg_mem  alloc  fail ovsz_alloc fail
14:29:12   95232   73472     0  311296  198656    0     180224    0
14:30:12   95232   75120     0  311296  198656    0     180224    0
14:31:12   95232   73600     0  311296  197632    0     180224    0
 
Average    95232   74064     0  311296  198314    0     180224    0