pub struct SwapController {
    child_process: Child,
    uffd_factory: UffdFactory,
    command_tube: Tube,
    num_static_devices: u32,
    _dead_uffd_checker: DeadUffdCheckerImpl,
}
Expand description

SwapController provides APIs to control vmm-swap.

Fields§

§child_process: Child§uffd_factory: UffdFactory§command_tube: Tube§num_static_devices: u32§_dead_uffd_checker: DeadUffdCheckerImpl

Implementations§

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.

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.

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.

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.

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.

Return current swap status.

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

Shutdown the monitor process.

This blocks until the monitor process exits.

This should be called once.

Suspend device processes using SIGSTOP signal.

When the returned ProcessesGuard is dropped, the devices resume.

This must be called from the main process.

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

Trait Implementations§

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§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.