vmstat

Updated: April 19, 2023

Display io-sock virtual memory statistics

Syntax:

vmstat [--libxo] [-l] [-mz] [-w wait] [wait]

Runs on:

QNX Neutrino

Options:

The vmstat utility that QNX Neutrino provides is adapted from FreeBSD and supports both a subset of the standard options and the -l (el) QNX Neutrino extension.

For descriptions of standard options, see the FreeBSD documentation (https://www.freebsd.org/cgi/man.cgi?query=vmstat&sektion=8&manpath=FreeBSD+13.0-RELEASE+and+Ports).

-l

Combine with -z or -m to automatically display any memory allocation changes. Enter command characters to select which statistics to display. See Detecting memory allocation changes.”

Description:

The vmstat utility displays virtual memory statistics in the kernel. When you use it with io-sock, because the kernel is simulated, the only statistics it provides are those related to networking features.

The default option for the version of vmstat that QNX Neutrino provides is -m, which displays reports on the memory used by the io-sock dynamic memory allocator (malloc()), by type. It does not support -a, which is the default option for the standard version of vmstat.

For the QNX Neutrino version of vmstat, to use -w (which pauses a specified number of seconds between displaying statistics), you must also specify -l.

Detecting memory allocation changes

The -l (el) option allows you to observe memory allocation changes and is particularly useful for debugging memory leaks. Measurement starts when vmstat starts with -l and refreshes after one second (or the interval set by -w). If you enter the t command and the memory allocation has not changed, nothing is reported.

The standard vmstat option -m displays the dynamic memory usage statistics and -z reports memory used by the io-sock zone allocator (Universal Memory Allocator or UMA), by zone. The -l (el) QNX Neutrino extension allows you to adjust usage statistics to show, for example, usage from the start of monitoring until the current state of usage, or usage from the last refresh until the current state.

The output uses the following terms to describe the output:

first
A snapshot of memory counts when vmstat started (or when you last entered the F command). This snapshot is compared to the current memory count when you enter the f command.
now
The current set of usage statistics (since the last refresh).
last
The set of statistics in the interval before the last refresh. When you enter the t command, current statistics are collected (i.e., now) and compared to last. Then, the now values become the last values.
min and max
The minimum and maximum memory counts since vmstat started (or since you last entered the M command). These values are compared when you enter the m command.

After you start vmstat with -l (el), you can enter the following commands to control the output:

a
Show counts of all memory types (either types displayed by -m or those displayed by -z). Nothing is shown if the counts haven't changed.
f
Show the change in usage between the first interval and the current one (i.e., now). Displays the highest memory use value since vmstat started under HighUse. (MemUse is the current value.)
F
Reset the start point for monitoring (i.e., first) to the current interval (now).
h
Display -l (el) QNX Neutrino extension help.
M
Reset the minimum and maximum values to the current ones.
m
Show the difference between max and min in the current set of usage statistics (under InUseDelta) and the difference between them since vmstat started. The Last values indicate the change in these values since the last time you entered m.
n
Show the change in values from the interval before the last refresh to the current interval.
t
Compare current statistics (i.e., now) to ones in the interval before the last refresh (last), and then save the now values as the last values.
x
Exit memory allocation monitoring.

Examples:

The following example illustrates how you can use vmstat to check for memory leaks.

The vmstat utility is started with -lm. The F command resets the starting point for monitoring, and then the f command displays the change between the starting point and now. Because the count is reset, no statistics are displayed:

F
Copy now->first

f Tue Apr  6 15:28:44 2021 (first->now) delta
Type                    InUse ( Delta)   MemUse  HighUse Requests Size(s) 

After mounting a driver (e.g., mount -T io-sock ixgbe), entering f displays the change in memory allocation generated by the mount task:

f
Tue Apr  6 15:28:48 2021 (first->now) delta
Type                    InUse ( Delta)   MemUse  HighUse Requests  Size(s) 
ifaddr:                    32 (    11)      12K      12K       87  16,32,64,256,512,2048,4096
ifnet:                      6 (     1)      11K      11K       11  128,2048
lltable:                   16 (     4)       4K       4K       36  256
BPF:                        5 (     1)       2K       2K       10  256
igmp:                       5 (     1)       1K       1K       10  128
busdma:                 49209 ( 49209)   67589K   67589K   295254  64,128,2048
linker:                    12 (     3)       3K       3K      103  16,32,512
temp:                      23 (     2)       1K       1K    33744  16,32,64,65536
module:                    85 (     2)      11K      11K       95  128
sysctloid:               1864 (  1561)      97K      97K     9682  16,32,64,128,256
mld:                        3 (     1)       1K       1K        8  128
ip6ndp:                     4 (     1)       1K       1K        9  64,256
resmgr:                     4 (     4)       7K       7K       47  128,2048,4096
nexusdev:                  12 (     9)       2K       2K       57  16,128
bus:                      127 (    15)      14K      14K      273  16,32,64,128,256
eventhandler:              69 (     2)       7K       7K       79  64,128
kobj:                      43 (     3)     172K     172K       64  4096
rman:                      20 (    14)       3K       3K       90  32,128
LRO:                       16 (    16)     320K     320K       96  8192,32768
iflib:                    101 (   101)    1209K    1209K      630  64,256,512,1024,8192,16384,32768
ix:                        11 (    11)      37K      37K       11  1024,2048,4096 

After unmounting the driver (e.g., umount -f /dev/io-sock/devs-ixgbe.so), entering f displays no statistics (i.e., no change), which indicates that the memory was released:

f Tue Apr  6 15:28:55 2021 (first->now) delta
Type                    InUse ( Delta)   MemUse  HighUse Requests Size(s)
ix:                  UNLOADED (Check logs for 'Warning: memory type ix leaked memory on destroy')
x exit!
#

Because the driver destroyed the ix memory type, vmstat can no longer compare it to counts in the current interval.

To detect whether any ix memory leaked when the driver destroyed that memory type, enter the following grep search of log information (after exiting the interactive monitor, or in another terminal). If there is no leak, no log is generated:

# slog2info | grep "Warning: memory type ix leaked memory on destroy" 
Dec 12 18:54:21.685 io_sock.77291564 main_buffer 60 Warning: memory type ix leaked
memory on destroy (11 allocations, 37888 bytes leaked).