Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mmap file shared via nfs?

Scenario A:

To share a read/write block of memory between two processes running on the same host, Joe mmaps the same local file from both processes.

Scenario B:

To share a read/write block of memory between two processes running on two different hosts, Joe shares a file via nfs between the hosts, and then mmaps the shared file from both processes.

Has anyone tried Scenario B? What are the extra problems that arise in Scenario B that do not apply to Scenario A?.

like image 491
Andrew Tomazos Avatar asked Apr 28 '12 21:04

Andrew Tomazos


2 Answers

Mmap will not share data without some additional actions.

If you change data in mmaped part of file, changes will be stored only in memory. They will not be flushed to the filesystem (local or remote) until msync or munmap or close or even decision of OS kernel and its FS.

When using NFS, locking and storing of data will be slower than if using local FS. Timeouts of flushing and time of file operations will vary too.

On the sister site people says that NFS may have poor caching policy, so there will be much more I/O requests to the NFS server comparing I/O request count to local FS.

like image 109
osgx Avatar answered Sep 20 '22 09:09

osgx


You will need byte-range-lock for correct behavior. They are available in NFS >= v4.0.

like image 45
kofemann Avatar answered Sep 18 '22 09:09

kofemann