System Administration Guide: Advanced Administration

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 bytes to 4 Kbytes), and oversized (greater than 4 Kbytes). The KMA 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 the sar -k command 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 that is allocated by KMA to increase over time. Thus, if the alloc fields of the sar -k command increase steadily over time, there might be a memory leak. Another indication of a memory leak is failed requests. If this problem 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 might 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

The following table describes the output from the -k option.

Table 24–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, where 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, where 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 that is allocated for oversized requests, which are requests that are 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 touchstone 5.9 Generic sun4u    03/04/2003

00:00:05 sml_mem   alloc  fail  lg_mem   alloc  fail  ovsz_alloc  fail
01:00:03 1761280 1209760     0 4833280 3955104     0     2293760     0
02:00:05 1761280 1209020     0 4833280 3953360     0     2293760     0
03:00:03 1761280 1208712     0 4833280 3972096     0     2293760     0
04:00:03 1761280 1209796     0 4833280 3976432     0     2293760     0
05:00:03 1761280 1207708     0 4833280 3976864     0     2293760     0
06:00:04 1761280 1208112     0 4833280 3977200     0     2293760     0
07:00:04 1761280 1209024     0 4833280 3977200     0     2293760     0
08:00:04 1761280 1208932     0 4833280 4035120     0     2293760     0
08:20:04 1761280 1210480     0 4833280 4035120     0     2293760     0
08:40:04 1761280 1210592     0 4833280 4035968     0     2293760     0
09:00:03 1761280 1212440     0 4833280 4039024     0     2293760     0
09:20:04 1761280 1214388     0 4833280 4043792     0     2293760     0
09:40:04 1761280 1210760     0 4833280 4041744     0     2293760     0
10:00:05 1761280 1208192     0 4833280 4040496     0     2293760     0
10:20:03 1761280 1213404     0 4833280 4046576     0     2293760     0
10:40:02 1761280 1212184     0 4833280 4046576     0     2293760     0

Average  1761280 1210219     0 4833280 4009542     0     2293760     0