This splits the `crosvm swap enable` command, which pauses the whole
crosvm processes while it write all the active pages on the guest memory
into the swap file, into 2 commands.
On `crosvm swap enable` command, the monitor process just moves the
guest memroy to the staging memory while blocking the whole crosvm
processes with SIGSTOP.
On `crosvm swap out` command, the monitor process writes the active
pages in the staging memory to the swap file.
The page faults between `swap enable` and `swap out` are swapped in from
the staging memory.
By waiting some time before sending swap out request after enabling
vmm-swap, hot pages on the guest memory, which are frequently accessed,
are swapped in from the staging memory and we can reduce the TBW of the
swap file and reduce the latency of page faults for hot pages.
BUG=b:263830401
TEST=cargo test -p swap -p base
Change-Id: Ia83f5052cc0bd4d25089c6a6680e40a1fa1661c0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4134149
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Handling page faults using userfaultfd for all the time after vmm-swap
is enabled originally has overhead. By disabling swapping, we can use
crosvm without the overhead when the crosvm become used heavily again.
This also refactor PageHandler and extract register logic to lib.rs.
BUG=b:215093219
TEST=cargo test -p swap
Change-Id: Id81d84ebe40067b4f19b212f6b81cbaf249c0c3c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4005474
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
userfaultfd returns ENOMEM on register if the corresponding process is
obsolete (e.g. the process dies, memory space is refleshed by execve).
BUG=b:253555760
TEST=cargo test -p swap
Change-Id: I9a6a7f0ed45cdc91bdf17e5d29e4c215b7f575a5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4025736
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Directories from TempDir::into_path() are not automatically deleted.
We should use TempDir::path() instead.
BUG=b:253555760
TEST=cargo test -p swap
Change-Id: I9f0c5398a7eaa16317f9e40f16231f9b7df0a3a5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4033426
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
origin:
https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3944711
PageHandler handles events from userfaultfd using SwapFile.
tests are placed as integration tests since they rely on userfaultfd(2).
design document: go/tanooki-phase1-dd
BUG=b:215093219
TEST=cargo test -p swap page_handler
Change-Id: I64d213d27174d75ee618c4675ea52dbac58bfe59
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4016144
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>