clock-page-replacement 0.1.1

Simple clock page replacement algorithm implementation
Documentation
  • Coverage
  • 100%
    13 out of 13 items documented0 out of 12 items with examples
  • Size
  • Source code size: 10.04 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.02 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • abmfy

Clock Page Replacement

A simple clock page replacement algorithm implementation.

Usage

First, you should have your type representing a page table entry on a memory implement Page trait which requires basic access to some flag bits:

pub trait Page {
    /// Check if the page is valid.
    fn is_valid(&self) -> bool;

    /// Check if the page is accessed.
    fn is_accessed(&self) -> bool;

    /// Check if the page is dirty.
    fn is_dirty(&self) -> bool;

    /// Set the 'A' bit.
    fn set_accessed(&mut self);

    /// Set the 'D' bit.
    fn set_dirty(&mut self);

    /// Clear the 'A' bit.
    fn clear_accessed(&mut self);

    /// Clear the 'D' bit.
    fn clear_dirty(&mut self);
}

Then create a ClockPageReplacer instance. Every time you allocate a physical memory page, you should call ClockPageReplacer::register to register it to the replacer.

You don't need to unregister a page when it's evicted from the physical memory, because the replacer will automatically remove it when it becomes invalid.

When you need to replace a page, call the replace method to get the page to replace. The page is automatically removed from the replacer.