如何刷新nfs属性缓存?

ram*_*mgo 6 linux caching nfsclient nfs stat

我需要找到一种方法来刷新客户端的NFS属性缓存.stat()调用从属性缓存中读取ctime而不是实际值,实际值最多需要3秒才能在缓存中反映出来.在安装工作时使用'noac'选项,但从长远来看会影响性能.

我遇到了解决方案,比如在文件的同一所有者上做了一个chown,但在执行stat()之前是否有适当的方法来刷新属性缓存?这个问题只发生在Redhat Linux而不是FreeBSD上.谁能解释一下?

jjj*_*jjj 3

这不是 NFS 特有的,但您可以让内核删除缓存。这通常在 IO 基准测试时完成,但也适用于 NFS。

https://www.kernel.org/doc/Documentation/sysctl/vm.txt

Writing to this will cause the kernel to drop clean caches, dentries and
inodes from memory, causing that memory to become free.

To free pagecache:
    echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
    echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
    echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation and dirty objects are not freeable, the
user should run `sync' first.
Run Code Online (Sandbox Code Playgroud)