Reputation: 99
I'm trying to figure out how I might be able to work with shared memory between two Linux machines. Ideally, each machine has its own shared memory segment and is running two processes (one that reads from the machine's shared memory, and one that writes to the machine's shared memory). When one machine's shared memory gets written to or updated, I need the other machine to be notified and have its own shared memory sync up with the shared memory of the first machine.
Is this possible? How can I do this?
Thanks a million!
Upvotes: 1
Views: 2612
Reputation:
I'm trying to figure out how I might be able to work with shared memory between two Linux machines.
This is a bad idea. Synchronizing access to shared memory is difficult; you will have a hard time preventing multiple clients from interfering with each other, even on a single machine. Across multiple machines, the situation will only get worse.
If you really want to do this, you have essentially two options:
The simple way. Create a file to represent the shared memory and store it on a network file share. Use mmap()
to map it into memory on each machine. Make sure to use msync()
to flush changes to disk and invalidate cache.
The complicated way. Use an Infiniband link to connect the machines and perform remote memory access. Details of how you do this will depend on what Infiniband vendor you use.
That all being said, you will probably be much better off using another approach entirely. Details will depend on your application.
Upvotes: 4