EECE-4029 Operating Systems Fall 2016
System Commands for Memory Control and Status

processes, mutex, semaphores, memory management, producer-consumer, files, deadlock, more..

vmstat     - Report virtual memory status

Procs
  r: The number of processes waiting for run time.
  b: The number of processes in uninterruptible sleep.

Memory
  swpd: the amount of virtual memory used.
  free: the amount of idle memory.
  buff: the amount of memory used as buffers.
  cache: the amount of memory used as cache.
  inact: the amount of inactive memory. (-a option)
  active: the amount of active memory. (-a option)

Swap
  si: Amount of memory swapped in from disk (/s).
  so: Amount of memory swapped to disk (/s).

IO
  bi: Blocks received from a block device (blocks/s).
  bo: Blocks sent to a block device (blocks/s).

System
  in: The number of interrupts per second, including the clock.
  cs: The number of context switches per second.

CPU
  These are percentages of total CPU time.
  us: Time spent running non-kernel code. (user time, including nice time)
  sy: Time spent running kernel code. (system time)
  id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
  wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
  st: Time stolen from a virtual machine.

Example:
  prompt: vmstat
  procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
   r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
   0  0  21120 176812 217876 804804    0    0    25    30  291  116 10  5 85  1  0
 
free     - Report amount of unused and used memory

Example:
  prompt> free
               total       used       free     shared    buffers     cached
  Mem:       1935552    1761100     174452          0     218120     806168
  -/+ buffers/cache:     736812    1198740
  Swap:      3899388      21120    3878268
 
top     - Reports a real-time view of current processes

Example:
  prompt> top
  top - 15:53:08 up 1 day,  6:50,  4 users,  load average: 0.13, 0.18, 0.26
  Tasks: 169 total,   1 running, 167 sleeping,   1 stopped,   0 zombie
  Cpu(s):  9.8%us,  4.5%sy,  0.0%ni, 84.8%id,  0.8%wa,  0.0%hi,  0.1%si,  0.0%st
  Mem:   1935552k total,  1769680k used,   165872k free,   218548k buffers
  Swap:  3899388k total,    21120k used,  3878268k free,   813832k cached

    PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
   1256 franco    20   0  338m  61m  34m S  7.7  3.3  81:52.33 kwin
    977 root      20   0  173m  79m  10m S  3.9  4.2  69:34.18 X
   1106 franco    20   0 38588  10m 9116 S  3.9  0.6  21:09.93 gkrellm
   9965 franco    20   0  2900 1056  800 R  1.9  0.1   0:00.02 top
 
pmap     - Report and examine memory map of a process

Example:
  prompt> pmap -x 1256
  Address   Kbytes     RSS   Dirty Mode   Mapping
  08048000       4       4       0 r-x--  kwin
  08049000       4       4       4 rw---  kwin
  08c5a000   11024   10944   10944 rw---    [ anon ]
  41000000   31476    7024    4496 r-x--  libnvidia-glcore.so.304.51
  42ebd000     404     188     144 rwx--  libnvidia-glcore.so.304.51

  prompt> pmap -d 1256
  Address   Kbytes Mode  Offset           Device    Mapping
  08048000       4 r-x-- 0000000000000000 0fd:00001 kwin
  08049000       4 rw--- 0000000000000000 0fd:00001 kwin
  08c5a000   11024 rw--- 0000000000000000 000:00000   [ anon ]
  41000000   31476 r-x-- 0000000000000000 0fd:00001 libnvidia-glcore.so.304.51
  42ebd000     404 rwx-- 0000000001ebd000 0fd:00001 libnvidia-glcore.so.304.51
 
time     - Report sys page size, page faults, etc of a process during execution

Example:
  prompt> /usr/bin/time -v date
    Command being timed: "date"
    User time (seconds): 0.00
    System time (seconds): 0.00
    Percent of CPU this job got: 33%
    Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
    Average shared text size (kbytes): 0
    Average unshared data size (kbytes): 0
    Average stack size (kbytes): 0
    Average total size (kbytes): 0
    Maximum resident set size (kbytes): 692
    Average resident set size (kbytes): 0
    Major (requiring I/O) page faults: 0
    Minor (reclaiming a frame) page faults: 200
    Voluntary context switches: 1
    Involuntary context switches: 2
    Swaps: 0
    File system inputs: 0
    File system outputs: 0
    Socket messages sent: 0
    Socket messages received: 0
    Signals delivered: 0
    Page size (bytes): 4096
    Exit status: 0
 
sar     - Collect, report, or save system activity information

  pgpgin/s
    Total  number  of  kilobytes the system paged in from disk per second

  pgpgout/s
    Total number of kilobytes the system paged out to disk per second

  fault/s
    Number  of  page faults (major + minor) made by the system per second
    This is not a count of page faults that  genderate  I/O, because some 
    page faults can be resolved without I/O.

  majflt/s
    Number of major faults the system has made per second -
    those which have required loading a memory page from disk

  pgfree/s
    Number  of pages placed on the free list by the system per second

  pgscank/s
    Number of pages scanned by the kswapd daemon per second

  pgscand/s
    Number of pages scanned directly per second

  pgsteal/s
    Number of pages the system has reclaimed from cache (pageā€cache and
    swapcache) per second to satisfy its memory demands

  %vmeff
    Calculated as pgsteal/pgscan, this is a metric of the efficiency of 
    page reclaim.  If it is near 100% then almost every page coming off the 
    tail of the inactive list is being reaped.  If it gets too low
    (e.g. less than 30%) then the virtual memory is having some difficulty.
    This  field is  displayed as zero if no pages have been scanned during
    the interval of time.

Example:
  prompt> sar -B
  Linux 3.5.4-1.fc17.i686 (franco.cinci.rr.com)   09/28/2012      _i686_  (2 CPU)
  04:40:01 AM  pgpgin/s pgpgout/s   fault/s  majflt/s  pgfree/s pgscank/s pgscand/s pgsteal/s    %vmeff
  04:50:01 AM     45.19     97.10   1114.98      0.20   1443.46      0.00      0.00      0.00      0.00
  04:30:01 PM      2.66      0.43      6.97      0.00      7.39      0.00      0.00      0.00      0.00
  ...
  Average:     99617.29     52.78    128.41  99664.09    277.42  99649.53  99663.27  99651.60    100.00
 
slabtop     - Report kernel slab cache information in real time

Example:
  prompt> sudo slabtop
   Active / Total Objects (% used)    : 576525 / 625799 (92.1%)
   Active / Total Slabs (% used)      : 23951 / 23951 (100.0%)
   Active / Total Caches (% used)     : 76 / 98 (77.6%)
   Active / Total Size (% used)       : 140806.48K / 145678.38K (96.7%)
   Minimum / Average / Maximum Object : 0.01K / 0.23K / 8.00K

    OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME
  170336 169269  99%    0.12K   5323       32     21292K dentry
  162058 161598  99%    0.58K  12466       13     99728K ext4_inode_cache
  103003  74646  72%    0.05K   1411       73      5644K buffer_head
   27200  21006  77%    0.02K    160      170       640K anon_vma_chain
  ...