Trait EvictionPolicy

Source
pub trait EvictionPolicy<F: FrameId> {
    type Error: Error;

    // Required methods
    fn evict(&self) -> Option<F>;
    fn peek(&self) -> Option<F>;
    fn touch(&self, id: F) -> Result<(), Self::Error>;
    fn touch_with<T: AccessType>(
        &self,
        id: F,
        access_type: T,
    ) -> Result<(), Self::Error>;
    fn pin(&self, id: F) -> Result<(), Self::Error>;
    fn unpin(&self, id: F) -> Result<(), Self::Error>;
    fn remove(&self, id: F) -> Result<(), Self::Error>;
    fn capacity(&self) -> usize;
    fn size(&self) -> usize;
}
Expand description

Page eviction policy.

Defines an interface for interacting with different page replacement strategies. At its core, it provides methods for logging data access, managing meta-data, and eventually locating the next frame to evict.

Required Associated Types§

Source

type Error: Error

Error type for the eviction policy.

Required Methods§

Source

fn evict(&self) -> Option<F>

Find the next frame to be evicted and evict it.

Only non-pinned frames are candidates for eviction. Use EvictionPolicy::pin to pin frames.

By default, all pages are pinned and it is the responsibility of the clients to unpin them before the eviction policy implementer can start evicting them.

Successful eviction of a frame decreases the list size of non-pinned frames and potentially cleans the frame’s access history.

Source

fn peek(&self) -> Option<F>

Peek into the next frame to be evicted.

This function does not remove the frame from the list of non-pinned frames.

Source

fn touch(&self, id: F) -> Result<(), Self::Error>

Notifies the policy manager that a page controlled by the frame has been referenced/accessed.

This normally updates the access history of a frame using the current timestamp.

Source

fn touch_with<T: AccessType>( &self, id: F, access_type: T, ) -> Result<(), Self::Error>

Notifies the policy manager that a page controlled by the frame has been referenced/accessed. In addition to mere occurrence of access, this method also logs the type of the access.

Source

fn pin(&self, id: F) -> Result<(), Self::Error>

Pin a frame, marking it as non-evictable.

If the frame is already pinned, nothing happens.

Source

fn unpin(&self, id: F) -> Result<(), Self::Error>

Unpin a frame, marking it as evictable.

If the frame is already unpinned, nothing happens.

Source

fn remove(&self, id: F) -> Result<(), Self::Error>

Removes an evictable frame.

In contrast to evict, this function removes an arbitrary non-pinned frame, not necessarily the one with the highest priority.

If the frame is pinned, then this function should return an error.

Source

fn capacity(&self) -> usize

Returns the maximum number of frames that can be stored.

Source

fn size(&self) -> usize

The number of elements that can be evicted. Essentially, this is the number of non-pinned frames.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§