[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Performance Management Guide

Memory usage

Several performance tools provide memory usage reports. The reports of most interest are from the vmstat, ps, and svmon commands.

Memory usage determination with the vmstat command

The vmstat command summarizes the total active virtual memory used by all of the processes in the system, as well as the number of real-memory page frames on the free list. Active virtual memory is defined as the number of virtual-memory working segment pages that have actually been touched. For a more detailed definition, see Late page space allocation. This number can be larger than the number of real page frames in the machine, because some of the active virtual-memory pages may have been written out to paging space.

When determining if a system might be short on memory or if some memory tuning needs to be done, run the vmstat command over a set interval and examine the pi and po columns on the resulting report. These columns indicate the number of paging space page-ins per second and the number of paging space page-outs per second. If the values are constantly non-zero, there might be a memory bottleneck. Having occasional non-zero values is not be a concern because paging is the main principle of virtual memory.

# vmstat 2 10
kthr     memory             page              faults        cpu
----- ----------- ------------------------ ------------ -----------
 r  b   avm   fre  re  pi  po  fr   sr  cy  in   sy  cs us sy id wa
 1  3 113726   124   0  14   6 151  600   0 521 5533 816 23 13  7 57
 0  3 113643   346   0   2  14 208  690   0 585 2201 866 16  9  2 73
 0  3 113659   135   0   2   2 108  323   0 516 1563 797 25  7  2 66
 0  2 113661   122   0   3   2 120  375   0 527 1622 871 13  7  2 79
 0  3 113662   128   0  10   3 134  432   0 644 1434 948 22  7  4 67
 1  5 113858   238   0  35   1 146  422   0 599 5103 903 40 16  0 44
 0  3 113969   127   0   5  10 153  529   0 565 2006 823 19  8  3 70
 0  3 113983   125   0  33   5 153  424   0 559 2165 921 25  8  4 63
 0  3 113682   121   0  20   9 154  470   0 608 1569 1007 15  8  0 77
 0  4 113701   124   0   3  29 228  635   0 674 1730 1086 18  9  0 73

In the example output above, notice the high I/O wait in the output and also the number of threads on the blocked queue. Other I/O activities might cause I/O wait, but in this particular case, the I/O wait is most likely due to the paging in and out from paging space.

To see if the system has performance problems with its VMM, examine the columns under memory and page:

One way to determine the appropriate amount of RAM for a system is to look at the largest value for avm as reported by the vmstat command. Multiply that by 4 K to get the number of bytes and then compare that to the number of bytes of RAM on the system. Ideally, avm should be smaller than total RAM. If not, some amount of virtual memory paging will occur. How much paging occurs will depend on the difference between the two values. Remember, the idea of virtual memory is that it gives us the capability of addressing more memory than we have (some of the memory is in RAM and the rest is in paging space). But if there is far more virtual memory than real memory, this could cause excessive paging which then results in delays. If avm is lower than RAM, then paging-space paging could be caused by RAM being filled up with file pages. In that case, tuning the minperm,maxperm, and maxclient values could reduce the amount of paging-space paging. Refer to VMM page replacement tuning with the vmo command for more information.

The vmstat -I command

The vmstat -I command displays additional information, such as file pages in per-second, file pages out per-second which means any VMM page-ins and page-outs that are not paging space page-ins or paging space page-outs. The re and cy columns are not reported with this flag.

The vmstat -s command

The summary option, -s, sends a summary report to standard output starting from system initialization expressed in absolute counts rather than on an interval basis. The recommended way of using these statistics is to run this command before a workload, save the output, and then run it again after the workload and save its output. The next step is to determine the difference between the two sets of output. An awk script called vmstatit that does this automatically is provided in Determining whether the problem is related to disk or memory.

# vmstat -s
  3231543 total address trans. faults
    63623 page ins
   383540 page outs
      149 paging space page ins
      832 paging space page outs
        0 total reclaims
   807729 zero filled pages faults
     4450 executable filled pages faults
   429258 pages examined by clock
        8 revolutions of the clock hand
   175846 pages freed by the clock
    18975 backtracks
        0 lock misses
       40 free frame waits
        0 extend XPT waits
    16984 pending I/O waits
   186443 start I/Os
   186443 iodones
141695229 cpu context switches
317690215 device interrupts
        0 software interrupts
        0 traps
 55102397 syscalls

The page-in and page-out numbers in the summary represent virtual memory activity to page in or out pages from page space and file space. The paging space ins and outs are representative of only page space.

Memory usage determination with the ps command

The ps command can also be used to monitor memory usage of individual processes. The ps v PID command provides the most comprehensive report on memory-related statistics for an individual process, such as:

The following is an example:

# ps v
   PID    TTY STAT  TIME PGIN  SIZE   RSS   LIM  TSIZ   TRS %CPU %MEM COMMAND
 36626  pts/3 A     0:00    0   316   408 32768    51    60  0.0  0.0 ps v

The most important columns on the resulting ps report are described as follows:

PGIN
Number of page-ins caused by page faults. Since all I/O is classified as page faults, this is basically a measure of I/O volume.
SIZE
Virtual size (in paging space) in kilobytes of the data section of the process (displayed as SZ by other flags). This number is equal to the number of working segment pages of the process that have been touched times 4. If some working segment pages are currently paged out, this number is larger than the amount of real memory being used. SIZE includes pages in the private segment and the shared-library data segment of the process.
RSS
Real-memory (resident set) size in kilobytes of the process. This number is equal to the sum of the number of working segment and code segment pages in memory times 4. Remember that code segment pages are shared among all of the currently running instances of the program. If 26 ksh processes are running, only one copy of any given page of the ksh executable program would be in memory, but the ps command would report that code segment size as part of the RSS of each instance of the ksh program.
TSIZ
Size of text (shared-program) image. This is the size of the text section of the executable file. Pages of the text section of the executable program are only brought into memory when they are touched, that is, branched to or loaded from. This number represents only an upper bound on the amount of text that could be loaded. The TSIZ value does not reflect actual memory usage. This TSIZ value can also be seen by executing the dump -ov command against an executable program (for example, dump -ov /usr/bin/ls).
TRS
Size of the resident set (real memory) of text. This is the number of code segment pages times 4. This number exaggerates memory use for programs of which multiple instances are running. The TRS value can be higher than the TSIZ value because other pages may be included in the code segment such as the XCOFF header and the loader section.
%MEM
Calculated as the sum of the number of working segment and code segment pages in memory times 4 (that is, the RSS value), divided by the size of the real memory of the machine in KB, times 100, rounded to the nearest full percentage point. This value attempts to convey the percentage of real memory being used by the process. Unfortunately, like RSS, it tends the exaggerate the cost of a process that is sharing program text with other processes. Further, the rounding to the nearest percentage point causes all of the processes in the system that have RSS values under 0.005 times real memory size to have a %MEM of 0.0.
Note:
The ps command does not indicate memory consumed by shared memory segments or memory-mapped segments. Because many applications use shared memory or memory-mapped segments, the svmon command is a better tool to view the memory usage of these segments.

The svmon command

The svmon command provides a more in-depth analysis of memory usage. It is more informative, but also more intrusive, than the vmstat and ps commands. The svmon command captures a snapshot of the current state of memory. However, it is not a true snapshot because it runs at the user level with interrupts enabled.

To determine whether svmon is installed and available, run the following command:

# lslpp -lI bos.perf.tools

The svmon command can only be executed by the root user.

If an interval is used, which is the -i option, statistics will be displayed until the command is killed or until the number of intervals, which can be specified right after the interval, is reached.

You can use the following different reports to analyze the displayed information:

Global (-G)
Displays statistics describing the real memory and paging space in use for the whole system.
Process (-P)
Displays memory usage statistics for active processes.
Segment (-S)
Displays memory usage for a specified number of segments or the top ten highest memory-usage processes in descending order.
Detailed Segment (-D)
Displays detailed information on specified segments.
User (-U)
Displays memory usage statistics for the specified login names. If no list of login names is supplied, memory usage statistics display all defined login names.
Command (-C)
Displays memory usage statistics for the processes specified by command name.
Workload Management Class (-W)
Displays memory usage statistics for the specified workload management classes. If no classes are supplied, memory usage statistics display all defined classes.
Frame (-F)
Displays information about frames. When no frame number is specified, the percentage of used memory is reported. When a frame number is specified, information about that frame is reported.
Tier (-T)
Displays information about tiers, such as the tier number, the superclass name when the -a flag is used, and the total number of pages in real memory from segments belonging to the tier.

Amount of memory in use

To print out global statistics, use the -G flag. In this example, we will repeat it five times at two-second intervals.

# svmon -G -i 2 5
       m e m o r y            i n  u s e            p i n        p g  s p a c e
  size inuse  free   pin   work  pers  clnt   work  pers  clnt     size   inuse
 16384 16250   134  2006  10675  2939  2636   2006     0     0    40960   12674
 16384 16254   130  2006  10679  2939  2636   2006     0     0    40960   12676
 16384 16254   130  2006  10679  2939  2636   2006     0     0    40960   12676
 16384 16254   130  2006  10679  2939  2636   2006     0     0    40960   12676
 16384 16254   130  2006  10679  2939  2636   2006     0     0    40960   12676

The columns on the resulting svmon report are described as follows:

memory
Statistics describing the use of real memory, shown in 4 K pages.
size
Total size of memory in 4 K pages.
inuse
Number of pages in RAM that are in use by a process plus the number of persistent pages that belonged to a terminated process and are still resident in RAM. This value is the total size of memory minus the number of pages on the free list.
free
Number of pages on the free list.
pin
Number of pages pinned in RAM (a pinned page is a page that is always resident in RAM and cannot be paged out).
in use
Detailed statistics on the subset of real memory in use, shown in 4 K frames.
work
Number of working pages in RAM.
pers
Number of persistent pages in RAM.
clnt
Number of client pages in RAM (client page is a remote file page).
pin
Detailed statistics on the subset of real memory containing pinned pages, shown in 4 K frames.
work
Number of working pages pinned in RAM.
pers
Number of persistent pages pinned in RAM.
clnt
Number of client pages pinned in RAM.
pg space
Statistics describing the use of paging space, shown in 4 K pages. This data is reported only if the -r flag is not used. The value reported is the actual number of paging-space pages used, which indicates that these pages were paged out to the paging space. This differs from the vmstat command in that the vmstat command's avm column which shows the virtual memory accessed but not necessarily paged out.
size
Total size of paging space in 4 K pages.
inuse
Total number of allocated pages.

In the example, there are 16384 pages of total size of memory. Multiply this number by 4096 to see the total real memory size (64 MB). While 16250 pages are in use, there are 134 pages on the free list and 2006 pages are pinned in RAM. Of the total pages in use, there are 10675 working pages in RAM, 2939 persistent pages in RAM, and 2636 client pages in RAM. The sum of these three parts is equal to the inuse column of the memory part. The pin part divides the pinned memory size into working, persistent and client categories. The sum of them is equal to the pin column of the memory part. There are 40960 pages (160 MB) of total paging space, and 12676 pages are in use. The inuse column of memory is usually greater than the inuse column of pg space because memory for file pages is not freed when a program completes, while paging-space allocation is.

The following output is an example of the svmon command:

# svmon -G -i 2 5

               size      inuse       free        pin    virtual
memory        65527      64087       1440       5909      81136
pg space     131072      55824

               work       pers       clnt
pin            5918          0          0
in use        47554      13838       2695


               size      inuse       free        pin    virtual
memory        65527      64091       1436       5909      81137
pg space     131072      55824

               work       pers       clnt
pin            5918          0          0
in use        47558      13838       2695


               size      inuse       free        pin    virtual
memory        65527      64091       1436       5909      81137
pg space     131072      55824

               work       pers       clnt
pin            5918          0          0
in use        47558      13838       2695


               size      inuse       free        pin    virtual
memory        65527      64090       1437       5909      81137
pg space     131072      55824

               work       pers       clnt
pin            5918          0          0
in use        47558      13837       2695


               size      inuse       free        pin    virtual
memory        65527      64168       1359       5912      81206
pg space     131072      55824

               work       pers       clnt
pin            5921          0          0
in use        47636      13837       2695

The additional output field is the virtual field, which shows the number of pages allocated in the system virtual space.

Memory usage by processes

The following command displays the memory usage statistics for the top ten processes. If you do not specify a number, it will display all the processes currently running in the system.

# svmon -Pau 10

  Pid                         Command        Inuse        Pin      Pgspace
15012                     maker4X.exe         4783       1174         4781
 2750                               X         4353       1178         5544
15706                            dtwm         3257       1174         4003
17172                       dtsession         2986       1174         3827
21150                          dtterm         2941       1174         3697
17764                         aixterm         2862       1174         3644
 2910                          dtterm         2813       1174         3705
19334                          dtterm         2813       1174         3704
13664                          dtterm         2804       1174         3706
17520                         aixterm         2801       1174         3619

Pid:  15012
Command:  maker4X.exe

Segid  Type  Description          Inuse    Pin  Pgspace  Address Range
 1572  pers  /dev/hd3:62              0      0        0  0..-1
  142  pers  /dev/hd3:51              0      0        0  0..-1
 1bde  pers  /dev/hd3:50              0      0        0  0..-1
  2c1  pers  /dev/hd3:49              1      0        0  0..7
  9ab  pers  /dev/hd2:53289           1      0        0  0..0
  404  work  kernel extension        27     27        0  0..24580
 1d9b  work  lib data                39      0       23  0..607
  909  work  shared library text    864      0        7  0..65535
  5a3  work  sreg[4]                  9      0       12  0..32768
 1096  work  sreg[3]                 32      0       32  0..32783
 1b9d  work  private               1057      1     1219  0..1306 : 65307..65535
 1af8  clnt                         961      0        0  0..1716
    0  work  kernel                1792   1146     3488  0..32767 : 32768..65535
...

The output is divided into summary and detail sections. The summary section lists the top ten highest memory-usage processes in descending order.

Pid 15012 is the process ID that has the highest memory usage. The Command indicates the command name, in this case maker4X.exe. The Inuse column, which is the total number of pages in real memory from segments that are used by the process, shows 4783 pages. Each page is 4 KB. The Pin column, which is the total number of pages pinned from segments that are used by the process, shows 1174 pages. The Pgspace column, which is the total number of paging-space pages that are used by the process, shows 4781 pages.

The detailed section displays information about each segment for each process that is shown in the summary section. This includes the segment ID, the type of the segment, description (a textual description of the segment, including the volume name and i-node of the file for persistent segments), number of pages in RAM, number of pinned pages in RAM, number of pages in paging space, and address range.

The Address Range specifies one range for a persistent or client segment and two ranges for a working segment. The range for a persistent or a client segment takes the form '0..x,' where x is the maximum number of virtual pages that have been used. The range field for a working segment can be '0..x : y..65535', where 0..x contains global data and grows upward, and y..65535 contains stack area and grows downward. For the address range, in a working segment, space is allocated starting from both ends and working towards the middle. If the working segment is non-private (kernel or shared library), space is allocated differently. In this example, the segment ID 1b9d is a private working segment; its address range is 0..1306 : 65307..65535. The segment ID 909 is a shared library text working segment; its address range is 0..65535.

A segment can be used by multiple processes. Each page in real memory from such a segment is accounted for in the Inuse field for each process using that segment. Thus, the total for Inuse may exceed the total number of pages in real memory. The same is true for the Pgspace and Pin fields. The sum of Inuse, Pin, and Pgspace of all segments of a process is equal to the numbers in the summary section.

The Vsid column is the virtual segment ID, and the Esid column is the effective segment ID. The effective segment ID reflects the segment register that is used to access the corresponding pages.

You can use one of the following commands to display the file name associated with the i-node:

Detailed information on a specific segment id

The -D option displays detailed memory-usage statistics for segments.

The following is an example:

# svmon -D 629 -b

Segid: 629
Type:  working
Address Range: 0..77
Size of page space allocation: 7 pages (  0.0 Mb)
Virtual: 11 frames ( 0.0 Mb)
Inuse: 7 frames ( 0.0 Mb)

           Page      Frame    Pin        Ref        Mod
              0      32304     N          Y          Y
              3      32167     N          Y          Y
              7      32321     N          Y          Y
              8      32320     N          Y          Y
              5      32941     N          Y          Y
              1      48357     N          N          Y
             77      47897     N          N          Y

The explanation of the columns are as follows:

Page
Specifies the index of the page within the segment.
Frame
Specifies the index of the real memory frame that the page resides in.
Pin
Specifies a flag indicating whether the page is pinned.
Ref
Specifies a flag indicating whether the page's reference bit is on.
Mod
Specifies a flag indicating whether the page is modified.

The -b flag shows the status of the reference and modified bits of all the displayed frames. After it is shown, the reference bit of the frame is reset. When used with the -i flag, it detects which frames are accessed between each interval.

List of top memory usage of segments

The -S option is used to sort segments by memory usage and to display the memory-usage statistics for the top memory-usage segments. The following command sorts system and non-system segments by the number of pages in real memory. The -t option can be used to limit the number of segments displayed to the count specified. The -u flag sorts the output in descending order by the total number of pages in real memory.

The following is example output of the svmon command with the -S, -t, and -u options:

# svmon -Sut 10

  Vsid     Esid Type Description           Inuse   Pin Pgsp Virtual Addr Range
  1966        - work                        9985     4 31892 32234   0..32272 :
                                                                    65309..65535
  14c3        - work                        5644     1  161  5993   0..6550 :
                                                                    65293..65535
  5453        - work                        3437     1 2971  4187   0..4141 :
                                                                    65303..65535
  4411        - work                        3165     0 1264  1315   0..65535
  5a1e        - work                        2986     1   13  2994   0..3036 :
                                                                    65295..65535
  340d        - work misc kernel tables     2643     0  993  2645   0..15038 :
                                                                    63488..65535
  380e        - work kernel pinned heap     2183  1055 1416  2936   0..65535
     0        - work kernel seg             2044  1455 1370  4170   0..32767 :
                                                                    65475..65535
  6afb        - pers /dev/notes:92          1522     0    -     -   0..10295
  2faa        - clnt                        1189     0    -     -   0..2324

Correlation between the svmon and vmstat command outputs

There is a correlation between the svmon and vmstat outputs.

The following is example output from the svmon command:

# svmon -G
               size      inuse       free        pin    virtual
memory      2097136    1347642     749494     156369     205041
pg space     249856        871

               work       pers       clnt      lpage
pin          156369          0          0          0
in use       205060    1130522      12060          0

The vmstat command was run in a separate window while the svmon command was running. The vmstat report follows:

# vmstat 5
kthr     memory             page              faults        cpu     
----- ----------- ------------------------ ------------ -----------
 r  b   avm   fre  re  pi  po  fr   sr  cy  in   sy  cs us sy id wa 
 1  5 205031 749504   0   0   0   0    0   0 1240  248 318  0  0 99  0
 0  0 205042 749493   0   0   0   0    0   0 1242  663 319  0  0 99  0
 0  0 205042 749493   0   0   0   0    0   0 1244  658 320  0  0 99  0
 0  0 205042 749493   0   0   0   0    0   0 1241  665 317  0  0 99  0
 0  0 205042 749493   0   0   0   0    0   0 1242  655 318  0  0 99  0
 0  0 205042 749493   0   0   0   0    0   0 1242  656 320  0  0 99  0
 0  0 205042 749493   0   0   0   0    0   0 1241  654 316  0  0 99  0

The global svmon report shows related numbers. The fre column of the vmstat command relates to the memory fre column of the svmon command. The Active Virtual Memory, avm, value of 205042 that the vmstat command reports is similar to the virtual memory value of 205041 that the svmon command reports.

Correlation between the svmon and ps command outputs

There are some relationships between the svmon and ps command outputs. The svmon command output is as follows:

# svmon -P 770204

-------------------------------------------------------------------------------
     Pid Command          Inuse      Pin     Pgsp  Virtual 64-bit Mthrd LPage
  770204 -ksh              7930     3273      869     7870      N     N     N

    Vsid      Esid Type Description              LPage  Inuse   Pin Pgsp Virtual

       0         0 work kernel segment               -   5994  3269  869  5994 
   509aa         d work loader segment               -   1794     0    0  1794 
   98fb3         2 work process private              -     59     4    0    59 
    8c21         1 clnt code,/dev/hd2:88             -     58     0    -     - 
   88fd1         f work shared library data          -     23     0    0    23 
   58fcb         - clnt /dev/hd4:1158                -      2     0    -     - 

Compare the above example with the ps report which follows:

# ps v 770204
    PID    TTY STAT  TIME PGIN  SIZE   RSS   LIM  TSIZ   TRS %CPU %MEM COMMAND
 770204  pts/0 A     0:00    0   328   560    xx   202   232  0.0  0.0 -ksh 

The SIZE value of 328 correlates to the Virtual value of the svmon command for process private value of 59 plus the shared library data value of 23, which is in 1 KB units. This number is equal to the number of working segment pages of the process that have been touched (that is, the number of paging-space pages that have been allocated) times 4. It must be multiplied by 4 because pages are in 4 K units and SIZE is in 1 K units. If some working segment pages are currently paged out, this number is larger than the amount of real memory being used. The SIZE value (240) correlates with the Pgspace number from the svmon command for private (32) plus lib data (28) in 1 K units.

RSS refers to the real memory (resident set) size in KB of the process. This number is equal to the sum of the number of working segment and code segment pages in memory times 4. Remember that code segment pages are shared among all of the currently running instances of the program. If 26 ksh processes are running, only one copy of any given page of the ksh executable program would be in memory, but the ps command would report that code segment size as part of the RSS of each instance of the ksh program. The RSS value of 560 correlates with the Inuse numbers from the svmon command for the private value of 59 working-storage segments, for 58 code segments, and for the shared library data value of 23 of the process in 1 KB units.

The TRS value refers to the size of the resident set (real memory) of text. This is the number of code segment pages times four. As was noted earlier, this number exaggerates memory use for programs of which multiple instances are running. This does not include the shared text of the process. The TRS value of 232 correlates with the number of the svmon pages in the code segment (58) of the Inuse column in 1 K units. The TRS value can be higher than the TSIZ value because other pages, such as the XCOFF header and the loader section, may be included in the code segment.

The following calculations can be made for the values mentioned:

SIZE = 4 * Pgspace of (work lib data + work private)
RSS  = 4 * Inuse of (work lib data + work private + pers code)
TRS  = 4 * Inuse of (pers code)

Minimum memory requirement calculation

The formula to calculate the minimum memory requirement of a program is the following:

Total memory pages (4 KB units) = T + ( N * ( PD + LD ) ) + F

where:

T
= Number of pages for text (shared by all users)
N
= Number of copies of this program running simultaneously
PD
= Number of working segment pages in process private segment
LD
= Number of shared library data pages used by the process
F
= Number of file pages (shared by all users)

Multiply the result by 4 to obtain the number of kilobytes required. You may want to add in the kernel, kernel extension, and shared library text segment values to this as well even though they are shared by all processes on the system. For example, some applications like CATIA and databases use very large shared library modules. Note that because we have only used statistics from a single snapshot of the process, there is no guarantee that the value we get from the formula will be the correct value for the minimum working set size of a process. To get working set size, one would need to run a tool such as the rmss command or take many snapshots during the life of the process and determine the average values from these snapshots. See Memory requirements assessment with the rmss Command for more information.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]