pub struct TierManager<const MAX_REGIONS: usize> { /* private fields */ }Expand description
Manages tier placement for a fixed set of memory regions.
MAX_REGIONS is the compile-time upper bound on tracked regions.
This avoids heap allocation and is suitable for no_std environments.
Implementations§
Source§impl<const MAX_REGIONS: usize> TierManager<MAX_REGIONS>
impl<const MAX_REGIONS: usize> TierManager<MAX_REGIONS>
Sourcepub const fn with_thresholds(thresholds: TierThresholds) -> Self
pub const fn with_thresholds(thresholds: TierThresholds) -> Self
Create a new TierManager with custom thresholds.
Sourcepub const fn current_epoch(&self) -> u32
pub const fn current_epoch(&self) -> u32
Return the current epoch.
Sourcepub fn advance_epoch(&mut self)
pub fn advance_epoch(&mut self)
Advance the epoch counter. Call this once per scheduler epoch.
Sourcepub fn register(
&mut self,
region_id: OwnedRegionId,
initial_tier: Tier,
) -> RvmResult<()>
pub fn register( &mut self, region_id: OwnedRegionId, initial_tier: Tier, ) -> RvmResult<()>
Register a new region in the tier manager at the given initial tier.
§Errors
Returns RvmError::ResourceLimitExceeded if the manager is at capacity.
Returns RvmError::MemoryOverlap if the region is already registered.
Sourcepub fn unregister(&mut self, region_id: OwnedRegionId) -> RvmResult<()>
pub fn unregister(&mut self, region_id: OwnedRegionId) -> RvmResult<()>
Unregister a region from the tier manager.
§Errors
Returns RvmError::PartitionNotFound if the region is not tracked.
Sourcepub fn record_access(&mut self, region_id: OwnedRegionId) -> RvmResult<()>
pub fn record_access(&mut self, region_id: OwnedRegionId) -> RvmResult<()>
Record an access to the given region, updating its recency score.
§Errors
Returns RvmError::PartitionNotFound if the region is not tracked.
Sourcepub fn update_cut_value(
&mut self,
region_id: OwnedRegionId,
cut_value: u16,
) -> RvmResult<()>
pub fn update_cut_value( &mut self, region_id: OwnedRegionId, cut_value: u16, ) -> RvmResult<()>
Update the cut value for a region (from the coherence engine).
§Errors
Returns RvmError::PartitionNotFound if the region is not tracked.
Sourcepub fn promote(
&mut self,
region_id: OwnedRegionId,
target_tier: Tier,
) -> RvmResult<Tier>
pub fn promote( &mut self, region_id: OwnedRegionId, target_tier: Tier, ) -> RvmResult<Tier>
Promote a region to a higher (lower-numbered) tier.
Returns the previous tier on success.
§Errors
Returns RvmError::PartitionNotFound if the region is not tracked.
Returns RvmError::InvalidTierTransition if the target tier is not
higher than the current tier, or if promoting from Cold.
Returns RvmError::CoherenceBelowThreshold if the residency score
does not meet the promotion threshold.
Sourcepub fn demote(
&mut self,
region_id: OwnedRegionId,
target_tier: Tier,
) -> RvmResult<Tier>
pub fn demote( &mut self, region_id: OwnedRegionId, target_tier: Tier, ) -> RvmResult<Tier>
Demote a region to a lower (higher-numbered) tier.
Returns the previous tier on success.
§Errors
Returns RvmError::PartitionNotFound if the region is not tracked.
Returns RvmError::InvalidTierTransition if the target tier is not
lower than the current tier.
Sourcepub fn get(&self, region_id: OwnedRegionId) -> Option<&RegionTierState>
pub fn get(&self, region_id: OwnedRegionId) -> Option<&RegionTierState>
Return the current tier state for a region, if tracked.
Sourcepub fn decay_recency(&mut self, decay_amount: u16)
pub fn decay_recency(&mut self, decay_amount: u16)
Decay recency scores for all tracked regions by the given amount (in basis points). Call this once per epoch to age out stale regions.
Sourcepub fn find_demotion_candidates(
&self,
out: &mut [(OwnedRegionId, Tier)],
) -> usize
pub fn find_demotion_candidates( &self, out: &mut [(OwnedRegionId, Tier)], ) -> usize
Identify regions that should be demoted based on current thresholds.
Returns (region_id, recommended_target_tier) pairs.
Caller is responsible for acting on recommendations (e.g., triggering
compression for Dormant demotion).
out is a caller-provided buffer; returns the number of entries written.