[−][src]Struct memflow::mem::cache::cached_vat::CachedVirtualTranslate
CachedVirtualTranslate trasnaparently caches virtual addresss translations.
Using a VAT cache can provide significant speedups, since page table walks perform a number of memory reads, which induces noticeable latency, especially on slow memory backends.
Using the builder
function is the recommended way to create such a cache.
Examples
use memflow::mem::cache::CachedVirtualTranslate; let mut cached_vat = CachedVirtualTranslate::builder(&mut vat) .arch(x64::ARCH) .build() .unwrap();
Testing that cached translation is 4x faster than uncached translation when having a cache hit:
use std::time::{Duration, Instant}; let translation_address = virt_base; let iter_count = 512; let avg_cached = (0..iter_count).map(|_| { let timer = Instant::now(); cached_vat .virt_to_phys(&mut mem, &translator, translation_address) .unwrap(); timer.elapsed() }) .sum::<Duration>() / iter_count; println!("{:?}", avg_cached); std::mem::drop(cached_vat); let avg_uncached = (0..iter_count).map(|_| { let timer = Instant::now(); vat .virt_to_phys(&mut mem, &translator, translation_address) .unwrap(); timer.elapsed() }) .sum::<Duration>() / iter_count; println!("{:?}", avg_uncached); assert!(avg_cached * 4 <= avg_uncached);
Fields
hitc: usize
misc: usize
Implementations
impl<V: VirtualTranslate, Q: CacheValidator> CachedVirtualTranslate<V, Q>
[src]
pub fn new(vat: V, tlb: TLBCache<Q>, arch: ArchitectureObj) -> Self
[src]
impl<V: VirtualTranslate> CachedVirtualTranslate<V, DefaultCacheValidator>
[src]
pub fn builder(
vat: V
) -> CachedVirtualTranslateBuilder<V, DefaultCacheValidator>
[src]
vat: V
) -> CachedVirtualTranslateBuilder<V, DefaultCacheValidator>
Trait Implementations
impl<V: VirtualTranslate + Clone, Q: CacheValidator + Clone> Clone for CachedVirtualTranslate<V, Q>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<V: VirtualTranslate, Q: CacheValidator> VirtualTranslate for CachedVirtualTranslate<V, Q>
[src]
fn virt_to_phys_iter<T: ?Sized, B, D, VI, VO, FO>(
&mut self,
phys_mem: &mut T,
translator: &D,
addrs: VI,
out: &mut VO,
out_fail: &mut FO
) where
T: PhysicalMemory,
B: SplitAtIndex,
D: ScopedVirtualTranslate,
VI: Iterator<Item = (Address, B)>,
VO: Extend<(PhysicalAddress, B)>,
FO: Extend<(Error, Address, B)>,
[src]
&mut self,
phys_mem: &mut T,
translator: &D,
addrs: VI,
out: &mut VO,
out_fail: &mut FO
) where
T: PhysicalMemory,
B: SplitAtIndex,
D: ScopedVirtualTranslate,
VI: Iterator<Item = (Address, B)>,
VO: Extend<(PhysicalAddress, B)>,
FO: Extend<(Error, Address, B)>,
fn virt_to_phys<T: PhysicalMemory + ?Sized, D: ScopedVirtualTranslate>(
&mut self,
phys_mem: &mut T,
translator: &D,
vaddr: Address
) -> Result<PhysicalAddress>
[src]
&mut self,
phys_mem: &mut T,
translator: &D,
vaddr: Address
) -> Result<PhysicalAddress>
Auto Trait Implementations
impl<V, Q> !RefUnwindSafe for CachedVirtualTranslate<V, Q>
impl<V, Q> Send for CachedVirtualTranslate<V, Q> where
Q: Send,
V: Send,
Q: Send,
V: Send,
impl<V, Q> !Sync for CachedVirtualTranslate<V, Q>
impl<V, Q> Unpin for CachedVirtualTranslate<V, Q> where
Q: Unpin,
V: Unpin,
Q: Unpin,
V: Unpin,
impl<V, Q> !UnwindSafe for CachedVirtualTranslate<V, Q>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<'a, T, P> VirtualTranslate for P where
P: DerefMut<Target = T> + Send,
T: VirtualTranslate + ?Sized,
[src]
P: DerefMut<Target = T> + Send,
T: VirtualTranslate + ?Sized,
fn virt_to_phys_iter<U, B, D, VI, VO, FO>(
&mut Self,
&mut U,
&D,
VI,
&mut VO,
&mut FO
) where
B: SplitAtIndex,
D: ScopedVirtualTranslate,
FO: Extend<(Error, Address, B)>,
U: PhysicalMemory + ?Sized,
VI: Iterator<Item = (Address, B)>,
VO: Extend<(PhysicalAddress, B)>,
[src]
&mut Self,
&mut U,
&D,
VI,
&mut VO,
&mut FO
) where
B: SplitAtIndex,
D: ScopedVirtualTranslate,
FO: Extend<(Error, Address, B)>,
U: PhysicalMemory + ?Sized,
VI: Iterator<Item = (Address, B)>,
VO: Extend<(PhysicalAddress, B)>,
fn virt_to_phys<T: PhysicalMemory + ?Sized, D: ScopedVirtualTranslate>(
&mut self,
phys_mem: &mut T,
translator: &D,
vaddr: Address
) -> Result<PhysicalAddress>
[src]
&mut self,
phys_mem: &mut T,
translator: &D,
vaddr: Address
) -> Result<PhysicalAddress>