pub struct MemoryWriter { /* private fields */ }Expand description
Memory file writer — wraps an AtomicWriter so the staged file is renamed onto
the destination on commit.
Implementations§
Source§impl MemoryWriter
impl MemoryWriter
Sourcepub fn open(
dest: &Path,
ram_size: u64,
page_size: u64,
) -> Result<Self, SnapshotError>
pub fn open( dest: &Path, ram_size: u64, page_size: u64, ) -> Result<Self, SnapshotError>
Open a memory writer for the destination path.
ram_size is the logical size; for Full snapshots the file ends up exactly
this large, for Diff it ends up sparse with the same logical extent.
page_size is the memory-file page size — typically the host page
(16 KiB on Apple Silicon) so the file aligns with pwrite granularity.
§Errors
Sourcepub fn write_full<R: PageReader>(
&mut self,
reader: &R,
) -> Result<(), SnapshotError>
pub fn write_full<R: PageReader>( &mut self, reader: &R, ) -> Result<(), SnapshotError>
Write a Full dump: every byte of [0, ram_size) from reader is written.
We chunk in page_size units so the writer never holds the whole memory in
a buffer; this matches the production path where applevisor::Memory::read
is the upstream of read_at.
§Errors
SnapshotError::MemoryIo for any read or write failure.
Sourcepub fn write_diff<R: PageReader>(
&mut self,
reader: &R,
dirty: &DirtyBitmap,
) -> Result<u64, SnapshotError>
pub fn write_diff<R: PageReader>( &mut self, reader: &R, dirty: &DirtyBitmap, ) -> Result<u64, SnapshotError>
Write a Diff dump: only the pages in dirty are pwritten at their offsets.
The file’s logical extent ends up at ram_size. Filesystem-level holes will
cover the unmodified pages on APFS, HFS+, and exFAT (per § 7 — “sparse file
cross-FS”); on NFS we still produce the right bytes, just dense.
dirty must cover the same [ram_start, ram_size) range as the writer, but
may have a different page_size: we re-chunk the writes accordingly so the
memory file stays at self.page_size granularity even when the bitmap was
rebuilt under the adaptive heuristic.
§Errors
SnapshotError::MemoryIo for any read or write failure.