Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3f60cf5
WIP on SHM handoff
yellowhatter Jun 16, 2026
95572d5
Re-engineer establishment procedure for new SHM counter segment excha…
yellowhatter Jun 30, 2026
7844283
Merge commit '55263c9da5841cc620ba8d9e41f8a8965a35978a'
yellowhatter Jun 30, 2026
7e84648
Shm handoff: format, clippy, code reorg
yellowhatter Jun 30, 2026
3b34960
Update mod.rs
yellowhatter Jun 30, 2026
135095b
Merge commit '5dd1a2f764b28a70ce6f12801e1d4dca2321bbc2'
yellowhatter Jun 30, 2026
d3da6f2
[skip ci] Big WIP on SHM Handoff
yellowhatter Jul 14, 2026
c229da3
Working handoff
yellowhatter Jul 20, 2026
8f8cdbf
Merge commit 'ecbfcfbe5e442ca8234b631576712e6d1c8b1ef9'
yellowhatter Jul 20, 2026
796d9c1
fix clippy
yellowhatter Jul 20, 2026
8c3c84e
fix compilation
yellowhatter Jul 20, 2026
43d4ed2
Test for SHM handoff
yellowhatter Jul 21, 2026
3c49106
Fix few issues
yellowhatter Jul 21, 2026
3a5d835
Fix lints
yellowhatter Jul 21, 2026
5f0ef1e
Clippy fix
yellowhatter Jul 23, 2026
7639f47
Merge commit '3298eee947e63ac4e319f8454dc58d91a48264cf'
yellowhatter Jul 27, 2026
6d995a8
fix compilation with shm
yellowhatter Jul 27, 2026
13426b5
Fix SHM Handoff concurrency issue
yellowhatter Jul 28, 2026
5e44daf
fix tests and clippy
yellowhatter Jul 28, 2026
9f22afb
fix compilation issues
yellowhatter Jul 28, 2026
80dc3b5
Update Cargo.lock and Cargo.toml
yellowhatter Jul 28, 2026
b8f01d3
Update Cargo.toml and Cargo.toml
yellowhatter Jul 28, 2026
bf5eca6
Cargo fmt
yellowhatter Jul 30, 2026
763f721
- make handoff reclamation task process-global
yellowhatter Aug 3, 2026
9885fb8
Merge commit '2b17838f9da73705a9d7d070b61fd2647654ae4c'
yellowhatter Aug 3, 2026
96dc67b
- use better container for handoff counter leases
yellowhatter Aug 3, 2026
f938555
Do not print out huge array on debug
yellowhatter Aug 3, 2026
9672773
Typo fix
yellowhatter Aug 3, 2026
2814b9c
Merge commit 'ad5e077a80841f4fa7f6cb7eb7b13fa509a17784'
yellowhatter Aug 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ lazy_static = "1.5.0"
leb128 = "0.2"
libc = "0.2.175"
libloading = "0.8.9"
lockfree = "0.5"
lru = "0.16.2"
lz4_flex = "0.10.0"
mime = "0.3.17"
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ shared-memory = [
std = ["tracing", "uhlc/std", "zenoh-buffers/std", "zenoh-protocol/std"]

[dependencies]
rand = { workspace = true }
tracing = { workspace = true, optional = true }
uhlc = { workspace = true }
zenoh-buffers = { workspace = true, default-features = false }
Expand All @@ -48,7 +49,6 @@ zenoh-shm = { workspace = true, optional = true }
# INFO: May cause problems when testing no_std stuff. Check this tool: https://docs.rs/crate/cargo-no-dev-deps/0.1.0
[dev-dependencies]
criterion = { workspace = true }

rand = { workspace = true, features = ["default"] }
zenoh-protocol = { workspace = true, features = ["test"] }
zenoh-util = { workspace = true }
Expand Down
64 changes: 63 additions & 1 deletion commons/zenoh-codec/src/core/shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ use zenoh_buffers::{
writer::{DidntWrite, Writer},
};
use zenoh_shm::{
api::provider::chunk::ChunkDescriptor, metadata::descriptor::MetadataDescriptor, ShmBufInfo,
api::provider::chunk::ChunkDescriptor,
metadata::descriptor::MetadataDescriptor,
posix_shm::{segment::Segment, struct_in_shm::StructInSHM},
shm::SegmentID,
ShmBufInfo,
};

use crate::{RCodec, WCodec, Zenoh080};
Expand Down Expand Up @@ -143,3 +147,61 @@ where
Ok(shm_info)
}
}

impl<'a, W, ID> WCodec<&'a Segment<ID>, &'a mut W> for Zenoh080
where
W: Writer,
ID: SegmentID,
rand::distributions::Standard: rand::distributions::Distribution<ID>,
Zenoh080: WCodec<ID, &'a mut W>,
{
type Output = <Zenoh080 as WCodec<ID, &'a mut W>>::Output;

fn write(self, writer: &'a mut W, x: &Segment<ID>) -> Self::Output {
self.write(&mut *writer, x.id())
}
}

impl<'a, R, ID> RCodec<Segment<ID>, &'a mut R> for Zenoh080
where
R: Reader,
ID: SegmentID,
rand::distributions::Standard: rand::distributions::Distribution<ID>,
Zenoh080: RCodec<ID, &'a mut R>,
{
type Error = DidntRead;

fn read(self, reader: &'a mut R) -> Result<Segment<ID>, Self::Error> {
let id = self.read(&mut *reader).map_err(|_| DidntRead)?;
Segment::open(id).map_err(|_| DidntRead)
}
}

impl<'a, W, ID, Elem> WCodec<&'a StructInSHM<ID, Elem>, &'a mut W> for Zenoh080
where
W: Writer,
ID: SegmentID,
rand::distributions::Standard: rand::distributions::Distribution<ID>,
Zenoh080: WCodec<ID, &'a mut W>,
{
type Output = <Zenoh080 as WCodec<ID, &'a mut W>>::Output;

fn write(self, writer: &'a mut W, x: &StructInSHM<ID, Elem>) -> Self::Output {
self.write(&mut *writer, x.id())
}
}

impl<'a, R, ID, Elem> RCodec<StructInSHM<ID, Elem>, &'a mut R> for Zenoh080
where
R: Reader,
ID: SegmentID,
rand::distributions::Standard: rand::distributions::Distribution<ID>,
Zenoh080: RCodec<ID, &'a mut R>,
{
type Error = DidntRead;

fn read(self, reader: &'a mut R) -> Result<StructInSHM<ID, Elem>, Self::Error> {
let id = self.read(&mut *reader).map_err(|_| DidntRead)?;
StructInSHM::open(id).map_err(|_| DidntRead)
}
}
6 changes: 3 additions & 3 deletions commons/zenoh-protocol/src/transport/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub mod ext {
/// # Shm extension
/// Used as challenge for probing shared memory capabilities
#[cfg(feature = "shared-memory")]
pub type Shm = zextz64!(0x2, false);
pub type Shm = zextzbuf!(0x2, false);

/// # Auth extension
/// Used as challenge for probing authentication rights
Expand Down Expand Up @@ -155,7 +155,7 @@ impl OpenSyn {
let cookie = ZSlice::rand(rng.gen_range(MIN..=MAX));
let ext_qos = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
#[cfg(feature = "shared-memory")]
let ext_shm = rng.gen_bool(0.5).then_some(ZExtZ64::rand());
let ext_shm = rng.gen_bool(0.5).then_some(ZExtZBuf::rand());
let ext_auth = rng.gen_bool(0.5).then_some(ZExtZBuf::rand());
let ext_mlink = rng.gen_bool(0.5).then_some(ZExtZBuf::rand());
let ext_lowlatency = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
Expand Down Expand Up @@ -219,7 +219,7 @@ impl OpenAck {
let initial_sn: TransportSn = rng.gen();
let ext_qos = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
#[cfg(feature = "shared-memory")]
let ext_shm = rng.gen_bool(0.5).then_some(ZExtZ64::rand());
let ext_shm = rng.gen_bool(0.5).then_some(ZExtZBuf::rand());
let ext_auth = rng.gen_bool(0.5).then_some(ZExtZBuf::rand());
let ext_mlink = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
let ext_lowlatency = rng.gen_bool(0.5).then_some(ZExtUnit::rand());
Expand Down
33 changes: 32 additions & 1 deletion commons/zenoh-shm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ pub mod init;
pub mod metadata;
pub mod posix_shm;
pub mod reader;
pub mod shm;
pub mod version;
pub mod watchdog;
tested_crate_module!(shm);

/// Information about a [`ShmBufInner`].
///
Expand Down Expand Up @@ -95,6 +95,37 @@ impl ShmBufInfo {
}
}

/// A hard shared reference to SHM buffer
#[derive(Debug, Clone)]
#[allow(unused)]
pub struct ShmBufHardRef(ConfirmedDescriptor);

impl From<&ShmBufInner> for ShmBufHardRef {
fn from(value: &ShmBufInner) -> Self {
Self(value.metadata.clone())
}
}
impl From<&ZShm> for ShmBufHardRef {
fn from(value: &ZShm) -> Self {
(&value.inner).into()
}
}
impl From<&zshm> for ShmBufHardRef {
fn from(value: &zshm) -> Self {
(&value.inner).into()
}
}
impl From<&ZShmMut> for ShmBufHardRef {
fn from(value: &ZShmMut) -> Self {
(&value.inner).into()
}
}
impl From<&zshmmut> for ShmBufHardRef {
fn from(value: &zshmmut) -> Self {
(&value.inner).into()
}
}

/// A zenoh buffer in shared memory.
pub struct ShmBufInner {
pub(crate) metadata: ConfirmedDescriptor,
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-shm/src/metadata/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl OwnedWatchdog {
pub struct OwnedMetadataDescriptor {
pub(crate) segment: Arc<MetadataSegment>,
header: &'static ChunkHeaderType,
watchdog: OwnedWatchdog,
pub(crate) watchdog: OwnedWatchdog,
}

impl Hash for OwnedMetadataDescriptor {
Expand Down
4 changes: 2 additions & 2 deletions commons/zenoh-shm/src/posix_shm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
//

pub mod array;
pub mod struct_in_shm;
tested_crate_module!(segment);
pub(crate) mod cleanup;
pub mod segment;
pub mod struct_in_shm;
1 change: 1 addition & 0 deletions commons/zenoh-shm/src/posix_shm/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{cleanup::CLEANUP, shm};
const SEGMENT_DEDICATE_TRIES: usize = 100;

/// Segment of shared memory identified by an ID
#[derive(PartialEq, Eq)]
pub struct Segment<ID>
where
rand::distributions::Standard: rand::distributions::Distribution<ID>,
Expand Down
17 changes: 17 additions & 0 deletions commons/zenoh-shm/src/posix_shm/struct_in_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ where
_phantom: PhantomData<Elem>,
}

impl<ID, Elem: Sync> PartialEq for StructInSHM<ID, Elem>
where
rand::distributions::Standard: rand::distributions::Distribution<ID>,
ID: shm::SegmentID,
{
fn eq(&self, other: &Self) -> bool {
self.inner == other.inner
}
}

impl<ID, Elem: Sync> Eq for StructInSHM<ID, Elem>
where
rand::distributions::Standard: rand::distributions::Distribution<ID>,
ID: shm::SegmentID,
{
}

unsafe impl<ID, Elem: Sync> Sync for StructInSHM<ID, Elem>
where
rand::distributions::Standard: rand::distributions::Distribution<ID>,
Expand Down
8 changes: 8 additions & 0 deletions commons/zenoh-shm/src/shm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ pub struct Segment<ID: SegmentID> {
inner: platform::SegmentImpl<ID>,
}

impl<ID: SegmentID> Eq for Segment<ID> {}

impl<ID: SegmentID> PartialEq for Segment<ID> {
fn eq(&self, other: &Self) -> bool {
self.inner.id() == other.inner.id()
}
}

impl<ID: SegmentID> std::fmt::Debug for Segment<ID> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("Segment").field(&self.inner).finish()
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-shm/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

pub const SHM_VERSION: u64 = 1;
pub const SHM_VERSION: u64 = 2;
13 changes: 7 additions & 6 deletions commons/zenoh-shm/src/watchdog/confirmator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ pub struct ConfirmedDescriptor {

impl Clone for ConfirmedDescriptor {
fn clone(&self) -> Self {
// NOTE: need `ConfirmedDescriptor::new` to add the descriptor to the confirmed segment
ConfirmedDescriptor::new(self.owned.clone(), self.confirmed.clone())
}
}

impl Drop for ConfirmedDescriptor {
fn drop(&mut self) {
self.confirmed.remove(self.owned.clone());
self.confirmed.remove(self.owned.deref().clone());
}
}

impl ConfirmedDescriptor {
fn new(owned: OwnedMetadataDescriptor, confirmed: Arc<ConfirmedSegment>) -> Self {
confirmed.add(owned.clone());
confirmed.add(owned.deref().clone());
Self { owned, confirmed }
}
}
Expand Down Expand Up @@ -99,12 +100,12 @@ impl ConfirmedSegment {
}
}

fn add(&self, descriptor: OwnedMetadataDescriptor) {
self.make_transaction(Transaction::Add(descriptor.deref().clone()));
fn add(&self, descriptor: OwnedWatchdog) {
self.make_transaction(Transaction::Add(descriptor));
}

fn remove(&self, descriptor: OwnedMetadataDescriptor) {
self.make_transaction(Transaction::Remove(descriptor.deref().clone()));
fn remove(&self, descriptor: OwnedWatchdog) {
self.make_transaction(Transaction::Remove(descriptor));
}

fn make_transaction(&self, transaction: Transaction) {
Expand Down
4 changes: 4 additions & 0 deletions io/zenoh-transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ auth_pubkey = ["rsa", "transport_auth"]
auth_usrpwd = ["transport_auth"]
default = ["test", "transport_multilink"]
shared-memory = [
"lockfree",
"static_init",
"zenoh-buffers/shared-memory",
"zenoh-codec/shared-memory",
"zenoh-protocol/shared-memory",
Expand Down Expand Up @@ -59,12 +61,14 @@ crossbeam-utils = { workspace = true }
flume = { workspace = true }
futures = { workspace = true }
lazy_static = { workspace = true }
lockfree = { workspace = true, optional = true }
lz4_flex = { workspace = true }
rand = { workspace = true, features = ["default"] }
ringbuffer-spsc = { workspace = true }
rsa = { workspace = true, optional = true }
serde = { workspace = true, features = ["default"] }
sha3 = { workspace = true }
static_init = { workspace = true, optional = true }
tokio = { workspace = true, features = [
"fs",
"io-util",
Expand Down
2 changes: 2 additions & 0 deletions io/zenoh-transport/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ pub(crate) mod defragmentation;
pub(crate) mod pipeline;
pub(crate) mod priority;
pub(crate) mod seq_num;
#[cfg(feature = "shared-memory")]
pub mod shm;
Loading
Loading