in resctl-bench/src/bench/protection/mem_hog_tune.rs [47:139]
fn run_one(
&self,
rctx: &mut RunCtx,
desc: &str,
size: usize,
base_period: &mut (u64, u64),
is_last: bool,
) -> Result<(bool, Option<MemHogRecord>)> {
let started_at = unix_now();
rctx.set_hashd_mem_size(size, false)?;
let base_rps = rctx.bench_knobs().hashd.rps_max as f64 * self.load;
let fail_pct = self.isol_pct.parse::<f64>().unwrap() / 100.0;
let early_fail_cnt = (self.dur * fail_pct).ceil() as u64;
let fail_rps_thr = base_rps * self.isol_thr;
let mut swap_started_at = 0;
let mut fail_cnt = 0;
let is_done =
|af: &AgentFiles,
hog_usage: &rd_agent_intf::UsageReport,
_hog_rep: &rd_agent_intf::bandit_report::BanditMemHogReport| {
if swap_started_at == 0 {
if hog_usage.swap_bytes > 0 {
swap_started_at = unix_now();
}
} else if (unix_now() - swap_started_at) as f64 >= self.dur {
return true;
}
if !is_last && af.report.data.hashd[0].rps < fail_rps_thr {
fail_cnt += 1;
fail_cnt > early_fail_cnt
} else {
false
}
};
let (run, bper) = match MemHog::run_one(
rctx,
desc,
self.load,
self.speed,
base_period.0 == base_period.1,
3600.0,
is_done,
) {
Ok((run, bper)) if run.failed.is_none() => (run, bper),
_ => return Ok((false, None)),
};
if base_period.0 == base_period.1 {
*base_period = bper.unwrap();
}
if fail_cnt > early_fail_cnt {
info!(
"protection: {} failed, early fail with fail_cnt={}",
desc, fail_cnt
);
return Ok((false, None));
}
let hog_rec = MemHogRecord {
period: (started_at, unix_now()),
base_period: *base_period,
base_rps,
runs: vec![run],
..Default::default()
};
let hog_res = MemHog::study(rctx, &hog_rec)?;
let isol_res = hog_res.isol[&self.isol_pct];
if isol_res < self.isol_thr {
info!(
"protection: {} failed, isol-{}={}% < {}%",
desc,
self.isol_pct,
format_pct(isol_res),
format_pct(self.isol_thr),
);
Ok((false, Some(hog_rec)))
} else {
info!(
"protection: {} succeeded, isol-{}={}% >= {}%",
desc,
self.isol_pct,
format_pct(isol_res),
format_pct(self.isol_thr),
);
Ok((true, Some(hog_rec)))
}
}