如何清除NFS属性缓存?

6
我需要找到一种方法来清除客户端上的NFS属性缓存。stat() 调用从属性缓存读取 ctime 而不是实际值,需要最多 3 秒才能在缓存中反映出实际值。使用挂载时的 'noac' 选项可以解决问题,但长期以来会影响性能。
我发现像对文件进行 chown等操作的解决方案,但有没有在执行 stat() 前清除属性缓存的正确方法?而且这个问题只会发生在 Redhat Linux 上,而不是 FreeBSD。有人能解释一下吗?

你使用的是哪个Redhat版本?也许这是一个bug,最好报告一下。你可以在Redhat的Bugzilla上填写一个bug。 - Bin Wang
2个回答

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.

0

来自官方文档(http://www.citi.umich.edu/projects/nfs-perf/results/cel/dnlc.html):

请注意,只有open和fopen需要保证它们获取一个一致的句柄以便读写特定的文件。stat和相关函数不需要检索新属性,...

具有讽刺意味的是,Java的FileInputStream正在使用open,但不会触发属性刷新,但尝试写入会起到作用:new FileOutputStream(file).close()

Python: os.access(path, os.W_OK)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接