Commit graph

78 commits

Author SHA1 Message Date
Shintaro Kawamura
168587a9b8 swap: improve metrics and logs
Added details metrics and fixed minor bugs in logging.

BUG=b:253555760
TEST=none

Change-Id: I553cae2b8201871648fda0222796cc99115ceeb2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4125077
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
2023-01-10 02:58:54 +00:00
Shintaro Kawamura
d37a6d71b9 swap: wake the faulting process on conflict
userfaultfd does not wake the thread if zero operation fails with
EEXIST.

minor change: An unexpected page fault event is critical error because
it blocks the faulting thread forever.

BUG=b:215093219
TEST=none

Change-Id: I5326878018f825024c7a5ceaf8daec5792547cb6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4125076
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
2023-01-10 02:58:54 +00:00
Daniel Verkamp
ac0fc378a3 Fix remaining Chrome/Chromium OS instances
These should be written as ChromeOS and ChromiumOS (without the space)
to match the updated branding. The copyright headers were already
migrated to the new style (https://crrev.com/c/3894243), but there were
some more instances left over.

BUG=None
TEST=tools/cargo-doc

Change-Id: I8c76aea2eb33b2e370ab71ee9b5cc0a4cfd00585
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4129934
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-01-03 22:14:30 +00:00
Federico 'Morg' Pareschi
912b70b741 cros_trace: Add initial trace_marker backend
This CL adds a new backend for the cros_tracing crate. This backend can
be enabled by building crosvm with the trace_marker feature enabled.
When the feature is not enabled, no extra overhead incurs as the default
NOOP cros_tracing crate will be compiled in instead.

BUG=b:259501910
TEST=compiled and ran crosvm with and without `--features trace_marker`

Change-Id: Ia4b929b042712a458b7d54c0362d6fda90db9e9f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4075413
Reviewed-by: Christian Blichmann <cblichmann@google.com>
Auto-Submit: Morg <morg@chromium.org>
Commit-Queue: Morg <morg@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-12-23 06:21:24 +00:00
Daniel Verkamp
a506de7ee6 Reformat with nightly rustfmt
BUG=None
TEST=tools/fmt --nightly

Change-Id: I7c74b9190bf28e3d7e3ac4401a2b79800a9e4b76
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4087003
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-12-07 19:33:09 +00:00
Daniel Verkamp
d570328520 swap: remove Cargo.toml data_model patch
Fixes compiler warning:

  warning: patch for the non root package will be ignored, specify patch
  at the workspace root:
  [...]/src/platform/crosvm/swap/Cargo.toml
  [...]/src/platform/crosvm/Cargo.toml

The top-level crosvm/Cargo.toml already specifies the patch, so we can
just remove it from swap/Cargo.toml

BUG=None
TEST=cargo build --features=swap
TEST=emerge-brya crosvm

Change-Id: Icdb9c7745478552ac01f07bdd5c799feff3f69a0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4062050
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-11-29 23:33:36 +00:00
Shintaro Kawamura
eee4f337df swap: log metrics of vmm-swap
This is for debugging purpose.

BUG=b:215093219
TEST=none

Change-Id: Idb5e09c2e06b719bff9ab7a0ead4d55f1f44c304
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4060494
Auto-Submit: Shin Kawamura <kawasin@google.com>
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
2022-11-29 07:38:38 +00:00
David Stevens
34d7f69f27 swap: fix for VMs with highmem
Handle the case where VM memory is split up into multiple regions by
taking into account the region end when swapping out memory. Also rename
SwapFile.len to SwapFile.num_pages to make the units clear.

BUG=b:215093219
TEST=cargo test --package base
TEST=enable/disable swap on VM with >4GB of memory

Change-Id: I8dcdadd39c3f7cbd22c1c042498153966a1a0431
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4040653
Commit-Queue: David Stevens <stevensd@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Shin Kawamura <kawasin@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-11-22 02:08:53 +00:00
Keiichi Watanabe
667a582781 swap: Fix cargo-doc warnings
BUG=none
TEST=./tools/cargo-doc

Change-Id: I395c7a51fb972d1333127c1e38faa4cedaea14b1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4042042
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-11-21 10:46:56 +00:00
Shintaro Kawamura
937a163518 swap: fix cursor in PageHandler::copy_all()
BUG=b:215093219
TEST=None

Change-Id: I9cf132e178d7dce922577ef214788ec1485a85fd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4037069
Reviewed-by: David Stevens <stevensd@chromium.org>
Auto-Submit: Shin Kawamura <kawasin@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-11-18 07:22:00 +00:00
Shintaro Kawamura
5a1ee09f2f swap: use VolatileSlice directly instead of FileContent
This is a refactoring CL. FileContent was created due to historical
reason. But using VolatileSlice directly is more straightforward.

BUG=b:215093219
TEST=cargo test -p swap

Change-Id: I2dbe7b5abb3e7e1d24f337b5e715acf1caf6db5f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4033201
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2022-11-18 01:23:47 +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
bcf9339387 swap: log page fault event
The new command "crosvm swap log_pagefault <socket>" starts logging
page fault events. The log file "page_fault.log" will be located under
the swap directory.

Pagefault event log help up debugging the vmm-swap feature and
understand the memory usage of the guest os.

design document: go/tanooki-phase1-dd

BUG=b:253555760
TEST=manually tested. this is debug feature.

Change-Id: I13e36cef873cd83179032fe8a289c8df71384644
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3954806
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2022-11-17 02:48:04 +00:00
Hikaru Nishida
2b35bf353b swap: add commands for vmm-swap out
Added new crosvm commands "crosvm swap enable" and "crosvm swap status".

swap crate exposes SwapController to control the vmm-swap feature.

When vmm-swap is enabled, all the pages on the GuestMemory are swapped
out to a file and are freed to give a lot of memory back to OS.

design document: go/tanooki-phase1-dd

BUG=b:215093219
TEST=manually tested

Change-Id: Ideb10b0119edd9f47b66c8ac61add21ac08181d4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3871758
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2022-11-17 02:39:55 +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
4196632a3e Reland "swap: suspend device processes using SIGSTOP signal"
origin:
https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3932497

ProcessesGuard stops all the crosvm processes except the caller process
using SIGSTOP signal because we must guarantee that no one changes the
guest memory contents while vmm-swap out.

This is a short term solution and will be replaced with device
suspension feature later.

See the "Write back atomicity" section in go/tanooki-phase1-dd

BUG=b:215093219
TEST=cargo build --features=swap

Change-Id: I34e528bf318e5ff9277048f3daf8608e7b09ddc7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4016145
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2022-11-14 06:14:07 +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
Shintaro Kawamura
9f962de130 Reland "swap: add swap file"
origin:
https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3930082

SwapFile saves the active pages in the memory region to a file.

design document: go/tanooki-phase1-dd

BUG=b:215093219
TEST=cargo test -p swap

Change-Id: Idce637ed069665e174b36c21a32afdad2f00fea1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4016143
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2022-11-14 06:14:07 +00:00
Shintaro Kawamura
67390a05fb Reland "swap: add userfaultfd wrapper"
origin:
https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3895235

userfaultfd enables applications to handle page faults on designated
memory area.

vmm-swap feature uses userfaultfd to catch page fault event and swap
in the guest memory from the swap file.

design document: go/tanooki-phase1-dd

BUG=b:215093219
TEST=cargo build --features=swap

Change-Id: I36ecfe9be988a4bc451f8edaf2ab48e25c6600f4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4016142
Commit-Queue: Shin Kawamura <kawasin@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-11-14 06:14:07 +00:00
Shin Kawamura
eb5c9ffef9 Revert "swap: add userfaultfd wrapper"
Revert submission 3935683

Reason for revert: userfaultfd-sys fails to build on windows
Reverted Changes:
Icf46cfb26:swap: add PageHandler
I408dbfa4d:base: unix: add fork_process
Ie62a0cf53:swap: suspend device processes using SIGSTOP signa...
I4ce16eef3:swap: add swap file
I13ae09cd9:swap: add userfaultfd wrapper

Change-Id: Ic815d0a73a0b2db6a33ed9d87025643a106183d2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4015885
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-11-09 06:02:39 +00:00
Shin Kawamura
35c9c13c65 Revert "swap: add swap file"
Revert submission 3935683

Reason for revert: userfaultfd-sys fails to build on windows
Reverted Changes:
Icf46cfb26:swap: add PageHandler
I408dbfa4d:base: unix: add fork_process
Ie62a0cf53:swap: suspend device processes using SIGSTOP signa...
I4ce16eef3:swap: add swap file
I13ae09cd9:swap: add userfaultfd wrapper

Change-Id: I6f323046726edf0d2006de99a2c07ee2956efda6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4015884
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-11-09 06:02:39 +00:00
Shin Kawamura
444ddb868c Revert "swap: add PageHandler"
Revert submission 3935683

Reason for revert: userfaultfd-sys fails to build on windows
Reverted Changes:
Icf46cfb26:swap: add PageHandler
I408dbfa4d:base: unix: add fork_process
Ie62a0cf53:swap: suspend device processes using SIGSTOP signa...
I4ce16eef3:swap: add swap file
I13ae09cd9:swap: add userfaultfd wrapper

Change-Id: I1db78f57a91968f17d8b27bbbfc574e14adea65b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4015883
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-11-09 06:02:39 +00:00
Shin Kawamura
55d99500a9 Revert "swap: suspend device processes using SIGSTOP signal"
Revert submission 3935683

Reason for revert: userfaultfd-sys fails to build on windows
Reverted Changes:
Icf46cfb26:swap: add PageHandler
I408dbfa4d:base: unix: add fork_process
Ie62a0cf53:swap: suspend device processes using SIGSTOP signa...
I4ce16eef3:swap: add swap file
I13ae09cd9:swap: add userfaultfd wrapper

Change-Id: Ia3675a8e0439de38db55a8cd0098bbc331230e8b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4015882
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-11-09 06:02:39 +00:00
Shintaro Kawamura
427f1becb9 swap: suspend device processes using SIGSTOP signal
ProcessesGuard stops all the crosvm processes except the caller process
using SIGSTOP signal because we must guarantee that no one changes the
guest memory contents while vmm-swap out.

This is a short term solution and will be replaced with device
suspension feature later.

See the "Write back atomicity" section in go/tanooki-phase1-dd

BUG=b:215093219
TEST=cargo build --features=swap

Change-Id: Ie62a0cf537a045128c0d298e7a73d222fea96ef0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3932497
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-11-09 05:24:08 +00:00
Shintaro Kawamura
0d94c42c56 swap: add PageHandler
PageHandler handles events from userfaultfd using SwapFile.

design document: go/tanooki-phase1-dd

BUG=b:215093219
TEST=cargo test -p swap page_handler

Change-Id: Icf46cfb26670ff4488d783c3623f280ccc89457a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3944711
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
2022-11-09 05:24:08 +00:00
Shintaro Kawamura
e8aaafffcf swap: add swap file
SwapFile saves the active pages in the memory region to a file.

design document: go/tanooki-phase1-dd

BUG=b:215093219
TEST=cargo test -p swap

Change-Id: I4ce16eef36ace832d26622e44444f7549299c1e7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3930082
Reviewed-by: David Stevens <stevensd@chromium.org>
2022-11-09 05:24:08 +00:00
Shintaro Kawamura
b75d3bc45e swap: add userfaultfd wrapper
userfaultfd enables applications to handle page faults on designated
memory area.

vmm-swap feature uses userfaultfd to catch page fault event and swap
in the guest memory from the swap file.

design document: go/tanooki-phase1-dd

BUG=b:215093219
TEST=cargo build --features=swap

Change-Id: I13ae09cd97e4215b00e5d834d4f97eb6b507b892
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3895235
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-11-09 05:24:08 +00:00