I am planning to use NFS to serve out many small files. They will be read very often so client side caching is crucial. Does NFS handle this? Is there a way to increase the client side caching in some way?

...or should I look at another solution? Syncing using rsync or unison periodically is not an option since the files are modified on the client side from time to time.

1 Answer 1


First, NFS does not provide cache coherency, so if you need that, you must look elsewhere.

What NFS specifies is a weaker model called close-to-open consistency. Meaning that when a file is closed, any dirty data are flushed to the server. Conversely, when a file is opened, an attribute check is performed, meaning that if the client has cached pages from that file, it checks whether those pages are still valid.

While not in the spec itself, most NFS clients have something called attribute cache timeout, i.e. how old the attributes of a directory or opened file can be before the client contacts the server to revalidate them. On Linux, see the actimeo= etc. mount options. Higher values allow more aggressive caching, but increase the risk of using stale data if some other client updated the file in the meantime.

  • Thank you for your reply. So, just so that I've understood this correctly, the client side "attribute cache" only contains a cache for file/dir-attributes ie. the cache doesn't contain any file content?
    – Ztyx
    Apr 8, 2010 at 7:26
  • 1
    Yes, the client caches file content in the page cache, just like it does for a local filesystem. The attributes are used to decide if and when the cached file contents are invalidated.
    – janneb
    Apr 8, 2010 at 10:35
  • Ah. Thank you so much for answering this. Have a nice day.
    – Ztyx
    Apr 8, 2010 at 13:42
  • When you say "page" it seems to mean that parts of the file can be cached and parts of the file may not be? It's not a file cache is it? It's subdivisions of the file that can be cached. Nov 16, 2018 at 4:09
  • 1
    @CMCDragonkai: The kernel keeps track of cached file contents at page granularity (typically 4KB), so yes, it can cache part of a file. I'm not sure how exactly the cache invalidation works for NFS, my guess would be that after the attribute cache timeout when it contacts the server to revalidate, and if the revalidation fails, then it drops all cached pages belonging to that file.
    – janneb
    Nov 16, 2018 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.