feature(krata): dynamic resource allocation (closes #298) (#333)

This commit is contained in:
Alex Zenla
2024-08-14 01:14:49 -07:00
committed by GitHub
parent 1dca770091
commit 87530edf70
15 changed files with 251 additions and 31 deletions

View File

@ -30,8 +30,9 @@ pub struct ZoneLaunchRequest {
pub initrd: Vec<u8>,
pub uuid: Option<Uuid>,
pub name: Option<String>,
pub vcpus: u32,
pub mem: u64,
pub cpus: u32,
pub target_memory: u64,
pub max_memory: u64,
pub env: HashMap<String, String>,
pub run: Option<Vec<String>>,
pub pcis: Vec<PciDevice>,
@ -194,8 +195,9 @@ impl ZoneLauncher {
let config = DomainConfig {
base: BaseDomainConfig {
max_vcpus: request.vcpus,
mem_mb: request.mem,
max_vcpus: request.cpus,
max_mem_mb: request.max_memory,
target_mem_mb: request.target_memory,
kernel: request.kernel,
initrd: request.initrd,
cmdline,

View File

@ -226,6 +226,36 @@ impl Runtime {
Ok(uuid)
}
pub async fn set_max_memory(&self, domid: u32, max_memory_bytes: u64) -> Result<()> {
self.context
.xen
.call
.set_max_mem(domid, max_memory_bytes / 1024)
.await?;
let domain_path = self.context.xen.store.get_domain_path(domid).await?;
let max_memory_path = format!("{}/memory/static-max", domain_path);
self.context
.xen
.store
.write_string(max_memory_path, &(max_memory_bytes / 1024).to_string())
.await?;
Ok(())
}
pub async fn set_target_memory(&self, domid: u32, target_memory_bytes: u64) -> Result<()> {
let domain_path = self.context.xen.store.get_domain_path(domid).await?;
let target_memory_path = format!("{}/memory/target", domain_path);
self.context
.xen
.store
.write_string(
target_memory_path,
&(target_memory_bytes / 1024).to_string(),
)
.await?;
Ok(())
}
pub async fn list(&self) -> Result<Vec<ZoneInfo>> {
self.context.list().await
}