Linux memory

  1. get top memory process

    1
    2
    # +3[CPU]
    ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head
  2. free

    1
    2
    3
    4
    5
    6
    7
    8
    free -m
    free -b -s5
    free -h

    total used free shared buffers cached
    Mem: 7.7G 7.6G 133M 164K 190M 3.1G
    -/+ buffers/cache: 4.2G 3.5G
    Swap: 0B 0B 0B

from the point of view of OS buffers and cached memory is used
available memory size = free + buffers + cached

  1. ps
    1
    2
    ps aux --sort -rss
    ps aux | grep xxx
  • USER process’ user
  • PID process id
  • %CPU cpu proportion
  • %MEM memory proportion
  • VSZ total VM size in kB
  • RSS resident set size
  • TTY terminal
  • STAT
    • R Running or runnable (on run queue)
    • S Interruptible sleep (waiting for an event to complete)
  • START time the command started
  • TIME run cpu time
  • COMMAND string as arguments
  1. /proc
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    cat /proc/pid/status

    VmPeak: 5033936 kB
    VmSize: 5033620 kB
    VmLck: 0 kB
    VmHWM: 1151928 kB
    VmRSS: 1151644 kB
    VmData: 4875980 kB
    VmStk: 88 kB
    VmExe: 36 kB
    VmLib: 127412 kB
    VmPTE: 2724 kB
    VmSwap: 0 kB
    Threads: 72
  • VmSize(KB) task’s virtual address space size (total_vm-reserved_vm)
  • VmLck(KB) been locked physical memory size, can’t exchange to hard drive(locked_vm)
  • VmRSS(KB) resident set size, physical memory. (rss in ps)
  • VmData(KB) program’s data paragraph size (virtual), store initialized data(total_vm-shared_vm-stack_vm)
  • VmStk(KB) task’s stack size in user(stack_vm)
  • VmExe(KB) executable virtual memory size, (exclude lib) (end_code-start_code)
  • VmLib(KB) lib mapping to task memory space size(exec_lib)
  • VmPTE(KB) this process’s page size
  • Threads share this signal’s task number(POSIX multi app, thread group use same signal)
  1. top
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # [shit+m sort by memory]
    top -p 6506

    top - 11:14:20 up 125 days, 1:47, 1 user, load average: 0.00, 0.00, 0.00
    Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
    Cpu(s): 0.2%us, 0.1%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
    Mem: 8061396k total, 7925220k used, 136176k free, 194748k buffers
    Swap: 0k total, 0k used, 0k free, 3291676k cached

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    3825 root 20 0 164m 41m 1020 S 0.0 0.5 146:54.42 redis-server

Cpu(s): 0.2%us, 0.1%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  • us user space cup proportion
  • sy system core space cup proportion
  • ni priority changed task cup proportion
  • id idle cpu proportion
  • wa waiting IO cpu proportion
  • hi hard ware cost
  • si soft ware cost
  • st steal time

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

  • PR priority rank
  • NI nice value
  • VIRT virtual memory size
  • RES not be exchanged memory size
  • SHR share meory size