free命令中buff/cache是可回收的缓存内存,available才是真实可用内存;当available低时需排查内存问题,可通过htop、ps、vmstat等工具分析进程内存占用及系统内存行为。

说起在Linux系统里看内存用量,我个人觉得最省事、也最直观的,就是那个老伙计
free
当你需要在Linux系统里快速摸清内存状况时,
free
-h
敲下
free -h
total used free shared buff/cache available Mem: 15Gi 5.0Gi 3.0Gi 1.0Gi 7.0Gi 9.0Gi Swap: 2.0Gi 0.0Gi 2.0Gi
这里面,
total
used
buff/cache
free
重点来了,
shared
buff/cache
buff/cache
available
free
free
buff/cache
available
free
available
最后是
Swap
used
free
buff/cache
available
我发现很多刚接触Linux的朋友,一看
free
free
buff/cache
available
buff/cache
buff/cache
available
free
buff/cache
free
available
available
如果你通过
free -h
available
Swap
top
htop
htop
比如,我可能会先运行
htop
F6
MEM%
top
htop
ps aux --sort=-%mem
定位到具体进程后,下一步就是分析了。是正常负载导致的?还是程序bug?或者仅仅是缓存太多了?如果是缓存,可以尝试清理一下:
sync; echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
free
虽然
free
vmstat
vmstat 1
swpd
free
buff
cache
free
另外,
proc
cat /proc/meminfo
free
MemTotal
MemFree
Buffers
Cached
SwapTotal
SwapFree
/proc/meminfo
pmap -x <pid>
以上就是如何在Linux中查看内存使用情况?使用free命令检查内存占用状态的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号