Skip to content

Commit

Permalink
[kernel] Enable zero page scanning as default
Browse files Browse the repository at this point in the history
Zero page scanning is a useful memory saving tool across almost all of
our targets. The exception being when running microbenchmarks, which
explicitly disables the scanner.

Default values are now:
kernel.page-scanner.start-at-boot=true
kernel.page-scanner.zero-page-scans-per-second=20000

Having the scanner be enabled by default allows for consistent behavior
and expectations across configurations, although any configuration is
still able to tune, or completely turn off, scanning.

Bug: 49773

Change-Id: Id742f7729c6101a662c9330150ed20188528f890
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/385894
Commit-Queue: Adrian Danis <adanis@google.com>
Testability-Review: Adrian Danis <adanis@google.com>
Reviewed-by: James Robinson <jamesr@google.com>
Reviewed-by: Carlos Pizano <cpu@google.com>
  • Loading branch information
AdrianDanis authored and CQ bot account: commit-bot@chromium.org committed May 5, 2020
1 parent 6e84d58 commit a84ed3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 7 additions & 0 deletions boards/x64-reduced-perf-variation.gni
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ board_kernel_cmdline_args = [
# which should bring all devices to the same patch level, removing the
# performance differences when spectre mitigations are in place.
"kernel.x86.disable_spec_mitigations=true",

# Disable page scanning in all its forms. Page scanning is intended to
# provide a memory benefit to final systems, but the operation of the scanner
# and its unpredictable de-duplication or eviction of memory in use by
# benchmarks could cause noticable variation.
"kernel.page-scanner.start-at-boot=false",
"kernel.page-scanner.zero-page-scans-per-second=0",
]
13 changes: 9 additions & 4 deletions docs/reference/kernel/kernel_cmdline.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,21 @@ terminated, or has no jobs and no processes.

## kernel.page-scanner.start-at-boot=\<bool>

This option (false by default) causes the kernels active memory scanner to be
This option (true by default) causes the kernels active memory scanner to be
initially enabled on startup. You can also enable and disable it using the
kernel console. If you disable the scanner, you can have additional system
predictability since it removes time based and background memory eviction.

Every action the scanner performs can be individually configured and disabled.
If all actions are disabled then enabling the scanner has no effect.

## kernel.page-scanner.zero-page-scans-per-second=\<num>

This option, zero by default, configures the maximal number of candidate pages
the zero page scanner will consider every second. Setting to zero means no
zero page scanning will occur.
This option, 20000 by default, configures the maximal number of candidate pages
the zero page scanner will consider every second.

Setting to zero means no zero page scanning will occur. This can provide
additional system predictability for benchmarking or other workloads.

The page scanner must be running for this option to have any effect. It can be
enabled at boot with the `kernel.page-scanner.start-at-boot` option.
Expand Down
11 changes: 8 additions & 3 deletions zircon/kernel/vm/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ static constexpr uint32_t kScannerOpRotateQueues = 1u << 5;
// Amount of time between pager queue rotations.
static constexpr zx_duration_t kQueueRotateTime = ZX_SEC(10);

// If not set on the cmdline this becomes the default zero page scans per second to target. This
// value was chosen to consume, in the worst case, 5% CPU on a lower-end arm device. Individual
// configurations may wish to tune this higher (or lower) as needed.
constexpr uint64_t kDefaultZeroPageScansPerSecond = 20000;

// Number of pages to attempt to de-dupe back to zero every second. This not atomic as it is only
// set during init before the scanner thread starts up, at which point it becomes read only.
static uint64_t zero_page_scans_per_second = 0;
Expand Down Expand Up @@ -198,9 +203,9 @@ static void scanner_init_func(uint level) {
Thread *thread =
Thread::Create("scanner-request-thread", scanner_request_thread, nullptr, LOW_PRIORITY);
DEBUG_ASSERT(thread);
zero_page_scans_per_second =
gCmdline.GetUInt64("kernel.page-scanner.zero-page-scans-per-second", 0);
if (!gCmdline.GetBool("kernel.page-scanner.start-at-boot", false)) {
zero_page_scans_per_second = gCmdline.GetUInt64("kernel.page-scanner.zero-page-scans-per-second",
kDefaultZeroPageScansPerSecond);
if (!gCmdline.GetBool("kernel.page-scanner.start-at-boot", true)) {
Guard<Mutex> guard{scanner_disabled_lock::Get()};
scanner_disable_count++;
scanner_operation.fetch_or(kScannerOpDisable);
Expand Down

0 comments on commit a84ed3e

Please sign in to comment.