johnnycrash
johnnycrash

Reputation: 5344

force attribute refresh in NFS

I don't know if I am asking this right, which is part of the problem. We use NFS on our linux boxes. We have mounts to directories on file servers. We use 1 hour attribute timeouts and 1 hour data timeouts. We have to models of writing files. 1) We add to the end of files. When adding to the end of files, we keep the same file name. 2) Changing previously written data. When changing a file, we change its file name. The idea is that this will work well With caching, because data that gets written to a file is never changed. I need one more thing to make this work. With the current settings, I get "bus error" when I access a newly added part of a file using mmap when that part of the file didnt exist at the time the attributes were cached. This all makes sense and is expected. What I would like to do is force NFS to refresh the file attributes so it knows that the file is larger now. In a perfect world, I would do this only when I got a bus error. So... is there a command I can execute from c or the shell that can do this?

EDIT I got down voted, so I guess my question is stupid. Maybe more information will help. When I use a mount that has a long attribute and data refresh, I get the microsecond performance I require. When I use a mount with a short attribute refresh, it becomes 1000x slower. I need the attribute refresh only when I get bus error. This is linux, so there is a good chance that a method exists to force this refresh. Our data only changes once every 20 minutes so I would like to explore the refresh on demand scenario.

Upvotes: 4

Views: 2421

Answers (1)

ArtemGr
ArtemGr

Reputation: 12547

NFS uses "Close-to-open cache consistency". According to the manual (man nfs), "When an application opens a file stored on an NFS server, the NFS client checks that it still exists on the server and is permitted to the opener by sending a GETATTR or ACCESS request".

According to A8 of the FAQ, "Linux implements close-to-open cache consistency by comparing the results of a GETATTR operation done just after the file is closed to the results of a GETATTR operation done when the file is next opened. If the results are the same, the client will assume its data cache is still valid; otherwise, the cache is purged."

I think you should close and reopen (and then re-mmap) the file when you get the "bus error".

P.S. Good question, by the way.

Upvotes: 1

Related Questions