mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-04 04:25:45 +00:00
vmm: memory: Add Copy-on-Write parameter when creating region
Now that we can choose specific mmap flags for the guest RAM, we create a new parameter "copy_on_write" meaning that the memory mappings backed by a file should be performed with MAP_PRIVATE instead of MAP_SHARED. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
be4e1e8712
commit
ee5a041a0f
@ -237,6 +237,7 @@ impl MemoryManager {
|
|||||||
&config.file,
|
&config.file,
|
||||||
region.0,
|
region.0,
|
||||||
region.1,
|
region.1,
|
||||||
|
false,
|
||||||
)?);
|
)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,6 +264,7 @@ impl MemoryManager {
|
|||||||
&config.file,
|
&config.file,
|
||||||
start_addr,
|
start_addr,
|
||||||
size as usize,
|
size as usize,
|
||||||
|
false,
|
||||||
)?);
|
)?);
|
||||||
|
|
||||||
virtiomem_resize = Some(vm_virtio::Resize::new().map_err(Error::EventFdFail)?);
|
virtiomem_resize = Some(vm_virtio::Resize::new().map_err(Error::EventFdFail)?);
|
||||||
@ -415,6 +417,7 @@ impl MemoryManager {
|
|||||||
backing_file: &Option<PathBuf>,
|
backing_file: &Option<PathBuf>,
|
||||||
start_addr: GuestAddress,
|
start_addr: GuestAddress,
|
||||||
size: usize,
|
size: usize,
|
||||||
|
copy_on_write: bool,
|
||||||
) -> Result<Arc<GuestRegionMmap>, Error> {
|
) -> Result<Arc<GuestRegionMmap>, Error> {
|
||||||
Ok(Arc::new(match backing_file {
|
Ok(Arc::new(match backing_file {
|
||||||
Some(ref file) => {
|
Some(ref file) => {
|
||||||
@ -436,7 +439,11 @@ impl MemoryManager {
|
|||||||
|
|
||||||
f.set_len(size as u64).map_err(Error::SharedFileSetLen)?;
|
f.set_len(size as u64).map_err(Error::SharedFileSetLen)?;
|
||||||
|
|
||||||
let mmap_flags = libc::MAP_NORESERVE | libc::MAP_SHARED;
|
let mmap_flags = if copy_on_write {
|
||||||
|
libc::MAP_NORESERVE | libc::MAP_PRIVATE
|
||||||
|
} else {
|
||||||
|
libc::MAP_NORESERVE | libc::MAP_SHARED
|
||||||
|
};
|
||||||
GuestRegionMmap::new(
|
GuestRegionMmap::new(
|
||||||
MmapRegion::build(
|
MmapRegion::build(
|
||||||
Some(FileOffset::new(f, 0)),
|
Some(FileOffset::new(f, 0)),
|
||||||
@ -497,7 +504,7 @@ impl MemoryManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allocate memory for the region
|
// Allocate memory for the region
|
||||||
let region = MemoryManager::create_ram_region(&self.backing_file, start_addr, size)?;
|
let region = MemoryManager::create_ram_region(&self.backing_file, start_addr, size, false)?;
|
||||||
|
|
||||||
// Map it into the guest
|
// Map it into the guest
|
||||||
self.create_userspace_mapping(
|
self.create_userspace_mapping(
|
||||||
|
Loading…
Reference in New Issue
Block a user