[][src]Struct memflow::mem::cache::cached_vat::CachedVirtualTranslate

pub struct CachedVirtualTranslate<V, Q> {
    pub hitc: usize,
    pub misc: usize,
    // some fields omitted
}

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: usizemisc: 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]

Trait Implementations

impl<V: VirtualTranslate + Clone, Q: CacheValidator + Clone> Clone for CachedVirtualTranslate<V, Q>[src]

impl<V: VirtualTranslate, Q: CacheValidator> VirtualTranslate for CachedVirtualTranslate<V, Q>[src]

Auto Trait Implementations

impl<V, Q> !RefUnwindSafe for CachedVirtualTranslate<V, Q>

impl<V, Q> Send for CachedVirtualTranslate<V, Q> where
    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

impl<V, Q> !UnwindSafe for CachedVirtualTranslate<V, Q>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<'a, T, P> VirtualTranslate for P where
    P: DerefMut<Target = T> + Send,
    T: VirtualTranslate + ?Sized
[src]