justinstenning / SharedMemory

C# shared memory classes for sharing data between processes (Array, Buffer and Circular Buffer)
https://www.nuget.org/packages/SharedMemory
Other
566 stars 118 forks source link

Working on Linux? #40

Open clSharp opened 5 years ago

clSharp commented 5 years ago

Do SharedBuffers work in Linux? Anyone successfully used it? As far as I understand it's based on named MemoryMaps, which are not supported in. NET Core under Linux.

Is there any alternative for shared memory with. NET Core under Linux?

mkosina commented 5 years ago

Got SharedArray to work on Linux with the following patches:

I only use SharedArray on Linux, so did the latter on SharedArray level only (via a secondary MMF of ints, which had the added benefit of fine-grained, per-cell locking), but could probably be adapted to BufferWithLocks in general.

I'll try to pull this together as a patch if there is interest, need to it dig out. Overall great library, using parts of it in a demanding server app (market data feed handler) without any issues - SharedArray for in-memory cache on Linux and CircularBuffer on Windows consumers to isolate GC-intolerant high bandwidth multicast consumption from rest of the client apps.

mkosina commented 5 years ago

May want to also check out https://github.com/AdaptiveConsulting/Aeron.NET - Martin Thomspon of LMAX Disruptor fame is involved.

justinstenning commented 5 years ago

@mkosina I would be interested in looking at integrating support for Linux.

I’m not sure how I feel about spin locks, but if there is no alternative for Linux then fair enough.

Would you be able to prepare a pull request or point to a repo that has these changes?

Thanks

clSharp commented 5 years ago

@mkosina Can you share experiences on when Linux flushes those mappings to disc? Will it flush if I delete the file before closing the map? Will it behave like memory maps backed by the page file and not write dirty pages as long as there is enough memory?

I need more than 1GB/s of shared memory bandwith. Any IO from those mappings is a serious problem for me.

justinstenning commented 5 years ago

My short investigation into this so far has found that the .NET core implementation on Linux only supports shared memory backed by files. I believe there is a memory only option within Linux, however this will require a custom implementation to support it.

justinstenning commented 4 years ago

As a note: cross-process mutex's are supported on Linux/POSIX with "Global\" prefix in name