Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flush nfs attribute cache?

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?

like image 999
ramgo Avatar asked Dec 19 '12 06:12

ramgo


1 Answers

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.
like image 147
jjj Avatar answered Sep 28 '22 03:09

jjj