How to flush nfs attribute cache?
Asked Answered
S

2

7

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?

Spain answered 19/12, 2012 at 6:39 Comment(1)
Which redhat version are you using? Maybe it is a bug and you'd better to report it. You could fill a bug on redhat's bugzillaPena
W
3

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.
Woaded answered 8/3, 2013 at 19:30 Comment(0)
T
0

From the official docs (http://www.citi.umich.edu/projects/nfs-perf/results/cel/dnlc.html):

Note that only open and fopen need to guarantee that they get a consistent handle to a particular file for reading and writing. stat and friends are not required to retrieve fresh attributes, ...

Ironically, Javas FileInputStream is using open, but does not trigger the attribute refresh, but attempting to write is doing the trick: new FileOutputStream(file).close()

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

Thermal answered 18/3, 2021 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.