Skip to content

Commit

Permalink
src: make --use-largepages a three-valued option
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Schulhof committed Dec 15, 2019
1 parent a83c5df commit 65622bf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
9 changes: 8 additions & 1 deletion doc/api/cli.md
Expand Up @@ -863,7 +863,7 @@ environment variables.

See `SSL_CERT_DIR` and `SSL_CERT_FILE`.

### `--use-largepages`
### `--use-largepages=num`
<!-- YAML
added: REPLACEME
-->
Expand All @@ -872,6 +872,13 @@ Re-map the Node.js static code to large memory pages at startup. If supported on
the target system, this will cause the Node.js static code to be moved onto 2
MiB pages instead of 4 KiB pages.

The following values are valid for `num`:
* 0: No mapping will be attempted. This is the default.
* 1: If supported by the OS, mapping will be attempted. Failure to map will be
ignored and will not be reported.
* 2: If supported by the OS, mapping will be attempted. Failure to map will be
ignored and a message will be printed to standard error.

### `--v8-options`
<!-- YAML
added: v0.1.3
Expand Down
4 changes: 3 additions & 1 deletion doc/node.1
Expand Up @@ -398,10 +398,12 @@ See
and
.Ev SSL_CERT_FILE .
.
.It Fl -use-largepages
.It Fl -use-largepages Ns = Ns Ar num
Re-map the Node.js static code to large memory pages at startup. If supported on
the target system, this will cause the Node.js static code to be moved onto 2
MiB pages instead of 4 KiB pages.
.Pp
The following values are valid: 0 (do not map), 1 (map, ignore failure, and do not report it), and 2 (map, ignore failure, but report it to standard error).
.
.It Fl -v8-options
Print V8 command-line options.
Expand Down
6 changes: 4 additions & 2 deletions src/node.cc
Expand Up @@ -984,9 +984,11 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) {
}
}

if (per_process::cli_options->use_largepages) {
if (per_process::cli_options->use_largepages == 1 ||
per_process::cli_options->use_largepages == 2) {
if (node::IsLargePagesEnabled()) {
if (node::MapStaticCodeToLargePages() != 0) {
if (node::MapStaticCodeToLargePages() != 0 &&
per_process::cli_options->use_largepages == 2) {
fprintf(stderr, "Reverting to default page size\n");
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/node_options.cc
Expand Up @@ -63,6 +63,9 @@ void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
"used, not both");
}
#endif
if (!(use_largepages >= 0 && use_largepages <= 2)) {
errors->push_back("--use-largepages must be one of 0, 1, or 2");
}
per_isolate->CheckOptions(errors);
}

Expand Down
2 changes: 1 addition & 1 deletion src/node_options.h
Expand Up @@ -235,7 +235,7 @@ class PerProcessOptions : public Options {
bool force_fips_crypto = false;
#endif
#endif
bool use_largepages = false;
uint64_t use_largepages = 0;

#ifdef NODE_REPORT
std::vector<std::string> cmdline;
Expand Down

0 comments on commit 65622bf

Please sign in to comment.