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

source

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.
source

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.

source

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.
source

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.

source

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.

source

pub fn status(&self) -> Result<SwapStatus>

Return current swap status.

This blocks until response from the monitor process arrives to the main process.

source

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.

source

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).

source

pub fn create_device_helper(&self) -> Result<SwapDeviceHelper>

Trait Implementations§

source§

impl Drop for SwapController

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl PrepareFork for SwapController

source§

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.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.