Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

正確理解 Linux 內存「佔用過高」:free 命令輸出深度解讀

編輯:Linux 教學

現象:top 顯示 4GB 物理內存已用 3.2GB(80%+),似乎內存不足。但實際運行負載很低,真相在 free -m 輸出中:

             total   used   free  shared buffers cached
Mem:          3798   3264    534      0     279   1518
-/+ buffers/cache:  1466   2332
Swap:         5983      0   5983

關鍵結論

  • 真正被進程佔用的內存 = used - (buffers + cached) = 3264 - (279+1518) = 1467 MB(對應第二行 -/+ buffers/cache 下的 used 1466)。
  • 可用內存 = free + buffers + cached = 534 + 279 + 1518 = 2331 MB(對應第二行 free 2332)。
  • Linux 內存管理哲學:「內存是拿來用的,不是拿來看的」。空閒內存會自動用作 buffers(塊設備緩存)和 cached(文件頁面緩存),提升 I/O 性能。當進程需要內存時,內核會自動回收緩存。
  • 判斷內存是否真不夠:觀察 Swap 使用量。若 Swap 長期佔用較大(如 >10%),才需考慮加內存;若 Swap 基本為 0,說明物理內存充足。

Buffers vs Cached

  • Buffers:針對磁盤塊的緩存(如文件系統元數據),加速 read/write/getdents 等系統調用。
  • Cached:針對文件 inode 內容的頁面緩存,加速文件讀寫。

二者均可快速釋放給進程使用,無需擔心。

Copyright © Windows教程網 All Rights Reserved