mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 05:10:55 +00:00
fix(runtime): adjust memory resources inside a transaction
This commit is contained in:
@ -664,22 +664,21 @@ impl ControlService for DaemonControlService {
|
|||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let resources = request.resources.unwrap_or_default();
|
let mut resources = request.resources.unwrap_or_default();
|
||||||
|
if resources.target_memory > resources.max_memory {
|
||||||
|
resources.max_memory = resources.target_memory;
|
||||||
|
}
|
||||||
|
|
||||||
self.runtime
|
self.runtime
|
||||||
.set_max_memory(status.domid, resources.max_memory * 1024 * 1024)
|
.set_memory_resources(
|
||||||
|
status.domid,
|
||||||
|
resources.target_memory * 1024 * 1024,
|
||||||
|
resources.max_memory * 1024 * 1024,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|error| ApiError {
|
.map_err(|error| ApiError {
|
||||||
message: format!("failed to set maximum memory: {}", error),
|
message: format!("failed to set memory resources: {}", error),
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.runtime
|
|
||||||
.set_target_memory(status.domid, resources.target_memory * 1024 * 1024)
|
|
||||||
.await
|
|
||||||
.map_err(|error| ApiError {
|
|
||||||
message: format!("failed to set target memory: {}", error),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
status.resource_status = Some(ZoneResourceStatus {
|
status.resource_status = Some(ZoneResourceStatus {
|
||||||
active_resources: Some(resources),
|
active_resources: Some(resources),
|
||||||
});
|
});
|
||||||
|
@ -6,6 +6,7 @@ use tokio::sync::Semaphore;
|
|||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use xenclient::XenClient;
|
use xenclient::XenClient;
|
||||||
|
use xenplatform::domain::XEN_EXTRA_MEMORY_KB;
|
||||||
use xenstore::{XsdClient, XsdInterface};
|
use xenstore::{XsdClient, XsdInterface};
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
@ -226,33 +227,34 @@ impl Runtime {
|
|||||||
Ok(uuid)
|
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
|
self.context
|
||||||
.xen
|
.xen
|
||||||
.call
|
.call
|
||||||
.set_max_mem(domid, max_memory_bytes / 1024)
|
.set_max_mem(domid, max_memory_bytes / 1024)
|
||||||
.await?;
|
.await?;
|
||||||
let domain_path = self.context.xen.store.get_domain_path(domid).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);
|
let max_memory_path = format!("{}/memory/static-max", domain_path);
|
||||||
self.context
|
tx.write_string(max_memory_path, &(max_memory_bytes / 1024).to_string())
|
||||||
.xen
|
|
||||||
.store
|
|
||||||
.write_string(max_memory_path, &(max_memory_bytes / 1024).to_string())
|
|
||||||
.await?;
|
.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);
|
let target_memory_path = format!("{}/memory/target", domain_path);
|
||||||
self.context
|
tx.write_string(
|
||||||
.xen
|
target_memory_path,
|
||||||
.store
|
&(target_memory_bytes / 1024).to_string(),
|
||||||
.write_string(
|
)
|
||||||
target_memory_path,
|
.await?;
|
||||||
&(target_memory_bytes / 1024).to_string(),
|
tx.commit().await?;
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ use xencall::XenCall;
|
|||||||
|
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
|
|
||||||
|
pub const XEN_EXTRA_MEMORY_KB: u64 = 2048;
|
||||||
|
|
||||||
pub struct BaseDomainManager<P: BootSetupPlatform> {
|
pub struct BaseDomainManager<P: BootSetupPlatform> {
|
||||||
call: XenCall,
|
call: XenCall,
|
||||||
pub platform: Arc<P>,
|
pub platform: Arc<P>,
|
||||||
@ -29,7 +31,7 @@ impl<P: BootSetupPlatform> BaseDomainManager<P> {
|
|||||||
let domid = self.call.create_domain(domain).await?;
|
let domid = self.call.create_domain(domain).await?;
|
||||||
self.call.set_max_vcpus(domid, config.max_vcpus).await?;
|
self.call.set_max_vcpus(domid, config.max_vcpus).await?;
|
||||||
self.call
|
self.call
|
||||||
.set_max_mem(domid, (config.max_mem_mb * 1024) + 2048)
|
.set_max_mem(domid, (config.max_mem_mb * 1024) + XEN_EXTRA_MEMORY_KB)
|
||||||
.await?;
|
.await?;
|
||||||
let loader = ElfImageLoader::load_file_kernel(&config.kernel)?;
|
let loader = ElfImageLoader::load_file_kernel(&config.kernel)?;
|
||||||
let platform = (*self.platform).clone();
|
let platform = (*self.platform).clone();
|
||||||
|
Reference in New Issue
Block a user