vmm: Move balloon code from MemoryManager to DeviceManager

Now that we have a new dedicated way of asking for a balloon through the
CLI and the REST API, we can move all the balloon code to the device
manager. This allows us to simplify the memory manager, which is already
quite complex.

It also simplifies the behavior of the balloon resizing command. Instead
of providing the expected size for the RAM, which is complex when memory
zones are involved, it now expects the balloon size. This is a much more
straightforward behavior as it really resizes the balloon to the desired
size. Additionally to the simplication, the benefit of this approach is
that it does not need to be tied to the memory manager at all.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-10-14 12:04:42 +02:00
parent 1d479e5e08
commit 3594685279
6 changed files with 55 additions and 57 deletions

View File

@@ -117,7 +117,6 @@ pub struct MemoryManager {
snapshot: Mutex<Option<GuestMemoryLoadGuard<GuestMemoryMmap>>>,
shared: bool,
hugepages: bool,
balloon: Option<Arc<Mutex<virtio_devices::Balloon>>>,
#[cfg(target_arch = "x86_64")]
sgx_epc_region: Option<SgxEpcRegion>,
user_provided_zones: bool,
@@ -176,9 +175,6 @@ pub enum Error {
/// memory regions.
InvalidAmountExternalBackingFiles,
/// Failed to virtio-balloon resize
VirtioBalloonResizeFail(virtio_devices::balloon::Error),
/// Invalid SGX EPC section size
#[cfg(target_arch = "x86_64")]
EpcSectionSizeInvalid,
@@ -688,7 +684,6 @@ impl MemoryManager {
snapshot: Mutex::new(None),
shared: config.shared,
hugepages: config.hugepages,
balloon: None,
#[cfg(target_arch = "x86_64")]
sgx_epc_region: None,
user_provided_zones,
@@ -1085,10 +1080,6 @@ impl MemoryManager {
Ok(region)
}
pub fn set_balloon(&mut self, balloon: Arc<Mutex<virtio_devices::Balloon>>) {
self.balloon = Some(balloon);
}
pub fn guest_memory(&self) -> GuestMemoryAtomic<GuestMemoryMmap> {
self.guest_memory.clone()
}
@@ -1242,30 +1233,6 @@ impl MemoryManager {
Err(Error::UnknownMemoryZone)
}
pub fn balloon_resize(&mut self, expected_ram: u64) -> Result<u64, Error> {
let mut balloon_size = 0;
if let Some(balloon) = &self.balloon {
if expected_ram < self.current_ram {
balloon_size = self.current_ram - expected_ram;
}
balloon
.lock()
.unwrap()
.resize(balloon_size)
.map_err(Error::VirtioBalloonResizeFail)?;
}
Ok(balloon_size)
}
pub fn get_balloon_actual(&self) -> u64 {
if let Some(balloon) = &self.balloon {
return balloon.lock().unwrap().get_actual();
}
0
}
/// In case this function resulted in adding a new memory region to the
/// guest memory, the new region is returned to the caller. The virtio-mem
/// use case never adds a new region as the whole hotpluggable memory has