-
Couldn't load subscription status.
- Fork 2.1k
[virtio-mem] Dynamic slots and performance tests #5490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/virtio-mem
Are you sure you want to change the base?
Changes from all commits
df8c61f
1ae1596
16eaf6f
555135e
f0edf49
45d927e
f272beb
c926344
c76904f
fd6bcff
25fa432
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,9 @@ use crate::devices::virtio::transport::{VirtioInterrupt, VirtioInterruptType}; | |
| use crate::logger::{IncMetric, debug, error}; | ||
| use crate::utils::{bytes_to_mib, mib_to_bytes, u64_to_usize, usize_to_u64}; | ||
| use crate::vstate::interrupts::InterruptError; | ||
| use crate::vstate::memory::{ByteValued, GuestMemoryExtension, GuestMemoryMmap, GuestRegionMmap}; | ||
| use crate::vstate::memory::{ | ||
| ByteValued, GuestMemoryExtension, GuestMemoryMmap, GuestRegionMmap, GuestRegionType, | ||
| }; | ||
| use crate::vstate::vm::VmError; | ||
| use crate::{Vm, impl_device_type}; | ||
|
|
||
|
|
@@ -76,6 +78,8 @@ pub enum VirtioMemError { | |
| PlugRequestIsTooBig, | ||
| /// The requested range cannot be unplugged because it's {0:?}. | ||
| UnplugRequestBlockStateInvalid(BlockRangeState), | ||
| /// There was an error updating the KVM slot. | ||
| UpdateKvmSlot(VmError), | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
|
|
@@ -501,6 +505,32 @@ impl VirtioMem { | |
| &self.activate_event | ||
| } | ||
|
|
||
| fn update_kvm_slots(&self, updated_range: &RequestedRange) -> Result<(), VirtioMemError> { | ||
| let hp_region = self | ||
| .guest_memory() | ||
| .iter() | ||
| .find(|r| r.region_type == GuestRegionType::Hotpluggable) | ||
| .expect("there should be one and only one hotpluggable region"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do we verify it's the only one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not verified, if there are multiple it's gonna return the first one. I specified it in the same sentence because I didn't want to leave a separate comment. |
||
| hp_region | ||
| .slots_intersecting_range( | ||
| updated_range.addr, | ||
| self.nb_blocks_to_len(updated_range.nb_blocks), | ||
| ) | ||
| .try_for_each(|slot| { | ||
| let slot_range = RequestedRange { | ||
| addr: slot.guest_addr, | ||
| nb_blocks: slot.slice.len() / u64_to_usize(self.config.block_size), | ||
| }; | ||
| match self.range_state(&slot_range) { | ||
| BlockRangeState::Mixed | BlockRangeState::Plugged => { | ||
| hp_region.update_slot(&self.vm, slot.slot, true) | ||
| } | ||
| BlockRangeState::Unplugged => hp_region.update_slot(&self.vm, slot.slot, false), | ||
| } | ||
| .map_err(VirtioMemError::UpdateKvmSlot) | ||
| }) | ||
| } | ||
|
|
||
| /// Plugs/unplugs the given range | ||
| /// | ||
| /// Note: the range passed to this function must be within the device memory to avoid | ||
|
|
@@ -527,9 +557,7 @@ impl VirtioMem { | |
| }); | ||
| } | ||
|
|
||
| // TODO: update KVM slots to plug/unplug them | ||
|
|
||
| Ok(()) | ||
| self.update_kvm_slots(range) | ||
| } | ||
|
|
||
| /// Updates the requested size of the virtio-mem device. | ||
|
|
@@ -692,6 +720,7 @@ pub(crate) mod test_utils { | |
| .unwrap() | ||
| .pop() | ||
| .unwrap(), | ||
| mib_to_bytes(128), | ||
| ); | ||
| let vm = Arc::new(vm); | ||
| VirtioMem::new(vm, addr, 1024, 2, 128).unwrap() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can explain why we need it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack