NAS 壓測過程中發現記憶體佔用 99% (62.6G/63G),但 top 顯示單一進程 %MEM 僅 0.x%。本文實戰記錄如何用 vmstat -m、slabtop 定位到 xfs_inode/xfs_ili Slab 緩存佔用 10GB,並通過 drop_caches 釋放驗證。
# top -M
Mem: 63.050G total, 62.639G used, 420.973M free, 33.973M buffers
Swap: 4095.996M total, 0 used, 4095.996M free, 48.889G cached
# 進程列表無明顯大佔用進程 (最大 %MEM < 1%)

# vmstat -m | grep -E 'xfs_'
xfs_ili 7564110 8351947 224 17
xfs_inode 7564205 8484180 1024 4
...
發現 xfs_ili (inode log item) 與 xfs_inode 佔用極大。
# slabtop -s c | head
OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME
8480676 7565420 89% 1.00K 2120169 4 8480676K xfs_inode
8351794 7565375 90% 0.22K 491282 17 1965128K xfs_ili
xfs_inode:~8.5 GB (XFS inode 緩存)xfs_ili:~1.9 GB (XFS inode log item,日誌緩存)-l size=128m (日誌大小)xfs_ili 1965128 KB (吻合)top 顯示 cached 48.889G 印證
# 1. 同步髒頁到磁碟
sync
# 2. 釋放所有緩存 (Page Cache + Dentries + Inodes)
echo 3 > /proc/sys/vm/drop_caches
# 3. 觀察記憶體釋放
free -h
drop_caches值:1=Page Cache、2=Dentries/Inodes、3=全部。生產環境謹慎使用,會導致後續 I/O 延遲飆升。
| 方向 | 措施 |
|---|---|
| 記憶體規劃 | NFS 伺服器記憶體 ≥ 總日誌大小 + 預估活躍 inode 緩存 (卷數 × 日誌大小 × 1.5) |
| XFS 掛載優化 | noatime,nodiratime,logbsize=256k,inode64 減少元數據寫入 |
| 緩存壓力控制 | vm.vfs_cache_pressure=100 (預設) 可調高至 200-500 加速 inode/dentry 回收 |
| 監控告警 | 監控 slabinfo 中 xfs_inode/xfs_ili 增長趨勢,而非單純 MemAvailable |