Use default VM memory size except when compiling

The effect of this is that the VM started by compos_verify is smaller,
as well as only using 1 CPU. (It does very little, so this should be
fine.)

And that should reduce its impact on boot time.

Compilation: "--mem" "1024" "--cpus" "8"
Verification: "--mem" "1024" "--cpus" "8"

Bug: 220824234
Test: staged-apex-compile, reboot, check logs.
Change-Id: I1101965fb532abe7923ec133920d62f5eacfd108
diff --git a/compos/common/compos_client.rs b/compos/common/compos_client.rs
index 63a6fd6..072b90b 100644
--- a/compos/common/compos_client.rs
+++ b/compos/common/compos_client.rs
@@ -47,9 +47,6 @@
 use std::sync::{Arc, Condvar, Mutex};
 use std::thread;
 
-// Enough memory to complete odrefresh in the VM.
-const VM_MEMORY_MIB: i32 = 1024;
-
 /// This owns an instance of the CompOS VM.
 pub struct VmInstance {
     #[allow(dead_code)] // Keeps the VM alive even if we don`t touch it
@@ -69,6 +66,8 @@
     pub cpu_set: Option<String>,
     /// If present, overrides the path to the VM config JSON file
     pub config_path: Option<String>,
+    /// If present, overrides the amount of RAM to give the VM
+    pub memory_mib: Option<i32>,
 }
 
 impl VmInstance {
@@ -127,7 +126,7 @@
             debugLevel: debug_level,
             extraIdsigs: vec![idsig_manifest_apk_fd],
             protectedVm: protected_vm,
-            memoryMib: VM_MEMORY_MIB,
+            memoryMib: parameters.memory_mib.unwrap_or(0), // 0 means use the default
             numCpus: parameters.cpus.map_or(1, NonZeroU32::get) as i32,
             cpuAffinity: parameters.cpu_set.clone(),
         });
diff --git a/compos/composd/src/instance_manager.rs b/compos/composd/src/instance_manager.rs
index f1289e8..587314c 100644
--- a/compos/composd/src/instance_manager.rs
+++ b/compos/composd/src/instance_manager.rs
@@ -32,6 +32,9 @@
 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>,
@@ -95,7 +98,7 @@
         }
     };
     let cpu_set = system_properties::read(DEX2OAT_CPU_SET_PROP_NAME)?;
-    Ok(VmParameters { cpus, cpu_set, ..Default::default() })
+    Ok(VmParameters { cpus, cpu_set, memory_mib: Some(VM_MEMORY_MIB), ..Default::default() })
 }
 
 // Ensures we only run one instance at a time.