Files
nvdriver/tools/bench_sysmem_pool_reuse.rs
ThingsCouldGetDicey 3e1bf7b8c8 perf(rmapi/uvm/pcie): batch sysmem pool reuse & UVM DMA drain, roll back PCIe target on retrain failure (#516)
* fix(pcie): restore link target after retrain register failures

Reuse the existing best-effort timeout rollback for every failure after the endpoint target write succeeds, preserving the original error. Fault injection exposes three failing tests on master; all eight targeted tests, workspace tests, clippy and offline codegen checks pass with the correction. No changes to link policy, capability gates or success path.

* perf(uvm): batch DMA mapping cleanup at node exit

Drain up to 16 live records per leaf-mutex acquisition, preserving bucket order and leaving DMA unmap/page/device releases outside the lock. No changes to insert/lookup/device detach, per-page unmap or mapping permissions. Seven paired CPU-only samples from 1 to 262144 records show 1.30x to 20.85x faster ledger cleanup. Workspace 1409 passed, 150 ignored; clippy, formatting, native codegen and Rust kernel object build pass. Full kernel module and physical/guest testing pending.

* perf(rmapi): batch hot system-page pool reuse

Take up to 32 hot pages per pool mutex acquisition, publish the count once, and clear all reused pages outside the mutex. Preserve LIFO order, partial/empty fallback, admission and cache policy, and allocation failure cleanup. Seven paired host benchmarks show up to 4.72x faster bookkeeping and 4.92x p99 improvement for 16384 fully pooled pages, with single-page and empty-pool parity. 1409 workspace tests pass, 150 ignored; strict clippy, codegen audit, Rust kernel object and offline kernel gates pass. Full C module/guest/physical validation pending.

---------

Co-authored-by: Nick <your-email@example.com>
2026-12-05 14:19:17 -08:00

96 lines
3.9 KiB
Rust

// SPDX-License-Identifier: MIT
// CPU-only synthetic page-pool benchmark; no GPU or kernel page access.
// Copy this file into a temporary directory beside the exact baseline
// alloc_registry.rs renamed ledger.rs. Compile with:
// rustc --edition=2024 -C opt-level=3 -C overflow-checks=yes bench.rs -o baseline
// Repeat with candidate ledger.rs and --cfg batch -o candidate.
// Pin both processes to the same allowed CPU, alternate order, retain CSV.
// CSV: request size, pool fill percent, repetitions, aggregate ns,
// mutex acquisitions, p99 request ns. Measures host mutex and bookkeeping
// only; fresh allocation and clear_highpage are represented by synthetic tokens.
#![allow(dead_code)]
#[path = "ledger.rs"]
mod ledger;
use ledger::SysmemPagePool;
use std::{
hint::black_box,
sync::{
Mutex,
atomic::{AtomicUsize, Ordering},
},
time::Instant,
};
fn main() {
for n in [1usize, 8, 32, 128, 1024, 16384] {
let rounds = (262144 / n).max(16);
for fill in [0usize, 50, 100] {
let pooled = n * fill / 100;
let mut inner = Mutex::new((SysmemPagePool::new(), vec![0usize; n.max(1)]));
let published = AtomicUsize::new(0);
let mut total = 0u128;
let mut samples = Vec::with_capacity(rounds);
let mut output = vec![0usize; n];
let mut calls = 0usize;
for _ in 0..rounds {
{
let (pool, slots) = inner.get_mut().unwrap();
for page in 1..=pooled {
assert_eq!(pool.push(slots, page), Ok(()));
}
published.store(pool.len(), Ordering::Release);
}
let now = Instant::now();
let mut i = 0usize;
while i < n {
#[cfg(not(batch))]
{
let item = {
let mut guard = black_box(&inner).lock().unwrap();
let (pool, slots) = &mut *guard;
let p = pool.pop_hot(slots);
published.store(pool.len(), Ordering::Release);
p
};
calls += 1;
output[i] = item.unwrap_or(n + i + 1);
i += 1;
}
#[cfg(batch)]
{
let limit = (n - i).min(32);
let count = {
let mut guard = black_box(&inner).lock().unwrap();
let (pool, slots) = &mut *guard;
let mut written = 0usize;
let count = pool.pop_hot_batch(slots, limit, |page| {
output[i + written] = page;
written += 1;
});
published.store(pool.len(), Ordering::Release);
count
};
calls += 1;
i += count;
if count < limit {
output[i] = n + i + 1;
i += 1;
}
}
}
let elapsed = now.elapsed().as_nanos();
total += elapsed;
samples.push(elapsed);
assert_eq!(published.load(Ordering::Acquire), 0);
for (i, &p) in black_box(&output).iter().enumerate() {
assert_eq!(p, if i < pooled { pooled - i } else { n + i + 1 });
}
}
samples.sort_unstable();
println!(
"{n},{fill},{rounds},{total},{calls},{}",
samples[(samples.len() - 1) * 99 / 100]
);
}
}
}