Crate rapace_transport_shm

Crate rapace_transport_shm 

Source
Expand description

rapace-transport-shm: Shared memory transport for rapace.

This is the performance reference implementation. It defines the canonical memory layout and zero-copy patterns.

§Characteristics

  • SPSC rings for descriptors
  • Slab allocator for payloads
  • Zero-copy when data is already in SHM
  • eventfd doorbells for async notification (future)
  • Generation counters for crash safety

§Architecture

Each SHM segment represents a session between exactly two peers (A and B). The design is intentionally SPSC (single-producer, single-consumer) per ring.

┌─────────────────────────────────────────────────────────────────────┐
│  Segment Header (64 bytes)                                           │
├─────────────────────────────────────────────────────────────────────┤
│  A→B Descriptor Ring                                                 │
├─────────────────────────────────────────────────────────────────────┤
│  B→A Descriptor Ring                                                 │
├─────────────────────────────────────────────────────────────────────┤
│  Data Segment (slab allocator)                                       │
└─────────────────────────────────────────────────────────────────────┘

§Optional: SHM Allocator

Enable the allocator feature to get [ShmAllocator], which allows allocating data directly into SHM slots. When such data is passed through the encoder, it’s detected as already in SHM and referenced zero-copy (no memcpy).

[dependencies]
rapace-transport-shm = { version = "0.1", features = ["allocator"] }

Important: This is an optional optimization. Service traits remain transport-agnostic—they don’t know or care whether data is in SHM. The allocator is for callers who want to pre-allocate in SHM for performance.

Re-exports§

pub use layout::DEFAULT_RING_CAPACITY;
pub use layout::DEFAULT_SLOT_COUNT;
pub use layout::DEFAULT_SLOT_SIZE;
pub use layout::DataSegment;
pub use layout::DataSegmentHeader;
pub use layout::DescRing;
pub use layout::DescRingHeader;
pub use layout::LayoutError;
pub use layout::RingError;
pub use layout::RingStatus;
pub use layout::SegmentHeader;
pub use layout::SegmentOffsets;
pub use layout::SlotError;
pub use layout::SlotMeta;
pub use layout::SlotState;
pub use layout::calculate_segment_size;
pub use doorbell::Doorbell;
pub use doorbell::close_peer_fd;
pub use hub_alloc::HubAllocator;
pub use hub_alloc::HubSlotStatus;
pub use hub_alloc::SizeClassStatus;
pub use hub_layout::ExtentHeader;
pub use hub_layout::HUB_SIZE_CLASSES;
pub use hub_layout::HubHeader;
pub use hub_layout::HubOffsets;
pub use hub_layout::HubSlotError;
pub use hub_layout::HubSlotMeta;
pub use hub_layout::PeerEntry;
pub use hub_layout::SizeClassHeader;
pub use hub_layout::decode_slot_ref;
pub use hub_layout::encode_slot_ref;
pub use hub_session::HubConfig;
pub use hub_session::HubHost;
pub use hub_session::HubPeer;
pub use hub_session::PeerInfo;
pub use hub_transport::HostPeerHandle;
pub use hub_transport::HubHostPeerTransport;
pub use hub_transport::HubHostTransport;
pub use hub_transport::HubPeerTransport;
pub use hub_transport::HubTransportError;
pub use hub_transport::INLINE_PAYLOAD_SIZE;
pub use hub_transport::INLINE_PAYLOAD_SLOT;

Modules§

doorbell
Socketpair doorbell for cross-process wakeup.
futex
Futex operations for cross-process signaling.
hub_alloc
Hub allocator: Per-class Treiber stack allocator with extent management.
hub_layout
Hub SHM memory layout definitions.
hub_session
Hub session management.
hub_transport
Hub transport implementation.
layout
SHM memory layout definitions.

Structs§

ShmMetrics
Metrics for tracking zero-copy performance and slot allocation.
ShmSession
A shared memory session between two peers.
ShmSessionConfig
Configuration for creating an SHM session.
ShmTransport
SHM transport implementation.