mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-05 03:21:13 +00:00
vmm: Add "prefault" option when restoring
Now that the restore path uses RestoreConfig structure, we add a new parameter called "prefault" to it. This will give the user the ability to populate the pages corresponding to the mapped regions backed by the snapshotted memory files. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
a517ca23a0
commit
8d9d22436a
@ -1117,23 +1117,34 @@ impl VsockConfig {
|
|||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct RestoreConfig {
|
pub struct RestoreConfig {
|
||||||
pub source_url: PathBuf,
|
pub source_url: PathBuf,
|
||||||
|
#[serde(default)]
|
||||||
|
pub prefault: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RestoreConfig {
|
impl RestoreConfig {
|
||||||
pub const SYNTAX: &'static str = "Restore from a VM snapshot. \
|
pub const SYNTAX: &'static str = "Restore from a VM snapshot. \
|
||||||
Restore parameters \"source_url=<source_url>\" \
|
\nRestore parameters \"source_url=<source_url>,prefault=on|off\" \
|
||||||
source_url should be a valid URL (e.g file:///foo/bar or tcp://192.168.1.10/foo)";
|
\n`source_url` should be a valid URL (e.g file:///foo/bar or tcp://192.168.1.10/foo) \
|
||||||
|
\n`prefault` brings memory pages in when enabled (disabled by default)";
|
||||||
pub fn parse(restore: &str) -> Result<Self> {
|
pub fn parse(restore: &str) -> Result<Self> {
|
||||||
let mut parser = OptionParser::new();
|
let mut parser = OptionParser::new();
|
||||||
parser.add("source_url");
|
parser.add("source_url").add("prefault");
|
||||||
parser.parse(restore).map_err(Error::ParseRestore)?;
|
parser.parse(restore).map_err(Error::ParseRestore)?;
|
||||||
|
|
||||||
let source_url = parser
|
let source_url = parser
|
||||||
.get("source_url")
|
.get("source_url")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.ok_or(Error::ParseRestoreSourceUrlMissing)?;
|
.ok_or(Error::ParseRestoreSourceUrlMissing)?;
|
||||||
|
let prefault = parser
|
||||||
|
.convert::<Toggle>("prefault")
|
||||||
|
.map_err(Error::ParseRestore)?
|
||||||
|
.unwrap_or(Toggle(false))
|
||||||
|
.0;
|
||||||
|
|
||||||
Ok(RestoreConfig { source_url })
|
Ok(RestoreConfig {
|
||||||
|
source_url,
|
||||||
|
prefault,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,6 +331,7 @@ impl Vmm {
|
|||||||
reset_evt,
|
reset_evt,
|
||||||
self.vmm_path.clone(),
|
self.vmm_path.clone(),
|
||||||
source_url,
|
source_url,
|
||||||
|
restore_cfg.prefault,
|
||||||
)?;
|
)?;
|
||||||
self.vm = Some(vm);
|
self.vm = Some(vm);
|
||||||
|
|
||||||
|
@ -387,6 +387,7 @@ impl MemoryManager {
|
|||||||
fd: Arc<VmFd>,
|
fd: Arc<VmFd>,
|
||||||
config: &MemoryConfig,
|
config: &MemoryConfig,
|
||||||
source_url: &str,
|
source_url: &str,
|
||||||
|
prefault: bool,
|
||||||
) -> Result<Arc<Mutex<MemoryManager>>, Error> {
|
) -> Result<Arc<Mutex<MemoryManager>>, Error> {
|
||||||
let url = Url::parse(source_url).unwrap();
|
let url = Url::parse(source_url).unwrap();
|
||||||
/* url must be valid dir which is verified in recv_vm_snapshot() */
|
/* url must be valid dir which is verified in recv_vm_snapshot() */
|
||||||
@ -419,7 +420,7 @@ impl MemoryManager {
|
|||||||
// allows for a faster VM restoration and does not require us to
|
// allows for a faster VM restoration and does not require us to
|
||||||
// fill the memory content, hence we can return right away.
|
// fill the memory content, hence we can return right away.
|
||||||
if config.file.is_none() {
|
if config.file.is_none() {
|
||||||
return MemoryManager::new(fd, config, Some(ext_regions), false);
|
return MemoryManager::new(fd, config, Some(ext_regions), prefault);
|
||||||
};
|
};
|
||||||
|
|
||||||
let memory_manager = MemoryManager::new(fd, config, None, false)?;
|
let memory_manager = MemoryManager::new(fd, config, None, false)?;
|
||||||
|
@ -388,6 +388,7 @@ impl Vm {
|
|||||||
reset_evt: EventFd,
|
reset_evt: EventFd,
|
||||||
vmm_path: PathBuf,
|
vmm_path: PathBuf,
|
||||||
source_url: &str,
|
source_url: &str,
|
||||||
|
prefault: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let (kvm, fd) = Vm::kvm_new()?;
|
let (kvm, fd) = Vm::kvm_new()?;
|
||||||
let config = vm_config_from_snapshot(snapshot).map_err(Error::Restore)?;
|
let config = vm_config_from_snapshot(snapshot).map_err(Error::Restore)?;
|
||||||
@ -400,6 +401,7 @@ impl Vm {
|
|||||||
fd.clone(),
|
fd.clone(),
|
||||||
&config.lock().unwrap().memory.clone(),
|
&config.lock().unwrap().memory.clone(),
|
||||||
source_url,
|
source_url,
|
||||||
|
prefault,
|
||||||
)
|
)
|
||||||
.map_err(Error::MemoryManager)?
|
.map_err(Error::MemoryManager)?
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user