Refine CrosvmConfig balloon filed setting logic
This CL makes CrosvmConfig's balloon field represent the correct balloon
enable status. Previously, whether to use balloon or not is defined in
run_vm() function. The vm may disable balloon even if config.balloon is
true. This logic is moved to before initializing CrosvmConfig.
Addtionally, this change introduces an API isMemoryBalloonEnabled() to
check if memory ballooning is enabled for a given VM.
Bug: b/392791968
Test: test with https://r.android.com/3502917
Change-Id: I79f722800aa9a6ed90e8455d185398bc4292b094
diff --git a/android/virtmgr/src/aidl.rs b/android/virtmgr/src/aidl.rs
index 3c5408c..fcc6181 100644
--- a/android/virtmgr/src/aidl.rs
+++ b/android/virtmgr/src/aidl.rs
@@ -935,6 +935,20 @@
})
.collect::<binder::Result<_>>()?;
+ let memory_reclaim_supported =
+ system_properties::read_bool("hypervisor.memory_reclaim.supported", false)
+ .unwrap_or(false);
+
+ let balloon = config.balloon && memory_reclaim_supported;
+
+ if !balloon {
+ warn!(
+ "Memory balloon not enabled:
+ config.balloon={},hypervisor.memory_reclaim.supported={}",
+ config.balloon, memory_reclaim_supported
+ );
+ }
+
// Actually start the VM.
let crosvm_config = CrosvmConfig {
cid,
@@ -974,7 +988,7 @@
boost_uclamp: config.boostUclamp,
gpu_config,
audio_config,
- balloon: config.balloon,
+ balloon,
usb_config,
dump_dt_fd,
enable_hypervisor_specific_auth_method: config.enableHypervisorSpecificAuthMethod,
@@ -1730,6 +1744,10 @@
.or_service_specific_exception(-1)
}
+ fn isMemoryBalloonEnabled(&self) -> binder::Result<bool> {
+ Ok(self.instance.balloon_enabled)
+ }
+
fn getMemoryBalloon(&self) -> binder::Result<i64> {
let balloon = self
.instance