File: guest_memory.rs

package info (click to toggle)
rust-vm-memory 0.16.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 884 kB
  • sloc: makefile: 2
file content (35 lines) | stat: -rw-r--r-- 920 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (C) 2020 Alibaba Cloud Computing. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
#![cfg(feature = "backend-mmap")]

pub use criterion::{black_box, Criterion};

use vm_memory::bitmap::Bitmap;
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryMmap};

const REGION_SIZE: usize = 0x10_0000;
const REGIONS_COUNT: u64 = 256;

pub fn benchmark_for_guest_memory(c: &mut Criterion) {
    benchmark_find_region(c);
}

fn find_region<B>(mem: &GuestMemoryMmap<B>)
where
    B: Bitmap + 'static,
{
    for i in 0..REGIONS_COUNT {
        let _ = mem
            .find_region(black_box(GuestAddress(i * REGION_SIZE as u64)))
            .unwrap();
    }
}

fn benchmark_find_region(c: &mut Criterion) {
    let memory = super::create_guest_memory_mmap(REGION_SIZE, REGIONS_COUNT);

    c.bench_function("find_region", |b| {
        b.iter(|| find_region(black_box(&memory)))
    });
}