performance-metrics: Settle host before each test

Flush host writeback queues, drop the page cache and sleep 1s
for kernel housekeeping before each test run.

The cloud-hypervisor block backend does buffered I/O on the host
side, so dirty pages from prior write tests can accumulate and
compete for I/O bandwidth with subsequent tests. Dropping caches
ensures cold read tests get a consistent baseline rather than
benefiting from data cached by prior tests. The brief cooldown
lets the kernel finish tearing down KVM state and freeing pages
from the previous VM before the next one starts.

Requires root, which the metrics container provides. Silently
fails otherwise.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-03-11 20:54:11 +01:00
committed by Rob Bradford
parent 57e64a0848
commit c0a81bc903

View File

@@ -1234,6 +1234,14 @@ fn cleanup_stale_processes() {
thread::sleep(Duration::from_secs(2));
}
fn settle_host() {
let _ = Command::new("sync").status();
let _ = Command::new("bash")
.args(["-c", "echo 3 > /proc/sys/vm/drop_caches"])
.status();
thread::sleep(Duration::from_secs(1));
}
fn date() -> String {
let output = test_infra::exec_host_command_output("date");
String::from_utf8_lossy(&output.stdout).trim().to_string()
@@ -1334,6 +1342,7 @@ fn main() {
for test in test_list.iter() {
if test_filter.is_empty() || test_filter.iter().any(|&s| test.name.contains(s)) {
settle_host();
match run_test_with_timeout(test, &overrides) {
Ok(r) => {
metrics_report.results.push(r);