Sunday, April 6, 2014

TOP explained

Very often when I look at linux command top I found difficult to fully understand the result. So following should remind me whats going on there.

top - 20:04:34 up 157 days, 17:22,  1 user,  load average: 2.52, 2.11, 1.23
Tasks: 102 total,   1 running, 101 sleeping,   0 stopped,   0 zombie
Cpu(s): 71.4%us,  0.2%sy,  0.0%ni, 28.3%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1018236k total,  1002152k used,    16084k free,    13600k buffers
Swap:  2064344k total,  1022604k used,  1041740k free,   183736k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                           
11025 honza     18   0  908m 596m 7292 S 285.9 60.0   2129:53 java                                                                                                                              
    1 root      15   0  2160  228  204 S  0.0  0.0   0:22.88 init                                                                                                                               
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:03.42 migration/0                                                                                                                        
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.03 ksoftirqd/0                                                                                                                        
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0         

I'll describe just part that made me a problem.

Cpu(s) abbreviations

  • us: user cpu time (or) % CPU time spent in user space
  • sy: system cpu time (or) % CPU time spent in kernel space
  • ni: user nice cpu time (or) % CPU time spent on low priority processes
  • id: idle cpu time (or) % CPU time spent idle
  • wa: io wait cpu time (or) % CPU time spent in wait (on disk)
  • hi: hardware irq (or) % CPU time spent servicing/handling hardware interrupts
  • si: software irq (or) % CPU time spent servicing/handling software interrupts
  • st: steal time - - % CPU time in involuntary wait by virtual cpu while hypervisor

Column names

Column names abbreviations:
  • PID -- Process Id The task's unique process ID, which periodically wraps, though never restarting at zero.
  • PR -- Priority The priority of the task.
  • NI -- Nice value The nice value of the task. A negative nice value means higher priority, whereas a positive nice value means lower priority. Zero in this field simply means priority will not be adjusted in determining a task's dispatchability.
  • P -- Last used CPU (SMP) A number representing the last used processor. In a true SMP environment this will likely change frequently since the kernel intentionally uses weak affinity. Also, the very act of running top may break this weak affinity and cause more processes to change CPUs more often (because of the extra demand for cpu time).
  • %CPU -- CPU usage The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if 'Irix mode' is Off, top will operate in 'Solaris mode' where a task's cpu usage will be divided by the total number of CPUs. You toggle 'Irix/Solaris' modes with the 'I' inter- active command.
  • TIME -- CPU Time Total CPU time the task has used since it started. When 'Cumulative mode' is On, each process is listed with the cpu time that it and its dead children has used. You toggle 'Cumulative mode' with 'S', which is a command-line option and an interactive command. See the 'S' interactive command for additional information regarding this mode.
  • TIME+ -- CPU Time, hundredths The same as 'TIME', but reflecting more granularity through hundredths of a second.
  • %MEM -- Memory usage (RES) A task's currently used share of available physical memory.
  • VIRT -- Virtual Image (kb) The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out. (Note: you can define the STATSIZE=1 environment variable and the VIRT will be calculated from the /proc/#/state VmSize field.) VIRT = SWAP + RES.
  • SWAP -- Swapped size (kb) The swapped out portion of a task's total virtual memory image.
  • RES -- Resident size (kb) The non-swapped physical memory a task has used. RES = CODE + DATA.
  • CODE -- Code size (kb) The amount of physical memory devoted to executable code, also known as the 'text resident set' size or TRS.
  • DATA -- Data+Stack size (kb) The amount of physical memory devoted to other than executable code, also known as the 'data resident set' size or DRS.
  • SHR -- Shared Mem size (kb) The amount of shared memory used by a task. It simply reflects memory that could be potentially shared with other processes.
  • nFLT -- Page Fault count The number of major page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that is not currently present in its address space. A major page fault is when disk access is involved in making that page available.
  • nDRT -- Dirty Pages count The number of pages that have been modified since they were last written to disk. Dirty pages must be written to disk before the corresponding physical memory location can be used for some other virtual page.
  • S -- Process Status The status of the task which can be one of:
    • 'D' = uninterruptible sleep
    • 'R' = running
    • 'S' = sleeping
    • 'T' = traced or stopped
    • 'Z' = zombie