介绍
在linux上跑程序时,常常遇到程序卡顿,内存消耗大,这时候,我们需要使用free
查看内存使用情况及top
内存消耗排行,当然,我们还可以继续使用一些其他的JVM监控命令如jstat
等命令进行java程序的性能评估。
free命令
free命令介绍
free
命令是显示系统内存的使用情况,一般包括了物理内存、交换内存以及内核缓冲区内存。
free命令使用
[linux@001]$ free --help
Usage:
free [options]
Options:
-b, --bytes show output in bytes
-k, --kilo show output in kilobytes
-m, --mega show output in megabytes
-g, --giga show output in gigabytes
--tera show output in terabytes
-h, --human show human-readable output
--si use powers of 1000 not 1024
-l, --lohi show detailed low and high memory statistics
-t, --total show total for RAM + swap
-s N, --seconds N repeat printing every N seconds
-c N, --count N repeat printing N times, then exit
-w, --wide wide output
--help display this help and exit
-V, --version output version information and exit
free命令示例
[linux@001]$ free -b
total used free shared buff/cache available
Mem: 16657858560 9096298496 5962731520 42442752 1598828544 7198982144
Swap: 0 0 0
[linux@001]$ free -k
total used free shared buff/cache available
Mem: 16267440 8884816 5821264 41448 1561360 7028544
Swap: 0 0 0
[linux@001]$ free -m
total used free shared buff/cache available
Mem: 15886 8757 5612 40 1516 6782
Swap: 0 0 0
[linux@001]$ free -g
total used free shared buff/cache available
Mem: 15 8 5 0 1 6
Swap: 0 0 0
[linux@001]$ free -h
total used free shared buff/cache available
Mem: 15G 8.6G 5.5G 40M 1.5G 6.6G
Swap: 0B 0B 0B
[linux@001]$ free -l -h
total used free shared buff/cache available
Mem: 15G 8.5G 5.6G 40M 1.5G 6.7G
Low: 15G 9G 5.6G
High: 0B 0B 0B
Swap: 0B 0B 0B
[linux@001]$ free -t -h
total used free shared buff/cache available
Mem: 15G 8.5G 5.6G 40M 1.5G 6.7G
Swap: 0B 0B 0B
Total: 15G 8.5G 5.6G
[linux@001]$ free -s 10
total used free shared buff/cache available
Mem: 16267440 8910116 5798884 41448 1558440 7003268
Swap: 0 0 0
total used free shared buff/cache available
Mem: 16267440 8912052 5796892 41448 1558496 7001336
Swap: 0 0 0
free命令的参数说明
Mem
:内存的使用情况。Swap
:交换空间的使用情况,是磁盘的一块区域,可以是swap分区也可以是swap文件,当系统物理内存使用比较紧张时,Linux会将内存中不常被访问的数据保存到Swap中,若需要访问该内容,会加载到内存中,即换出和换入的意思。total
:物理内存总数。used
:已使用内存大小。free
:可使用内存大小,即未被真正使用过的物理内存大小。shared
:多个进程可共享内存大小。buff/cache
:磁盘缓存大小。available
:可提供的内存大小,区别于free列,如果没有足够的free内存可用,会从buffer/cache回收内存来满足应用程序的需求,所以available=free+buffer+cache
。
top命令
top命令介绍
top
命令是用于监控Linux系统状况,可以通过该命令实时查看系统各个进程的资源占用状况。相当于Windows系统的任务管理器。
top命令使用
[linux@001]$ top -help
procps-ng version 3.3.10
Usage:
top -hv | -bcHiOSs -d