24 releases

0.4.6 Aug 20, 2024
0.4.5 Aug 5, 2023
0.4.3 Jul 10, 2023
0.3.0 Oct 3, 2022
0.0.1 Jun 3, 2018

#340 in Database interfaces

Download history 134/week @ 2024-07-25 142/week @ 2024-08-01 114/week @ 2024-08-08 353/week @ 2024-08-15 134/week @ 2024-08-22 128/week @ 2024-08-29 132/week @ 2024-09-05 229/week @ 2024-09-12 209/week @ 2024-09-19 160/week @ 2024-09-26 120/week @ 2024-10-03 113/week @ 2024-10-10 67/week @ 2024-10-17 78/week @ 2024-10-24 145/week @ 2024-10-31 207/week @ 2024-11-07

516 downloads per month
Used in 15 crates (2 directly)

MIT/Apache

12KB
220 lines

pagetable

Wait-free 4-level page table that maps from a u64 key to an &AtomicU64 value. Page fan-out is 2^16. If a key doesn't exist, intermediate pages are atomically created while traversing down the levels, and the value is initialized to 0.

This is a somewhat specialized data structure, but it is useful for maintaining metadata in concurrent systems that need to track many items that have an associated logical ID that is allocated from a dense keyspace, like databases that would like to keep track of where a page lives based on its 64-bit ID, despite it being rewritten in random places during defragmentation.

API

#[derive(Default)]
pub struct PageTable { .. }

pub fn get(&self, key: u64) -> &AtomicU64 { .. }

Example

let pt = PageTable::default();

for i in 0..100_000_000 {
    pt.get(i).fetch_add(1, Ordering::SeqCst);
}

for i in 0..100_000_000 {
    let value = pt.get(i).load(Ordering::SeqCst);
    assert_eq!(value, 1);
}

No runtime deps