MCPcopy Index your code
hub / github.com/diwic/shmem-ipc

github.com/diwic/shmem-ipc @v0.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.3.0 ↗ · + Follow
59 symbols 143 edges 7 files 24 documented · 41%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

crates.io API documentation license

Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux.

When is this Rust crate useful?

  • Performance or latency is crucial, and
  • you run Linux.

A typical use case could be audio/video streaming.

Don't need maximum performance and minimum latency, and want a higher level protocol with serialization and lots of bells and whistles built-in? Try D-Bus.

Also, a unix socket is easier to set up and is not that much slower (see benchmark below).

As for Linux, this crate uses memfd sealing to ensure safety between untrusted processes, and ringbuffer signaling is done using eventfd for best performance. These two features are Linux only.

Getting started

You probably want to start in the sharedring module, which sets up a ringbuffer between untrusted processes (it's a wait-free/lock-free, bounded, SPSC queue). Another useful function is mem::write_once for a scenario where you write data once and make it available for reading afterwards. The mem and ringbuf modules contain building blocks that might be useful in other use cases.

The downside of using memfd based shared memory is that you need to set it up by transferring file descriptors, using some other way of communication. Using D-Bus would be the standard way of doing that - it's also possible using unix sockets.

There is also a client/server example in the examples directory that can help you get started. Enjoy!

Benchmark

Sharedring vs unix sockets vs D-Bus Notice the log scale: for a 64K packet, sharedring is a three times faster than unix sockets, and 60 times faster than D-Bus. (D-Bus is a higher level protocol, so that comparison is to some degree comparing apples and oranges.)

License

The code is Apache 2.0 / MIT dual licensed. Any code submitted in Pull Requests, discussions or issues is assumed to have this license, unless explicitly stated otherwise.

Core symbols most depended-on inside this repo

send
called by 10
src/ringbuf.rs
recv
called by 10
src/ringbuf.rs
sum
called by 5
benches/sharedring1.rs
empty_signal
called by 5
src/sharedring.rs
full_signal
called by 5
src/sharedring.rs
load_count
called by 5
src/ringbuf.rs
count
called by 4
src/ringbuf.rs
memfd
called by 3
src/sharedring.rs

Shape

Method 25
Function 24
Class 8
Enum 2

Languages

Rust100%

Modules by API surface

src/sharedring.rs22 symbols
src/ringbuf.rs18 symbols
src/mem.rs8 symbols
benches/sharedring1.rs6 symbols
examples/server.rs3 symbols
src/lib.rs1 symbols
examples/client.rs1 symbols

For agents

$ claude mcp add shmem-ipc \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page