feat: add template-level ivshmem opt-in#858
Open
zyl1121 wants to merge 1 commit into
Open
Conversation
Add a template option that lets users opt in to ivshmem support, and carry that setting through CubeAPI, CubeMaster, cubemastercli, and the Python SDK. Persist the opt-in as an internal CubeMaster annotation so CubeShim can attach a per-sandbox ivshmem backend file only for templates that requested it. During restore, retarget ivshmem devices that already exist in the snapshot to the new sandbox backend file, without adding ivshmem to snapshots that did not opt in. Add focused tests and public examples for mmap benchmarking and minimal host/guest ring-buffer communication. Signed-off-by: zhengyilei <zheng_yilei@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
CubeSandbox already uses vsock for host/guest communication. That remains a good default abstraction for command, control, and general streaming use cases.
For performance-sensitive data paths, a shared-memory backend can provide better throughput and latency characteristics than a socket stream.
ivshmemgives CubeSandbox a way to add that backend without changing the default communication path for existing templates.This PR exposes
ivshmemas an experimental, template-level opt-in. Keeping it template-scoped makes the capability explicit, avoids changing normal sandbox behavior, and keeps normal snapshot/restore flows unchanged unless the template has requested ivshmem support.What Changed
Add template-level
enableIvshmemsupport across CubeAPI, CubeMaster, cubemastercli, and the Python SDK.Persist the opt-in as an internal CubeMaster annotation.
Have CubeShim create and clean up one host-side ivshmem backend file per sandbox:
/dev/shm/ivshmem-{sandbox_id}Retarget existing snapshot ivshmem devices to the new sandbox backend path during restore.
Keep ivshmem disabled by default.
Avoid injecting ivshmem into existing non-ivshmem templates or snapshots.
Add public examples for host-side mmap benchmarking and minimal host/guest communication over an ivshmem-backed ring buffer.
Validation
Focused tests:
The following validation was also run on a real verification server: Tencent Lighthouse, 4 vCPU, 8 GB memory, PVM enabled, Linux kernel
6.6.69-1.1.cubesandbox.oc9.x86_64, AMD EPYC 7K62 CPU.Guest-visible device and communication:
/dev/shm/ivshmem-{sandbox_id}as the host backend path, with a 1 MiB backend file and0600permissions./proc/<pid>/maps.0x1af4/0x1110.resource2andresource2_wcwere present.Host -> GuestandGuest -> Hostbyte exchange through the guestresource2mapping.examples/ivshmem/ivshmem_ring_demo.pypassed host/guest communication.Snapshot, clone, and rollback lifecycle:
create/delete: shared-memory read/write succeeded, and/dev/shm/ivshmem-{sandbox_id}was cleaned up after delete.pause/resume: shared-memory read/write succeeded before pause and after resume.snapshot/rollback: shared-memory read/write succeeded before snapshot and after rollback.commit+create: the source sandbox and cloned sandbox used different ivshmem shm paths, and shared-memory read/write succeeded in both sandboxes.Default behavior and non-opt-in regression:
Performance Check
The benchmark compared an ivshmem shared-memory ring buffer with a raw vsock stream on the same host. The guest side used a C helper for both paths.
These numbers are included as a sanity check for the experimental data path, not as a stable performance guarantee.
The two latency rows are separate one-off samples collected by the same guest-C benchmark script in different throughput runs. They are not a 3-run latency average.
Additional smoke checks:
These Python-based E2E checks validate API wiring, sandbox lifecycle, shared-memory access, and cleanup behavior. They are not intended to represent the ivshmem data-path ceiling because the demo uses per-message acknowledgements, Python-side polling loops,
mmap.flush()on each round, and Python payload generation and verification on both sides.Scope
This PR adds experimental template-level ivshmem opt-in.
It intentionally does not:
Restore-time ivshmem handling is limited to snapshots that already contain an ivshmem device. Existing non-ivshmem templates and snapshots keep their original behavior.
Notes
The ivshmem backend file is sandbox-scoped and uses
/dev/shm/ivshmem-{sandbox_id}on the host.