Skip to main content

DirtyBitmap

Struct DirtyBitmap 

Source
pub struct DirtyBitmap { /* private fields */ }
Expand description

Box<[AtomicU64]> shadow bitmap of dirty tracking pages.

The map covers [ram_start, ram_start + ram_size). set_dirty is called from the vCPU exit handler; drain is called by the snapshot writer. Both are lock-free.

Implementations§

Source§

impl DirtyBitmap

Source

pub fn new( ram_start: u64, ram_size: u64, page_size: u64, ) -> Result<Self, SnapshotError>

Build a bitmap covering [ram_start, ram_start + ram_size) at page_size.

§Errors

SnapshotError::InvalidPath (re-used for “rejected configuration”) if page_size is not a power of two, the range is empty, or the range overflows.

Source

pub const fn ram_start(&self) -> u64

Total tracked range start.

Source

pub const fn ram_size(&self) -> u64

Total tracked range size in bytes.

Source

pub const fn page_size(&self) -> u64

Page size (in bytes).

Source

pub const fn page_count(&self) -> u64

Number of tracked pages.

Source

pub fn page_shift(&self) -> u32

log2(page_size) — used by callers that compute the FAR-to-bit-index shift.

Source

pub fn page_index_of(&self, addr: u64) -> Option<u64>

Compute the bit index of the page containing addr.

Returns None if addr is outside the tracked range.

Source

pub fn set_dirty(&self, addr: u64) -> bool

Set the dirty bit for the page containing addr. Idempotent.

Returns true if the bit transitioned from clean to dirty.

Source

pub fn set_dirty_by_index(&self, page: u64) -> bool

Set a specific page’s dirty bit. Same return semantics as Self::set_dirty.

Source

pub fn is_dirty(&self, addr: u64) -> bool

Read whether addr is dirty (without clearing).

Source

pub fn is_dirty_by_index(&self, page: u64) -> bool

Same as Self::is_dirty but accepts a pre-computed page index.

Source

pub fn drain(&self) -> Vec<u64>

Atomically swap each word to zero, returning a list of dirty page indices.

The acquire ordering on the swap pairs with the release on set_dirty’s fetch_or (Relaxed is sufficient there because the only consumer is this drain on the snapshot path, and the drain seq-cst-like ordering is owed by the surrounding pause/resume vCPU dance, not by the bitmap itself; we use Acquire here to synchronize-with any future code that relaxes the surrounding vCPU coordination).

Source

pub fn drain_into<F: FnMut(u64)>(&self, callback: F)

Drain into a callback, avoiding the intermediate Vec allocation. Used by the memory-file writer’s hot path.

Source

pub fn fold_into_finer(&self, fine: &DirtyBitmap) -> Result<(), SnapshotError>

Fold all coarse-block dirty bits into a finer-grained bitmap.

When the heuristic steps down a region from 2 MiB to 16 KiB, the coarse bitmap’s set bits each correspond to a 2 MiB block: every fine page in that block becomes dirty. This preserves snapshot coverage across the transition.

fine must cover the same [ram_start, ram_start + ram_size) and have a strictly smaller page_size.

§Errors

SnapshotError::InvalidPath if the geometry doesn’t match.

Trait Implementations§

Source§

impl Debug for DirtyBitmap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more