MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / insert

Method insert

block/src/qcow/vec_cache.rs:142–157  ·  view source on GitHub ↗

Check if the refblock cache is full and we need to evict.

(&mut self, index: usize, block: T, write_callback: F)

Source from the content-addressed store, hash-verified

140
141 // Check if the refblock cache is full and we need to evict.
142 pub fn insert<F>(&mut self, index: usize, block: T, write_callback: F) -> io::Result<()>
143 where
144 F: FnOnce(usize, T) -> io::Result<()>,
145 {
146 if self.map.len() == self.capacity {
147 // TODO(dgreid) - smarter eviction strategy.
148 let to_evict = *self.map.iter().next().unwrap().0;
149 if let Some(evicted) = self.map.remove(&to_evict)
150 && evicted.dirty()
151 {
152 write_callback(to_evict, evicted)?;
153 }
154 }
155 self.map.insert(index, block);
156 Ok(())
157 }
158}
159
160#[cfg(test)]

Callers 10

l2_tableMethod · 0.45
cache_l2_clusterMethod · 0.45
cache_l2_clusterMethod · 0.45
evicts_when_fullFunction · 0.45
set_cluster_refcountMethod · 0.45
get_cluster_refcountMethod · 0.45
refcount_blockMethod · 0.45
collect_bat_entriesMethod · 0.45
newMethod · 0.45

Calls 5

iterMethod · 0.80
dirtyMethod · 0.80
lenMethod · 0.45
nextMethod · 0.45
removeMethod · 0.45

Tested by 1

evicts_when_fullFunction · 0.36