mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-23 08:21:15 +00:00
vmm: memory_manager: Only file back memory when required
If we do not need an anonymous file backing the memory then do not create one. As a side effect this addresses an issue with CoW (mmap with MAP_PRIVATE but no MAP_ANONYMOUS) when the memory is pinned for VFIO. Fixes: #4805 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
1e5a4e8d77
commit
df7c728399
@ -1303,8 +1303,10 @@ impl MemoryManager {
|
|||||||
Some(FileOffset::new(f, file_offset))
|
Some(FileOffset::new(f, file_offset))
|
||||||
} else if let Some(backing_file) = backing_file {
|
} else if let Some(backing_file) = backing_file {
|
||||||
Some(Self::open_backing_file(backing_file, file_offset, size)?)
|
Some(Self::open_backing_file(backing_file, file_offset, size)?)
|
||||||
} else {
|
} else if shared || hugepages {
|
||||||
Some(Self::create_anonymous_file(size, hugepages, hugepage_size)?)
|
Some(Self::create_anonymous_file(size, hugepages, hugepage_size)?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut mmap_flags = libc::MAP_NORESERVE
|
let mut mmap_flags = libc::MAP_NORESERVE
|
||||||
@ -1317,6 +1319,10 @@ impl MemoryManager {
|
|||||||
mmap_flags |= libc::MAP_POPULATE;
|
mmap_flags |= libc::MAP_POPULATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fo.is_none() {
|
||||||
|
mmap_flags |= libc::MAP_ANONYMOUS;
|
||||||
|
}
|
||||||
|
|
||||||
let region = GuestRegionMmap::new(
|
let region = GuestRegionMmap::new(
|
||||||
MmapRegion::build(fo, size, libc::PROT_READ | libc::PROT_WRITE, mmap_flags)
|
MmapRegion::build(fo, size, libc::PROT_READ | libc::PROT_WRITE, mmap_flags)
|
||||||
.map_err(Error::GuestMemoryRegion)?,
|
.map_err(Error::GuestMemoryRegion)?,
|
||||||
|
Loading…
Reference in New Issue
Block a user