6

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?

ramgo
  • 184
  • 1
  • 3
  • 10
  • 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 bugzilla](https://bugzilla.redhat.com/) – Bin Wang Jan 17 '13 at 06:34

2 Answers2

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.
jjj
  • 685
  • 1
  • 7
  • 14
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)

HeikoG
  • 591
  • 6
  • 10