mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 21:21:32 +00:00
fix(runtime): adjust memory resources inside a transaction
This commit is contained in:
@ -6,6 +6,7 @@ use tokio::sync::Semaphore;
|
||||
use uuid::Uuid;
|
||||
|
||||
use xenclient::XenClient;
|
||||
use xenplatform::domain::XEN_EXTRA_MEMORY_KB;
|
||||
use xenstore::{XsdClient, XsdInterface};
|
||||
|
||||
use self::{
|
||||
@ -226,33 +227,34 @@ impl Runtime {
|
||||
Ok(uuid)
|
||||
}
|
||||
|
||||
pub async fn set_max_memory(&self, domid: u32, max_memory_bytes: u64) -> Result<()> {
|
||||
pub async fn set_memory_resources(
|
||||
&self,
|
||||
domid: u32,
|
||||
target_memory_bytes: u64,
|
||||
max_memory_bytes: u64,
|
||||
) -> Result<()> {
|
||||
let mut max_memory_bytes = max_memory_bytes + (XEN_EXTRA_MEMORY_KB * 1024);
|
||||
if target_memory_bytes > max_memory_bytes {
|
||||
max_memory_bytes = target_memory_bytes + (XEN_EXTRA_MEMORY_KB * 1024);
|
||||
}
|
||||
|
||||
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 tx = self.context.xen.store.transaction().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())
|
||||
tx.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?;
|
||||
tx.write_string(
|
||||
target_memory_path,
|
||||
&(target_memory_bytes / 1024).to_string(),
|
||||
)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user