How does NFS read cache work on Debian?
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.
Solution 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.