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 記憶體 Cache 深度分析:為何 Cache 佔用超過實體記憶體?

編輯:關於 Linux

Linux 核心會將近期存取的檔案資料暫存於頁面快取,導致 free -h 顯示的 Cache 價值遠大於實體記憶體。本文實測驗證 「編輯大型檔案會大幅增加 Cache」,並介紹 linux-ftools 工具組精確分析哪些檔案佔用快取。

編輯前 Cache 40MB

用 vi 開啟 110MB wildfly 封裝檔

linux-ftools 分析結果

實驗流程

  1. 觀察初始 Cache 約 40 MB。
  2. 用 vi 開啟 110 MB 的 wildfly-8.1.0.Final.tar.gz。
  3. Cache 瞬間飆升至接近檔案大小。
  4. 使用 linux-fincore 確認快取內容確為該檔案。

工具安裝與使用

# 1. 下載原始碼並修正換行符 (Windows CRLF -> LF)
# 2. 賦予執行權限並編譯
chmod 755 -R *
./configure
make && make install

# 3. 分析目前目錄下被快取的檔案
linux-fincore --pages=false --summarize --only-cached *

輸出解讀

filename                       size  total_pages  cached_pages  cached_size  cached_perc
wildfly-8.1.0.Final.tar.gz   115MB      28320           28320       115MB       100.00
total cached size: 115MB

結論:Linux 會將編輯器載入的檔案完整放入頁面快取,這屬正常行為。核心會在記憶體壓力大時自動回收快取,無需人為清理。若確需釋放,可參考《如何清理 Linux 中的 swap、buffer 及 cache》。

Copyright © Windows教程網 All Rights Reserved