Skip to main content

BlockCache

Struct BlockCache 

Source
pub struct BlockCache { /* private fields */ }
Expand description

Verified segment blocks, evicted least recently used first once their total size passes the budget.

A build’s resolver threads read the same segments at once, and one lock for every hit made each hit wait for all the others (12 threads: 4.9 us per hit, against 0.1 us for one thread). So the cache is split into shards by block, each with its own lock, its own share of the budget and its own use order, and a hit takes only its shard’s read lock: it stamps the block’s last use atomically and leaves the use order alone. The order catches up at eviction, which moves a block it finds used since it was listed instead of evicting it. Eviction is therefore least recently used within a shard; a small cache keeps one shard, so its order is exact.

Implementations§

Source§

impl BlockCache

Source

pub fn new(budget_bytes: usize) -> Self

A cache holding at most budget_bytes of block data.

§Panics

If the budget is smaller than one block: such a cache could not hold the block a read is waiting for.

Source

pub fn set_budget(&self, bytes: usize)

Resize without invalidating blocks readers already hold. Each shard keeps its identity; a shrink releases at most 64 entries per lock hold. The budget must still allow at least one block per existing shard.

Source

pub fn stats(&self) -> CacheStats

Source

pub fn memory_bytes(&self) -> Option<usize>

The bytes the cache holds in memory, measured as crate::heap describes: every cached block in its shared allocation, and the two tables that find a block and order blocks by use. None while another thread holds the cache’s lock: the memory census never waits for it.

Trait Implementations§

Source§

impl Debug for BlockCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.