Skip to content

Commit 4dab024

Browse files
slptylerfanelli
authored andcommitted
context: set SHM window to be as large as the host's RAM
On version 1.9.5 libkrun introduced an API to set the size of the SHM window for virtio-gpu. Use it to set it to be as large as the host's RAM. This should give us enough room for running large models, accounting for potential device memory fragmentation. Signed-off-by: Sergio Lopez <slp@redhat.com>
1 parent 153aab4 commit 4dab024

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ build = "build.rs"
1212
anyhow = "1.0.79"
1313
clap = { version = "4.5.0", features = ["derive"] }
1414
mac_address = "1.1.5"
15+
sysinfo = "0.31.4"

src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use anyhow::{anyhow, Context};
1515
#[link(name = "krun-efi")]
1616
extern "C" {
1717
fn krun_create_ctx() -> i32;
18-
fn krun_set_gpu_options(ctx_id: u32, virgl_flags: u32) -> i32;
18+
fn krun_set_gpu_options2(ctx_id: u32, virgl_flags: u32, shm_size: u64) -> i32;
1919
fn krun_set_vm_config(ctx_id: u32, num_vcpus: u8, ram_mib: u32) -> i32;
2020
fn krun_set_smbios_oem_strings(ctx_id: u32, oem_strings: *const *const c_char) -> i32;
2121
fn krun_start_enter(ctx_id: u32) -> i32;
@@ -64,7 +64,8 @@ impl TryFrom<Args> for KrunContext {
6464

6565
// Temporarily enable GPU by default
6666
let virgl_flags = VIRGLRENDERER_VENUS | VIRGLRENDERER_NO_VIRGL;
67-
if unsafe { krun_set_gpu_options(id, virgl_flags) } < 0 {
67+
let sys = sysinfo::System::new_all();
68+
if unsafe { krun_set_gpu_options2(id, virgl_flags, sys.total_memory()) } < 0 {
6869
return Err(anyhow!("unable to set krun vCPU/RAM configuration"));
6970
}
7071

0 commit comments

Comments
 (0)