如果刷新缓存(echo 3> /proc/sys/vm/drop_caches),我会丢失文件吗?

如果刷新缓存(echo 3> /proc/sys/vm/drop_caches),我会丢失文件吗?

我在运行后发现文件丢失sync; echo 3> /proc/sys/vm/drop_caches

我不确定情况是否如此,但由于文件系统是通过 NFS 传输的,也许当我删除缓存时,文件缓存也会消失。

使用删除缓存会sync; echo 3 > /proc/sys/vm/drop_caches导致文件丢失吗?

答案1

如果内核工作正常,您不应该丢失文件。从man 5 proc

/proc/sys/vm/drop_caches (since Linux 2.6.16)
       Writing  to  this  file  causes the kernel to drop clean caches,
       dentries, and inodes from memory, causing that memory to  become
       free ...
...
       Because writing to this file is a nondestructive  operation  and
       dirty  objects  are  not  freeable,  the user should run sync(1)
       first.

正如手册所述,只有干净的缓存才会被刷新,并且写入任何内容drop_caches都是非破坏性操作。脏东西根本不会受到干扰。

相关内容