memory usage (pmap, smem)

最後更新: 2015-03-04

目錄

  •  

說明

  • Vss = virtual set size               <--- Process 宣告用幾多 ram
  • Rss = resident set size            <--- 實際用幾多 ram (包含 library) [Unit: kbyte]
  • Pss = proportional set size      <--- library 平分後的 ram 用量
  • Uss = unique set size

Unshared memory is reported as the USS (Unique Set Size).

The unshared memory (USS) plus a process's proportion of shared memory is reported as the PSS (Proportional Set Size).

The USS and PSS only include physical memory usage.
(They do not include memory that has been swapped out to disk. )

 


smem -  Report memory usage

 

pull most of the data it needs from the /proc

Depends: python

opts:

#  This lets smem detect the amount of memory

-R REALMEM           # Example: -R 1024M

usage by X

  • -m, --mappings
  • -u, --users
  • -w, --system

FILTER BY

-P PROCESSFILTER

Show

  • -t                                                                                        # Show totals
  • -P regex                                                                              # Process filter regular expression
  • -k                                                                                       # Show unit suffixes
  • -n, --numeric                                                                       # Show numeric user IDs instead of usernames.
  • -s SORT, --sort=SORT                                                         # Field to sort on.
  • -r, --reverse                                                                        # Reverse sort.

FILES

  • /proc/$pid/cmdline
  • /proc/$pid/smaps
  • /proc/$pid/stat
  • /proc/meminfo
  • /proc/version

Example

smem

  PID User     Command                         Swap      USS      PSS      RSS
  300 root     /usr/sbin/courierlogger -pi       84        4       13      384
 2917 root     /sbin/getty 38400 console         76        4       14      456
 2918 root     /sbin/getty 38400 tty1            72        4       14      456
 2919 root     /sbin/getty 38400 tty2            72        4       14      456
 2920 root     /sbin/getty 38400 tty3            72        4       14      456
 2921 root     /sbin/getty 38400 tty4            72        4       14      456
............

# Filter by proccess name

smem -t -k -P [a]pache2

  PID User     Command                         Swap      USS      PSS      RSS
19705 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19706 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19707 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19708 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19709 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19710 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19711 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19712 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19713 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19714 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19715 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19716 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19717 root     /usr/sbin/apache2 -k start         0   124.0K   356.0K     6.5M
19718 root     /usr/sbin/apache2 -k start         0   124.0K   357.0K     6.5M
19719 root     /usr/sbin/apache2 -k start         0   124.0K   357.0K     6.5M
19704 root     /usr/sbin/apache2 -k start         0   128.0K   361.0K     6.5M
19735 root     /usr/sbin/apache2 -k start         0   124.0K   361.0K     6.5M
19701 root     /usr/sbin/apache2 -k start         0   232.0K   582.0K     7.2M
19702 root     /usr/sbin/apache2 -k start         0   232.0K   582.0K     7.2M
19693 root     /usr/sbin/apache2 -k start         0   992.0K     1.1M     4.0M
19700 root     /usr/sbin/apache2 -k start         0     2.1M     3.2M    11.0M
19688 root     /usr/sbin/apache2 -k start         0     4.8M     6.0M    14.4M
19703 root     /usr/sbin/apache2 -k start         0     6.3M     7.2M    14.4M
-------------------------------------------------------------------------------
   63 1                                           0    16.6M    24.6M   169.2M

# sort by swap & show pid

smem -s swap -t -k -n

-n, --numeric                    # Show numeric user IDs instead of usernames.

-s SORT, --sort=SORT      # Field to sort on.

# User 用幾多 memory

smem -u -k

-u, --users    # Report memory usage by user.

User     Count     Swap      USS      PSS      RSS
dovecot      1   144.0K     4.0K     4.0K    16.0K
nobody       1   188.0K     4.0K     4.0K    16.0K
policyd      1   588.0K     4.0K     4.0K    16.0K
rpcuser      1   404.0K     4.0K     4.0K    16.0K
opendkim     1   784.0K    28.0K    29.0K    68.0K
rpc          1   168.0K    72.0K    72.0K   100.0K
iredadmin     1     5.0M    40.0K   205.0K     1.6M
iredapd      1     2.1M   252.0K   281.0K   516.0K
amavis       3   166.2M   592.0K   633.0K   804.0K
vmail        4     1.4M   812.0K     1.3M     3.6M
postfix      3     1.1M     1.5M     1.9M     3.0M
apache       6    22.9M     3.9M     5.0M    13.6M
mysql        1    11.4M     9.5M     9.5M     9.8M
root        33    19.5M    16.1M    17.4M    24.6M
clamav       2   196.6M    80.0M    80.1M    80.8M

 

 


pmap

 

pmap - report memory map of a process

usage:

pmap 6703

ps aux

VSZ    virtual memory size of the process in KiB (1024-byte units)
RSS    resident set size, the non-swapped physical memory that a task has used
       (RSS 是包括共享存的"/lib/i386-linux-gnu/libpthread-2.15.so")

 

pmap -d 6703

-d   device         Show the device format.

................
mapped: 6008K    writeable/private: 936K    shared: 4K

writeable/private 才是真正用 RAM 數

    RSS: 保留內存的字節數(KB)
    Dirty: 髒頁的字節數(包括共享和私有的)(KB)
    Mode: read, write, execute, shared, private (寫時複製)
    Mapping:
        filename: 佔用內存的文件
        [anon](分配的內存)
        [stack](堆棧)
    Offset: 文件偏移
    Device: major:minor

 

 


memstat

 

pidof proccess_name       // Get pid

memstat -p <pid>

e.g.

    668k: PID  6702 (/usr/sbin/nginx)
      4k(      4k): [00:04]:697812347 6702
    600k(    560k): /usr/sbin/nginx 6702
    136k(    128k): /lib/ld-linux.so.2 6702
   1692k(   1676k): [fc:04]:131200 6702
     40k(     32k): [fc:04]:131203 6702
   1696k(   1608k): [fc:04]:131204 6702
     20k(     12k): [fc:04]:131206 6702
     96k(     88k): [fc:04]:131221 6702
     36k(     28k): [fc:04]:131222 6702
     52k(     44k): [fc:04]:131224 6702
     48k(     40k): [fc:04]:131226 6702
    240k(    232k): [fc:04]:131232 6702
    100k(     92k): [fc:04]:131235 6702
    344k(    316k): [fc:04]:131242 6702
     88k(     80k): [fc:04]:131250 6702
--------
   5860k (   4940k)

 

668k: PID  6702 (/usr/sbin/nginx)

amount of memory(does not include shared memory, text-segment is also not included), process ID, executable name

      4k(      4k): [00:04]:697812347 6702
    600k(    560k): /usr/sbin/nginx 6702
    136k(    128k): /lib/ld-linux.so.2 6702
   1692k(   1676k): [fc:04]:131200 6702
     40k(     32k): [fc:04]:131203 6702
   1696k(   1608k): [fc:04]:131204 6702
     20k(     12k): [fc:04]:131206 6702
     96k(     88k): [fc:04]:131221 6702
     36k(     28k): [fc:04]:131222 6702
     52k(     44k): [fc:04]:131224 6702
     48k(     40k): [fc:04]:131226 6702
    240k(    232k): [fc:04]:131232 6702
    100k(     92k): [fc:04]:131235 6702
    344k(    316k): [fc:04]:131242 6702
     88k(     80k): [fc:04]:131250 6702

total amount of memory allocated ( amount that is really shared is listed )

 

 

 

Creative Commons license icon Creative Commons license icon