Skip to main content

ZERO_COPY_THRESHOLD

Constant ZERO_COPY_THRESHOLD 

Source
pub const ZERO_COPY_THRESHOLD: usize = 4096;
Expand description

The data size threshold at which we start using shared memory.

Shared memory works by sharing memory pages. This means that the smallest memory region that can be shared is one memory page, which is typically 4KiB.

Using shared memory for messages smaller than the page size still requires sharing a full page, so we have some memory overhead. We also have some performance overhead because setting up a shared segment is not free. For small messages it is cheaper to copy them into a heap-buffered publish.

On the zenoh data plane this threshold selects how an output is published: payloads at or above it go through zenoh shared memory (zero-copy for local subscribers), while smaller payloads are published via zenoh with a heap-buffered put. A large payload that did not get a shared-memory buffer takes the reliable daemon path instead of the zenoh one, because a fragmented express publish would be silently dropped (dora-rs/dora#2366). See DoraNode::zero_copy_threshold for the runtime value (overridable via DORA_ZERO_COPY_THRESHOLD).