Struct swap::controller::SwapController
source · pub struct SwapController {
child_process: Option<Child>,
uffd_factory: Factory,
command_tube: Tube,
num_static_devices: u32,
_dead_uffd_checker: DeadUffdCheckerImpl,
_guest_memory: GuestMemory,
}
Expand description
SwapController provides APIs to control vmm-swap.
Fields§
§child_process: Option<Child>
§uffd_factory: Factory
§command_tube: Tube
§num_static_devices: u32
§_dead_uffd_checker: DeadUffdCheckerImpl
§_guest_memory: GuestMemory
Implementations§
source§impl SwapController
impl SwapController
sourcepub fn launch(
guest_memory: GuestMemory,
swap_dir: &Path,
jail_config: &Option<JailConfig>
) -> Result<Self>
pub fn launch( guest_memory: GuestMemory, swap_dir: &Path, jail_config: &Option<JailConfig> ) -> Result<Self>
Launch a monitor process for vmm-swap and return a controller.
Pages on the [GuestMemory] are registered to userfaultfd to track pagefault events.
§Arguments
guest_memory
- fresh new [GuestMemory]. Any pages on the [GuestMemory] must not be touched.swap_dir
- directory to store swap files.
sourcepub fn enable(&self) -> Result<()>
pub fn enable(&self) -> Result<()>
Enable monitoring page faults and move guest memory to staging memory.
The pages will be swapped in from the staging memory to the guest memory on page faults until pages are written into the swap file by Self::swap_out().
This waits until enabling vmm-swap finishes on the monitor process.
The caller must guarantee that any contents on the guest memory is not updated during enabling vmm-swap.
§Note
Enabling does not write pages to the swap file. User should call Self::swap_out() after a suitable time.
Just after enabling vmm-swap, some amount of pages are swapped in as soon as guest resumes. By splitting the enable/swap_out operation and by delaying write to the swap file operation, it has a benefit of reducing file I/O for hot pages.
sourcepub fn trim(&self) -> Result<()>
pub fn trim(&self) -> Result<()>
Trim pages in the staging memory which are needless to be written back to the swap file.
- zero pages
- pages which are the same as the pages in the swap file.
sourcepub fn swap_out(&self) -> Result<()>
pub fn swap_out(&self) -> Result<()>
Swap out all the pages in the staging memory to the swap files.
This returns as soon as it succeeds to send request to the monitor process.
Users should call Self::enable() before this. See the comment of Self::enable() as well.
sourcepub fn disable(&self, slow_file_cleanup: bool) -> Result<()>
pub fn disable(&self, slow_file_cleanup: bool) -> Result<()>
Swap in all the guest memory and disable monitoring page faults.
This returns as soon as it succeeds to send request to the monitor process.
sourcepub fn status(&self) -> Result<SwapStatus>
pub fn status(&self) -> Result<SwapStatus>
Return current swap status.
This blocks until response from the monitor process arrives to the main process.
sourcepub fn suspend_devices(&self) -> Result<ProcessesGuard>
pub fn suspend_devices(&self) -> Result<ProcessesGuard>
Suspend device processes using SIGSTOP
signal.
When the returned ProcessesGuard
is dropped, the devices resume.
This must be called from the main process.
sourcepub fn on_static_devices_setup_complete(&self) -> Result<()>
pub fn on_static_devices_setup_complete(&self) -> Result<()>
Notify the monitor process that all static devices are forked.
Devices forked after this call are treated as dynamic devices which can die (e.g. hotplug devices).
sourcepub fn create_device_helper(&self) -> Result<SwapDeviceHelper>
pub fn create_device_helper(&self) -> Result<SwapDeviceHelper>
Create SwapDeviceHelper.
Trait Implementations§
source§impl Drop for SwapController
impl Drop for SwapController
source§impl PrepareFork for SwapController
impl PrepareFork for SwapController
source§fn prepare_fork(&mut self) -> Result<SwapDeviceUffdSender>
fn prepare_fork(&mut self) -> Result<SwapDeviceUffdSender>
Create a new SwapDeviceUffdSender.
This should be called from the main process because creating a [Tube]s requires seccomp policy.
This also counts the number of static devices which are created before booting.