两种方法:
# top
top - 22:06:09 up 20 days, 42 min, 1 user, load average: 0.57, 0.65, 0.67
Tasks: 291 total, 1 running, 290 sleeping, 0 stopped, 0 zombie
Cpu(s): 3.4%us, 0.7%sy, 0.0%ni, 95.8%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 33012532k total, 27538556k used, 5473976k free, 498668k buffers
Swap: 33030140k total, 0k used, 33030140k free, 17477040k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
23293 oracle 20 0 15.4g 3.9g 50m S 49.0 12.4 13277:21 java
27013 oracle -2 0 9.9g 22m 20m S 3.3 0.1 954:57.23 ora_vktm_elctrl
23114 oracle 20 0 5374m 643m 6980 S 1.0 2.0 248:03.13 mysqld
26268 root 20 0 15204 1284 848 R 0.7 0.0 0:00.04 top
其中VIRT, RES, SHR列代表进程的内存使用情况,我们主要关注RES (resident)列,表示进程实际占用的物理内存(进程常驻内存)。关于他们的详细解释如下 :
VIRT
stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card’s RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.
RES
stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.
SHR
indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.
[root@host ~]# ps aux |grep 23293
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
oracle 23293 47.2 12.4 16147868 4094712 ? SLl Apr09 13276:53
/u01/app/oracle/java/bin/java -server -Xms512m -Xmx8192 ...
-Dweblogic.utils.cmm.lowertier.ServiceDisabled=true weblogic.Server
其中,RSS表示实际占用物理内存,根跟op的RES相同。VSZ表示使用的虚拟内存大小,根top的VIRT字段意思相同。
总结:以上图中java process为例,java的初始内存512M, 最大内存是8G,但是虚拟内存是15.4G, 实际使用内存只有3.9G。
可以使用iotop命令。
#iotop
Total DISK READ: 0.00 B/s | Total DISK WRITE: 807.16 K/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO COMMAND
23155 be/4 oracle 0.00 B/s 0.00 B/s 0.00 % 1.12 % mysqld --defaults-
802 be/4 root 0.00 B/s 0.00 B/s 0.00 % 1.03 % [kjournald]
1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % init
2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd]
3 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0]
6 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/0]
7 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [watchdog/0]
8 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/1]