在 Linux 中,“mount 缓存”并不是一个单一的机制,而是可能涉及 目录项缓存(dcache)、inode 缓存、文件系统缓存、NFS 属性缓存、mount 表缓存 等。下面按常见场景说明如何“清除”。
如果你是想释放内存中的文件/目录缓存:
# 释放 pagecache、dentries、inodes
sync
echo 3 > /proc/sys/vm/drop_caches
说明:
1:只清 pagecache2:清 dentries + inodes3:全部清除⚠️ 需要 root 权限,且只是释放内存缓存,不影响已挂载的文件系统。
如果是 NFS mount 看不到最新文件,通常是属性缓存导致:
mount -o remount /mnt/nfs
mount -o remount,noac /mnt/nfs
# 或
mount -o remount,actimeo=0 /mnt/nfs
ls -l /mnt/nfs
stat /mnt/nfs
mount
cat /proc/mounts
umount /mnt/xxx
mount /mnt/xxx
umount -l /mnt/xxx # 懒卸载
umount -f /mnt/xxx # 强制(NFS)
systemctl restart autofs
或:
automount -k
如果是 Docker 卷或 bind mount:
docker restart <container>
或重新创建容器。
mount -a
| 场景 | 做法 |
|---|---|
| 内存缓存 | echo 3 > /proc/sys/vm/drop_caches |
| NFS 看不到文件 | remount 或 noac |
| 挂载状态异常 | umount + mount |
| autofs | restart autofs |
| 容器 | 重启容器 |
如果你能说明:
我可以给你更精确的命令。