vmstat – Report virtual memory statistics

A UNIX Command . vmstat -m 

Cache                       Num  Total   Size  Pages
fat_inode_cache              23     23    688     23
fat_cache                   102    102     40    102
isofs_inode_cache             0      0    1006     12
udf_inode_cache              23     23    712     23
fuse_request                  0      0    632     25
fuse_inode                    0      0    768     21
dm_crypt_io                   0      0    152     26
kcopyd_job                    0      0    368     22
dm_uevent                     0      0   2608     12
dm_rq_target_io               0      0    400     20
ext3_inode_cache          11017  12882    824     19
ext3_xattr                    0      0     88     46
journal_handle              170    170     24    170
journal_head                 36     36    112     36
revoke_table                256    256     16    256
revoke_record               128    128     32    128
UDPLITEv6                     0      0   1024     16
UDPv6                        16     16   1024     16
tw_sock_TCPv6                 0      0    320     12
TCPv6                        17     17   1856     17
cfq_queue                   110    119    240     17
Cache                       Num  Total   Size  Pages
bsg_cmd                       0      0    312     13
mqueue_inode_cache           18     18    896     18
hugetlbfs_inode_cache        13     13    624     13
dquot                         0      0    256     16
dnotify_mark                237    240    136     30
pid_namespace                15     15   2112     15
user_namespace                0      0   1072     15
posix_timers_cache           23     23    176     23
UDP-Lite                      0      0    832     19
ip_fib_hash                  46     46     88     46
arp_cache                    36     72    320     12
RAW                         450    475    832     19
UDP                          19     19    832     19
tw_sock_TCP                  16     16    256     16
TCP                          24     38   1664     19
blkdev_queue                 18     18   1736     18
blkdev_requests              34     44    360     22
bip-256                       7      7   4224      7
bip-128                       0      0   2176     15
bip-64                        0      0   1152     14
bip-16                       21     21    384     21
Cache                       Num  Total   Size  Pages
sock_inode_cache            531    575    704     23
file_lock_cache              22     22    184     22
net_namespace                12     12   2560     12
shmem_inode_cache           708    740    816     20
Acpi-ParseExt              1385   1400     72     56
Acpi-Namespace              816    816     40    102
task_delay_info             263    324    112     36
taskstats                    23     24    328     12
proc_inode_cache           1240   11006    1006     12
sigqueue                     25     25    160     25
bdev_cache                   19     19    832     19
sysfs_dir_cache           16424  110024     80     51
inode_cache                1175   1573    608     13
dentry                     8128   9744    192     21
buffer_head              149614 2010005    104     39
vm_area_struct            13975  14520    184     22
mm_struct                   101    119    960     17
files_cache                 105    115    704     23
signal_cache                143    1100   1088     15
sighand_cache               140    1100   2112     15
task_struct                 252    288   1728     18
Cache                       Num  Total   Size  Pages
anon_vma                   6242   6834     40    102
shared_policy_node         9171  10115     48     85
numa_policy                 170    170     24    170
radix_tree_node           19547  19558    568     14
idr_layer_cache             453    4100    544     15
dma-kmalloc-8192              0      0   8192      4
dma-kmalloc-4096              0      0   4096      8
dma-kmalloc-2048              0      0   2048     16
dma-kmalloc-1024              0      0   1024     16
dma-kmalloc-512              16     16    512     16
dma-kmalloc-256               0      0    256     16
dma-kmalloc-128               0      0    128     32
dma-kmalloc-64                0      0     64     64
dma-kmalloc-32                0      0     32    128
dma-kmalloc-16                0      0     16    256
dma-kmalloc-8                 0      0      8    512
dma-kmalloc-192               0      0    192     21
dma-kmalloc-96                0      0     96     42
kmalloc-8192                 11     12   8192      4
kmalloc-4096                582    616   4096      8
kmalloc-2048                233    272   2048     16
Cache                       Num  Total   Size  Pages
kmalloc-1024                596    1006   1024     16
kmalloc-512                 493    544    512     16
kmalloc-256                 696    816    256     16
kmalloc-128                 790    864    128     32
kmalloc-64                 3047   3840     64     64
kmalloc-32                  777   1024     32    128
kmalloc-16                 2778   2816     16    256
kmalloc-8                  4094   4096      8    512
kmalloc-192                5795   6489    192     21
kmalloc-96                  649    798     96     42
kmem_cache                   42     42    192     21
kmem_cache_node             128    128     64     64


UNIX Explanation

vmstat  reports   information  about  processes,  memory,
paging, block IO, traps, disks and cpu activity.


Related Source Code Exposition


int main(int argc, char *argv[]) {
  char *partition = NULL;
  int c;

  while((c = getopt(argc, argv, "VdafmDnp:S:s")) != EOF) switch(c) {
      case 'V':
	display_version();
	exit(0);
      case 'd':
	statMode |= DISKSTAT;
	break;
      case 'a':
	/* active/inactive mode */
	a_option=1;
        break;
      case 'f':
        // FIXME: check for conflicting args
	fork_format();
        exit(0);
      case 'm':
        statMode |= SLABSTAT;
	break;
      case 'D':
        statMode |= DISKSUMSTAT;
	break;
      case 'n':
	/* print only one header */
	moreheaders=FALSE;
        break;
      case 'p':
        statMode |= PARTITIONSTAT;
	partition = optarg;
	if (memcmp(partition, "/dev/", 5) == 0) partition += 5;
        break;
      case 'S':
	switch(optarg[0]) {
	case 'b': case 'B': dataUnit = UNIT_B; break;
	case 'k': dataUnit = UNIT_k; break;
	case 'K': dataUnit = UNIT_K; break;
	case 'm': dataUnit = UNIT_m; break;
	case 'M': dataUnit = UNIT_M; break;
	default:
	  fprintf(stderr, "-S requires k, K, m or M (default is kb)n");
	  exit(EXIT_FAILURE);
	}
	szDataUnit[0] = optarg[0];
	break;
      case 's':
        statMode |= VMSUMSTAT;
	break;
      default:
	/* no other aguments defined yet. */
	usage();
  }

Source Code Highlight


Using getopt to select -m option for slabinfo.

Featured Image
FIXME


Related Knowledge

Physical  memory  the actual  RAM  installe  is a  finite
resource on any system.  The Linux memory handler manages
the  allocation  of  that  limited  resource  by  freeing
portions of physical memory when possible.

All  processes use  memory, of  course, but  each process
doesn't   need   all  its   allocated   memory  all   the
time. Taking advantage of  this fact, the kernel frees up
physical  memory by  writing some  or all  of  a process'
memory to disk until it's needed again.

The  kernel  uses paging  and  swapping  to perform  this
memory  management. Paging  refers  to writing  portions,
termed  pages, of  a process'  memory to  disk. Swapping,
strictly speaking, refers  to writing the entire process,
not  just part,  to  disk.  In  Linux,  true swapping  is
exceedingly rare, but the terms paging and swapping often
are used interchangeably.

When pages  are written  to disk, the  event is  called a
page-out, and when pages are returned to physical memory,
the event  is called a  page-in.A page fault  occurs when
the  kernel  needs a  page,  finds  it  doesn't exist  in
physical  memory  because  it  has  been  paged-out,  and
re-reads it in from disk.

Page-ins  are common,  normal  and are  not  a cause  for
concern.  For example, when  an application  first starts
up, its  executable image and data are  paged-in. This is
normal behavior.

Page-outs, however,  can be a  sign of trouble.  When the
kernel detects that memory is running low, it attempts to
free  up  memory by  paging  out.Though  this may  happen
briefly from time to time, if page-outs are plentiful and
constant,  the  kernel  can  reach  a  point  where  it's
actually spending more time managing paging activity than
running   the   applications,   and  system   performance
suffers. This woeful state is referred to as thrashing.

Using  swap space  is  not inherently  bad. Rather,  it's
intense paging activity that's problematic. For instance,
if your  most-memory-intensive application is  idle, it's
fine  for portions  of it  to be  set aside  when another
large job  is active. Memory  pages belonging to  an idle
application are  better set aside  so the kernel  can use
physical memory for disk buffering.

source : http://www.linuxjournal.com/article/8178