pub struct FreeList { /* private fields */ }Expand description
In-memory freelist tracking
Maintains a fast in-memory list of free pages, with persistence through trunk pages.
Implementations§
Source§impl FreeList
impl FreeList
Sourcepub fn from_header(trunk_head: u32, total_free: u32) -> Self
pub fn from_header(trunk_head: u32, total_free: u32) -> Self
Create freelist from header page info
Sourcepub fn trunk_head(&self) -> u32
pub fn trunk_head(&self) -> u32
Get trunk head page ID
Sourcepub fn total_free(&self) -> u32
pub fn total_free(&self) -> u32
Get total count of free pages
Sourcepub fn mark_clean(&mut self)
pub fn mark_clean(&mut self)
Mark freelist as clean
Sourcepub fn allocate(&mut self) -> Option<u32>
pub fn allocate(&mut self) -> Option<u32>
Allocate a free page
Returns None if no free pages available.
Sourcepub fn free_batch(&mut self, page_ids: &[u32])
pub fn free_batch(&mut self, page_ids: &[u32])
Add multiple pages to freelist
Sourcepub fn in_memory_count(&self) -> usize
pub fn in_memory_count(&self) -> usize
Get count of pages in memory (not including trunk pages)
Sourcepub fn load_from_trunk(
&mut self,
trunk: &Page,
) -> Result<Option<u32>, FreeListError>
pub fn load_from_trunk( &mut self, trunk: &Page, ) -> Result<Option<u32>, FreeListError>
Load free pages from a trunk page
Sourcepub fn create_trunk(&mut self, trunk_page_id: u32, next_trunk: u32) -> Page
pub fn create_trunk(&mut self, trunk_page_id: u32, next_trunk: u32) -> Page
Create a trunk page from current free pages
Moves pages from in-memory list to a trunk page. Returns the trunk page and remaining pages.
Sourcepub fn flush_to_trunks(
&mut self,
threshold: usize,
allocate_page: impl FnMut() -> u32,
) -> Vec<Page>
pub fn flush_to_trunks( &mut self, threshold: usize, allocate_page: impl FnMut() -> u32, ) -> Vec<Page>
Flush excess free pages to trunk pages
If we have more than threshold pages in memory, create trunk pages.
Returns trunk pages that need to be written.
Sourcepub fn merge_all_trunks(
&mut self,
load_page: impl Fn(u32) -> Option<Page>,
) -> Result<Vec<u32>, FreeListError>
pub fn merge_all_trunks( &mut self, load_page: impl Fn(u32) -> Option<Page>, ) -> Result<Vec<u32>, FreeListError>
Merge all trunk pages into memory
Used during compaction to reclaim trunk pages.