Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

GitHub

This documentation is part of the "Projects with Books" initiative at zenOSmosis.

The source code for this project is available on GitHub.

EntryHandle: Zero-Copy Data Access

Loading…

EntryHandle: Zero-Copy Data Access

Relevant source files

EntryHandle is the primary data structure for accessing entry payloads in rust-simd-r-drive. It acts as a zero-copy owner of a sub-slice within a memory-mapped file (Mmap), ensuring that data is never copied from the disk buffer into application memory during read operations.

Overview and Lifecycle

An EntryHandle binds an Arc<Mmap> with a specific Range<usize> and EntryMetadata simd-r-drive-entry-handle/src/entry_handle.rs:9-19 By using an Arc, the underlying memory mapping is kept alive as long as at least one handle exists, even if the DataStore that created it is closed or the file is remapped simd-r-drive-entry-handle/src/entry_handle.rs:123-125

Data Flow: From Disk to Application

The following diagram illustrates how EntryHandle bridges the gap between the raw memory map and the user’s byte-slice access.

Diagram: EntryHandle Memory Mapping Architecture

graph TD
    subgraph "Disk Storage"
        FILE["test_storage.bin"]
end

    subgraph "Process Address Space"
        MMAP["memmap2::Mmap (Memory Mapping)"]
ARC["Arc<Mmap> (Shared Ownership)"]
end

    subgraph "Code Entities (EntryHandle)"
        EH["EntryHandle"]
META["EntryMetadata"]
RANGE["Range<usize> (Payload Bounds)"]
end

 
   FILE -.->|mmap| MMAP
    MMAP --- ARC
    ARC --- EH
 
   EH --> META
 
   EH --> RANGE
    
 
   EH -.->|as_slice| SLICE["&[u8] (Zero-Copy View)"]
RANGE -.->|indexes| MMAP

Sources: simd-r-drive-entry-handle/src/entry_handle.rs:7-19 simd-r-drive-entry-handle/src/entry_handle.rs:151-155


Core API Methods

Construction

Data Access

Metadata and Validation

Sources: simd-r-drive-entry-handle/src/entry_handle.rs:21-244 simd-r-drive-entry-handle/src/entry_handle.rs:87-113


Internal API and Feature Gates

When the expose-internal-api feature is enabled (or during tests), additional methods are available to inspect the physical layout and memory addresses:

Sources: simd-r-drive-entry-handle/src/entry_handle.rs:22-33 simd-r-drive-entry-handle/src/entry_handle.rs:250-275


Alignment and SIMD Compatibility

The EntryHandle is designed to support SIMD operations and zero-copy typed views. Because the DataStore enforces PAYLOAD_ALIGNMENT (64 bytes) simd-r-drive-entry-handle/src/constants.rs18 the as_slice() pointer is often suitable for direct casting to SIMD types or aligned buffers simd-r-drive-entry-handle/src/debug_assert_aligned.rs:26-35

Diagram: Zero-Copy Memory Access Path

Sources: simd-r-drive-entry-handle/src/constants.rs:13-18 simd-r-drive-entry-handle/src/debug_assert_aligned.rs:66-81


Integration with Storage Operations

The DataStore utilizes EntryHandle in its read operations and iteration. When an entry is read, the DataStore constructs an EntryHandle using the current file mapping. This allows the system to verify integrity via is_valid_checksum() before passing the handle to the caller. The debug_assert_aligned_offset function ensures that file offsets used during handle construction adhere to the 64-byte boundary required for SIMD-optimized access simd-r-drive-entry-handle/src/debug_assert_aligned.rs:66-81

Sources: simd-r-drive-entry-handle/src/entry_handle.rs:129-139 simd-r-drive-entry-handle/src/debug_assert_aligned.rs:66-81