mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-02 11:35:46 +00:00
vmm: Create a MemoryZone structure
In order to anticipate the need for storing memory regions along with virtio-mem information for each memory zone, we create a new structure MemoryZone that will replace Vec<Arc<GuestRegionMmap>> in the hash map MemoryZones. This makes thing more logical as MemoryZones becomes a list of MemoryZone sorted by their identifier. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
27c28fa3b0
commit
b173b6c5b4
@ -64,7 +64,26 @@ struct HotPlugState {
|
|||||||
removing: bool,
|
removing: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type MemoryZones = HashMap<String, Vec<Arc<GuestRegionMmap>>>;
|
#[derive(Default)]
|
||||||
|
pub struct MemoryZone {
|
||||||
|
regions: Vec<Arc<GuestRegionMmap>>,
|
||||||
|
virtiomem_region: Option<Arc<GuestRegionMmap>>,
|
||||||
|
virtiomem_resize: Option<virtio_devices::Resize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MemoryZone {
|
||||||
|
pub fn regions(&self) -> &Vec<Arc<GuestRegionMmap>> {
|
||||||
|
&self.regions
|
||||||
|
}
|
||||||
|
pub fn virtiomem_region(&self) -> &Option<Arc<GuestRegionMmap>> {
|
||||||
|
&self.virtiomem_region
|
||||||
|
}
|
||||||
|
pub fn virtiomem_resize(&self) -> &Option<virtio_devices::Resize> {
|
||||||
|
&self.virtiomem_resize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type MemoryZones = HashMap<String, MemoryZone>;
|
||||||
|
|
||||||
pub struct MemoryManager {
|
pub struct MemoryManager {
|
||||||
guest_memory: GuestMemoryAtomic<GuestMemoryMmap>,
|
guest_memory: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||||
@ -300,7 +319,7 @@ impl MemoryManager {
|
|||||||
let mut memory_zones = HashMap::new();
|
let mut memory_zones = HashMap::new();
|
||||||
|
|
||||||
// Add zone id to the list of memory zones.
|
// Add zone id to the list of memory zones.
|
||||||
memory_zones.insert(zone.id.clone(), Vec::new());
|
memory_zones.insert(zone.id.clone(), MemoryZone::default());
|
||||||
|
|
||||||
for ram_region in ram_regions.iter() {
|
for ram_region in ram_regions.iter() {
|
||||||
let mut ram_region_offset = 0;
|
let mut ram_region_offset = 0;
|
||||||
@ -346,7 +365,7 @@ impl MemoryManager {
|
|||||||
// Add region to the list of regions associated with the
|
// Add region to the list of regions associated with the
|
||||||
// current memory zone.
|
// current memory zone.
|
||||||
if let Some(memory_zone) = memory_zones.get_mut(&zone.id) {
|
if let Some(memory_zone) = memory_zones.get_mut(&zone.id) {
|
||||||
memory_zone.push(region.clone());
|
memory_zone.regions.push(region.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
mem_regions.push(region);
|
mem_regions.push(region);
|
||||||
@ -371,7 +390,7 @@ impl MemoryManager {
|
|||||||
);
|
);
|
||||||
return Err(Error::DuplicateZoneId);
|
return Err(Error::DuplicateZoneId);
|
||||||
}
|
}
|
||||||
memory_zones.insert(zone.id.clone(), Vec::new());
|
memory_zones.insert(zone.id.clone(), MemoryZone::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ram_region_consumed {
|
if ram_region_consumed {
|
||||||
|
@ -404,7 +404,7 @@ impl Vm {
|
|||||||
if let Some(memory_zones) = &config.memory_zones {
|
if let Some(memory_zones) = &config.memory_zones {
|
||||||
for memory_zone in memory_zones.iter() {
|
for memory_zone in memory_zones.iter() {
|
||||||
if let Some(mm_zone) = mm_zones.get(memory_zone) {
|
if let Some(mm_zone) = mm_zones.get(memory_zone) {
|
||||||
node.memory_regions.extend(mm_zone.clone());
|
node.memory_regions.extend(mm_zone.regions().clone());
|
||||||
} else {
|
} else {
|
||||||
error!("Unknown memory zone '{}'", memory_zone);
|
error!("Unknown memory zone '{}'", memory_zone);
|
||||||
return Err(Error::InvalidNumaConfig);
|
return Err(Error::InvalidNumaConfig);
|
||||||
|
Loading…
Reference in New Issue
Block a user