vmm, main: Add optional "hotplug_size" to --mem

This specifies how much address space should be reserved for hotplugging
of RAM. This space is reserved by adding move the start of the device
area by the desired amount.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-01-07 11:25:55 +00:00 committed by Samuel Ortiz
parent f1b6657833
commit f5137e84bb
4 changed files with 21 additions and 2 deletions

View File

@ -94,7 +94,8 @@ fn create_app<'a, 'b>(
.long("memory")
.help(
"Memory parameters \"size=<guest_memory_size>,\
file=<backing_file_path>,mergeable=on|off\"",
file=<backing_file_path>,mergeable=on|off,\
hotplug_size=<hotpluggable_memory_size>\"",
)
.default_value(&default_memory)
.group("vm-config"),
@ -451,6 +452,7 @@ mod unit_tests {
size: 536_870_912,
file: None,
mergeable: false,
hotplug_size: None,
},
kernel: None,
cmdline: CmdlineConfig {

View File

@ -248,6 +248,8 @@ pub struct MemoryConfig {
pub file: Option<PathBuf>,
#[serde(default)]
pub mergeable: bool,
#[serde(default)]
pub hotplug_size: Option<u64>,
}
impl MemoryConfig {
@ -259,6 +261,7 @@ impl MemoryConfig {
let mut file_str: &str = "";
let mut mergeable_str: &str = "";
let mut backed = false;
let mut hotplug_str: &str = "";
for param in params_list.iter() {
if param.starts_with("size=") {
@ -268,6 +271,8 @@ impl MemoryConfig {
file_str = &param[5..];
} else if param.starts_with("mergeable=") {
mergeable_str = &param[10..];
} else if param.starts_with("hotplug_size=") {
hotplug_str = &param[13..]
}
}
@ -285,6 +290,11 @@ impl MemoryConfig {
size: parse_size(size_str)?,
file,
mergeable: parse_on_off(mergeable_str)?,
hotplug_size: if hotplug_str == "" {
None
} else {
Some(parse_size(hotplug_str)?)
},
})
}
}
@ -295,6 +305,7 @@ impl Default for MemoryConfig {
size: DEFAULT_MEMORY_MB << 20,
file: None,
mergeable: false,
hotplug_size: None,
}
}
}

View File

@ -81,6 +81,7 @@ impl MemoryManager {
allocator: Arc<Mutex<SystemAllocator>>,
fd: Arc<VmFd>,
boot_ram: u64,
hotplug_size: Option<u64>,
backing_file: &Option<PathBuf>,
mergeable: bool,
) -> Result<Arc<Mutex<MemoryManager>>, Error> {
@ -107,12 +108,16 @@ impl MemoryManager {
let end_of_device_area = GuestAddress((1 << get_host_cpu_phys_bits()) - 1);
let mem_end = guest_memory.end_addr();
let start_of_device_area = if mem_end < arch::layout::MEM_32BIT_RESERVED_START {
let mut start_of_device_area = if mem_end < arch::layout::MEM_32BIT_RESERVED_START {
arch::layout::RAM_64BIT_START
} else {
mem_end.unchecked_add(1)
};
if let Some(size) = hotplug_size {
start_of_device_area = start_of_device_area.unchecked_add(size);
}
let guest_memory = Arc::new(ArcSwap::new(Arc::new(guest_memory)));
let memory_manager = Arc::new(Mutex::new(MemoryManager {

View File

@ -309,6 +309,7 @@ impl Vm {
allocator.clone(),
fd.clone(),
memory_config.size,
memory_config.hotplug_size,
&memory_config.file,
memory_config.mergeable,
)