Linux – lose files if I flush the cache (echo 3> /proc/sys/vm/drop_caches)

linux

I'm seeing file losses just after running sync; echo 3> /proc/sys/vm/drop_caches.

I'm not sure if this is the case, but as the filesystem is over NFS, maybe when I drop the caches, the file cache is gone too.

Can droping the caches using sync; echo 3 > /proc/sys/vm/drop_caches lead to file losses?

Best Answer

You shouldn't lose files if the kernel is working properly. From 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.

As the manual states, only clean caches are flushed and writing anything to drop_caches is a nondestructive operation. Dirty objects aren't disturbed at all.