问题
I need to find a way to flush the NFS attribute cache on the client side. stat() call reads ctime from attribute cache and not the actual value, takes upto 3 second for the actual value to be reflected in cache. using 'noac' option when mounting works but will affect performance in the long run.
I came across solutions like doing a chown on the same owner of the file etc. but is there a proper method to flush the attribute cache before doing a stat()? and this prob happens only on Redhat Linux and not FreeBSD. Can anyone explain?
回答1:
This isn't specific to NFS, but you can have the kernel drop caches. This is usually done when IO benchmarking, but works for NFS too.
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.
来源:https://stackoverflow.com/questions/13946852/how-to-flush-nfs-attribute-cache