Determine CompOS VM size from properties
Rather than hard-wiring the max VM size, use properties to allow ART
to specify how much is needed by the current ART version, and the
hypervisor provider to specify an adjustment to it.
Previously we set the maximum to 1 GiB, in an attempt to allow for
future growth. Instead set the default in the absence of information
from ART to 400 MiB, which is sufficient for current versions with a
small amount of additional headroom.
Bug: 274597466
Test: atest ComposHostTestCases
Test: manual: set bad values, see errors
Change-Id: Ibd98b670c2ee800064f8069b64ffa9fd160b7446
diff --git a/compos/composd/src/instance_manager.rs b/compos/composd/src/instance_manager.rs
index 98d4a1b..2ce12f8 100644
--- a/compos/composd/src/instance_manager.rs
+++ b/compos/composd/src/instance_manager.rs
@@ -19,16 +19,16 @@
use crate::instance_starter::{CompOsInstance, InstanceStarter};
use android_system_virtualizationservice::aidl::android::system::virtualizationservice;
-use anyhow::{bail, Result};
+use anyhow::{anyhow, bail, Context, Result};
use binder::Strong;
use compos_common::compos_client::{VmCpuTopology, VmParameters};
use compos_common::{CURRENT_INSTANCE_DIR, TEST_INSTANCE_DIR};
+use log::info;
+use rustutils::system_properties;
+use std::str::FromStr;
use std::sync::{Arc, Mutex, Weak};
use virtualizationservice::IVirtualizationService::IVirtualizationService;
-// Enough memory to complete odrefresh in the VM.
-const VM_MEMORY_MIB: i32 = 1024;
-
pub struct InstanceManager {
service: Strong<dyn IVirtualizationService>,
state: Mutex<State>,
@@ -81,12 +81,33 @@
// number of dex2oat threads.
let cpu_topology = VmCpuTopology::MatchHost;
let task_profiles = vec!["SCHED_SP_COMPUTE".to_string()];
- Ok(VmParameters {
- cpu_topology,
- task_profiles,
- memory_mib: Some(VM_MEMORY_MIB),
- ..Default::default()
- })
+ let memory_mib = Some(compos_memory_mib()?);
+ Ok(VmParameters { cpu_topology, task_profiles, memory_mib, ..Default::default() })
+}
+
+fn compos_memory_mib() -> Result<i32> {
+ // Enough memory to complete odrefresh in the VM, for older versions of ART that don't set the
+ // property explicitly.
+ const DEFAULT_MEMORY_MIB: u32 = 400;
+
+ let art_requested_mib =
+ read_property("composd.vm.art.memory_mib.config")?.unwrap_or(DEFAULT_MEMORY_MIB);
+
+ let vm_adjustment_mib = read_property("composd.vm.vendor.memory_mib.config")?.unwrap_or(0);
+
+ info!(
+ "Compilation VM memory: ART requests {art_requested_mib} MiB, \
+ VM adjust is {vm_adjustment_mib}"
+ );
+ art_requested_mib
+ .checked_add_signed(vm_adjustment_mib)
+ .and_then(|x| x.try_into().ok())
+ .context("Invalid vm memory adjustment")
+}
+
+fn read_property<T: FromStr>(name: &str) -> Result<Option<T>> {
+ let str = system_properties::read(name).context("Failed to read {name}")?;
+ str.map(|s| s.parse().map_err(|_| anyhow!("Invalid {name}: {s}"))).transpose()
}
// Ensures we only run one instance at a time.