Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit RAM+VRAM to avoid exceeding IPA addressing #19

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ impl TryFrom<Args> for KrunContext {

if args.memory == 0 {
return Err(anyhow!("zero MiB RAM inputted (invalid)"));
} else if args.memory > 61440 {
// Limit RAM to 60 GiB of the 62 GiB upper bound to leave room for VRAM.
return Err(anyhow!(
"requested RAM larger than upper limit of 61440 MiB"
));
}

if unsafe { krun_set_vm_config(id, args.cpus, args.memory) } < 0 {
Expand All @@ -69,7 +74,10 @@ impl TryFrom<Args> for KrunContext {
// Temporarily enable GPU by default
let virgl_flags = VIRGLRENDERER_VENUS | VIRGLRENDERER_NO_VIRGL;
let sys = sysinfo::System::new_all();
if unsafe { krun_set_gpu_options2(id, virgl_flags, sys.total_memory()) } < 0 {
// Limit RAM + VRAM to 64 GB (36 bit IPA address limit) minus 2 GB (start address plus rounding).
let rounded_mem = ((args.memory as u64) / 1024 + 1) * 1024;
let vram = std::cmp::min((63488 - rounded_mem) * 1024 * 1024, sys.total_memory());
if unsafe { krun_set_gpu_options2(id, virgl_flags, vram) } < 0 {
return Err(anyhow!("unable to set krun vCPU/RAM configuration"));
}

Expand Down
Loading