Commit graph

5 commits

Author SHA1 Message Date
Shintaro Kawamura
0897c87424 swap: split vmm-swap out command
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>
2023-01-10 08:07:57 +00:00
Shintaro Kawamura
fc88a6091d swap: add disable command to vmm-swap
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>
2022-11-18 01:23:45 +00:00
Shintaro Kawamura
f20622f6fb swap: handle ENOMEM error from userfaultfd
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>
2022-11-17 02:39:55 +00:00
Shintaro Kawamura
87679c98d2 swap: fix tempdir usage in tests
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>
2022-11-17 02:37:47 +00:00
Shintaro Kawamura
df2ec8ec88 Reland "swap: add PageHandler"
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>
2022-11-14 06:14:07 +00:00