Skip to content

Commit 065a32f

Browse files
MylesBorinsaddaleax
authored andcommitted
Revert "src: make --use-largepages a runtime option"
This reverts commit fcbd2d2. PR-URL: #31782 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 7a1b0ac commit 065a32f

10 files changed

+58
-101
lines changed

configure.py

+33
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,17 @@
398398
dest='with_etw',
399399
help='build with ETW (default is true on Windows)')
400400

401+
parser.add_option('--use-largepages',
402+
action='store_true',
403+
dest='node_use_large_pages',
404+
help='build with Large Pages support. This feature is supported only on Linux kernel' +
405+
'>= 2.6.38 with Transparent Huge pages enabled and FreeBSD')
406+
407+
parser.add_option('--use-largepages-script-lld',
408+
action='store_true',
409+
dest='node_use_large_pages_script_lld',
410+
help='link against the LLVM ld linker script. Implies -fuse-ld=lld in the linker flags')
411+
401412
intl_optgroup.add_option('--with-intl',
402413
action='store',
403414
dest='with_intl',
@@ -1050,6 +1061,28 @@ def configure_node(o):
10501061
else:
10511062
o['variables']['node_use_dtrace'] = 'false'
10521063

1064+
if options.node_use_large_pages and not flavor in ('linux', 'freebsd', 'mac'):
1065+
raise Exception(
1066+
'Large pages are supported only on Linux, FreeBSD and MacOS Systems.')
1067+
if options.node_use_large_pages and flavor in ('linux', 'freebsd', 'mac'):
1068+
if options.shared or options.enable_static:
1069+
raise Exception(
1070+
'Large pages are supported only while creating node executable.')
1071+
if target_arch!="x64":
1072+
raise Exception(
1073+
'Large pages are supported only x64 platform.')
1074+
if flavor == 'mac':
1075+
info('macOS server with 32GB or more is recommended')
1076+
if flavor == 'linux':
1077+
# Example full version string: 2.6.32-696.28.1.el6.x86_64
1078+
FULL_KERNEL_VERSION=os.uname()[2]
1079+
KERNEL_VERSION=FULL_KERNEL_VERSION.split('-')[0]
1080+
if KERNEL_VERSION < "2.6.38" and flavor == 'linux':
1081+
raise Exception(
1082+
'Large pages need Linux kernel version >= 2.6.38')
1083+
o['variables']['node_use_large_pages'] = b(options.node_use_large_pages)
1084+
o['variables']['node_use_large_pages_script_lld'] = b(options.node_use_large_pages_script_lld)
1085+
10531086
if options.no_ifaddrs:
10541087
o['defines'] += ['SUNOS_NO_IFADDRS']
10551088

doc/api/cli.md

-17
Original file line numberDiff line numberDiff line change
@@ -881,22 +881,6 @@ environment variables.
881881

882882
See `SSL_CERT_DIR` and `SSL_CERT_FILE`.
883883

884-
### `--use-largepages=mode`
885-
<!-- YAML
886-
added: v12.16.0
887-
-->
888-
889-
Re-map the Node.js static code to large memory pages at startup. If supported on
890-
the target system, this will cause the Node.js static code to be moved onto 2
891-
MiB pages instead of 4 KiB pages.
892-
893-
The following values are valid for `mode`:
894-
* `off`: No mapping will be attempted. This is the default.
895-
* `on`: If supported by the OS, mapping will be attempted. Failure to map will
896-
be ignored and a message will be printed to standard error.
897-
* `silent`: If supported by the OS, mapping will be attempted. Failure to map
898-
will be ignored and will not be reported.
899-
900884
### `--v8-options`
901885
<!-- YAML
902886
added: v0.1.3
@@ -1153,7 +1137,6 @@ Node.js options that are allowed are:
11531137
* `--track-heap-objects`
11541138
* `--unhandled-rejections`
11551139
* `--use-bundled-ca`
1156-
* `--use-largepages`
11571140
* `--use-openssl-ca`
11581141
* `--v8-pool-size`
11591142
* `--zero-fill-buffers`

doc/node.1

-10
Original file line numberDiff line numberDiff line change
@@ -421,16 +421,6 @@ See
421421
and
422422
.Ev SSL_CERT_FILE .
423423
.
424-
.It Fl -use-largepages Ns = Ns Ar mode
425-
Re-map the Node.js static code to large memory pages at startup. If supported on
426-
the target system, this will cause the Node.js static code to be moved onto 2
427-
MiB pages instead of 4 KiB pages.
428-
.Pp
429-
.Ar mode
430-
must have one of the following values:
431-
`off` (the default value, meaning do not map), `on` (map and ignore failure,
432-
reporting it to stderr), or `silent` (map and silently ignore failure).
433-
.
434424
.It Fl -v8-options
435425
Print V8 command-line options.
436426
.

node.gyp

+3-2
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,10 @@
843843
}],
844844
],
845845
}],
846-
[ 'OS in "linux freebsd mac" and '
847-
'target_arch=="x64"', {
846+
[ 'node_use_large_pages=="true" and OS in "linux freebsd mac"', {
848847
'defines': [ 'NODE_ENABLE_LARGE_CODE_PAGES=1' ],
848+
# The current implementation of Large Pages is under Linux.
849+
# Other implementations are possible but not currently supported.
849850
'sources': [
850851
'src/large_pages/node_large_page.cc',
851852
'src/large_pages/node_large_page.h'

node.gypi

+4-2
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,17 @@
309309
}],
310310
[ 'OS=="linux" and '
311311
'target_arch=="x64" and '
312-
'llvm_version=="0.0"', {
312+
'node_use_large_pages=="true" and '
313+
'node_use_large_pages_script_lld=="false"', {
313314
'ldflags': [
314315
'-Wl,-T',
315316
'<!(realpath src/large_pages/ld.implicit.script)',
316317
]
317318
}],
318319
[ 'OS=="linux" and '
319320
'target_arch=="x64" and '
320-
'llvm_version!="0.0"', {
321+
'node_use_large_pages=="true" and '
322+
'node_use_large_pages_script_lld=="true"', {
321323
'ldflags': [
322324
'-Wl,-T',
323325
'<!(realpath src/large_pages/ld.implicit.script.lld)',

src/large_pages/node_large_page.cc

+8-11
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
// Map a new area and copy the original code there
6363
// Use mmap using the start address with MAP_FIXED so we get exactly the
6464
// same virtual address
65-
// Use madvise with MADV_HUGEPAGE to use Anonymous 2M Pages
65+
// Use madvise with MADV_HUGE_PAGE to use Anonymous 2M Pages
6666
// If successful copy the code there and unmap the original region.
6767

6868
extern char __nodetext;
@@ -308,7 +308,7 @@ static bool IsSuperPagesEnabled() {
308308
// a. map a new area and copy the original code there
309309
// b. mmap using the start address with MAP_FIXED so we get exactly
310310
// the same virtual address (except on macOS).
311-
// c. madvise with MADV_HUGEPAGE
311+
// c. madvise with MADV_HUGE_PAGE
312312
// d. If successful copy the code there and unmap the original region
313313
int
314314
#if !defined(__APPLE__)
@@ -333,6 +333,9 @@ MoveTextRegionToLargePages(const text_region& r) {
333333
PrintSystemError(errno);
334334
return -1;
335335
}
336+
OnScopeLeave munmap_on_return([nmem, size]() {
337+
if (-1 == munmap(nmem, size)) PrintSystemError(errno);
338+
});
336339

337340
memcpy(nmem, r.from, size);
338341

@@ -349,14 +352,13 @@ MoveTextRegionToLargePages(const text_region& r) {
349352
return -1;
350353
}
351354

352-
ret = madvise(tmem, size, 14 /* MADV_HUGEPAGE */);
355+
ret = madvise(tmem, size, MADV_HUGEPAGE);
353356
if (ret == -1) {
354357
PrintSystemError(errno);
355358
ret = munmap(tmem, size);
356359
if (ret == -1) {
357360
PrintSystemError(errno);
358361
}
359-
if (-1 == munmap(nmem, size)) PrintSystemError(errno);
360362
return -1;
361363
}
362364
memcpy(start, nmem, size);
@@ -367,7 +369,6 @@ MoveTextRegionToLargePages(const text_region& r) {
367369
MAP_ALIGNED_SUPER, -1 , 0);
368370
if (tmem == MAP_FAILED) {
369371
PrintSystemError(errno);
370-
if (-1 == munmap(nmem, size)) PrintSystemError(errno);
371372
return -1;
372373
}
373374
#elif defined(__APPLE__)
@@ -382,7 +383,6 @@ MoveTextRegionToLargePages(const text_region& r) {
382383
VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
383384
if (tmem == MAP_FAILED) {
384385
PrintSystemError(errno);
385-
if (-1 == munmap(nmem, size)) PrintSystemError(errno);
386386
return -1;
387387
}
388388
memcpy(tmem, nmem, size);
@@ -393,7 +393,6 @@ MoveTextRegionToLargePages(const text_region& r) {
393393
if (ret == -1) {
394394
PrintSystemError(errno);
395395
}
396-
if (-1 == munmap(nmem, size)) PrintSystemError(errno);
397396
return -1;
398397
}
399398
memcpy(start, tmem, size);
@@ -406,10 +405,8 @@ MoveTextRegionToLargePages(const text_region& r) {
406405
if (ret == -1) {
407406
PrintSystemError(errno);
408407
}
409-
if (-1 == munmap(nmem, size)) PrintSystemError(errno);
410408
return -1;
411409
}
412-
if (-1 == munmap(nmem, size)) PrintSystemError(errno);
413410
return ret;
414411
}
415412

@@ -421,12 +418,12 @@ int MapStaticCodeToLargePages() {
421418
return -1;
422419
}
423420

424-
#if defined(__linux__) || defined(__FreeBSD__)
421+
#if defined(__linux__)
425422
if (r.from > reinterpret_cast<void*>(&MoveTextRegionToLargePages))
426423
return MoveTextRegionToLargePages(r);
427424

428425
return -1;
429-
#elif defined(__APPLE__)
426+
#elif defined(__FreeBSD__) || defined(__APPLE__)
430427
return MoveTextRegionToLargePages(r);
431428
#endif
432429
}

src/node.cc

+10-20
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
#include "inspector/worker_inspector.h" // ParentInspectorHandle
6565
#endif
6666

67+
#ifdef NODE_ENABLE_LARGE_CODE_PAGES
6768
#include "large_pages/node_large_page.h"
69+
#endif
6870

6971
#ifdef NODE_REPORT
7072
#include "node_report.h"
@@ -952,6 +954,14 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) {
952954

953955
CHECK_GT(argc, 0);
954956

957+
#ifdef NODE_ENABLE_LARGE_CODE_PAGES
958+
if (node::IsLargePagesEnabled()) {
959+
if (node::MapStaticCodeToLargePages() != 0) {
960+
fprintf(stderr, "Reverting to default page size\n");
961+
}
962+
}
963+
#endif
964+
955965
// Hack around with the argv pointer. Used for process.title = "blah".
956966
argv = uv_setup_args(argc, argv);
957967

@@ -971,26 +981,6 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) {
971981
}
972982
}
973983

974-
#if defined(NODE_ENABLE_LARGE_CODE_PAGES) && NODE_ENABLE_LARGE_CODE_PAGES
975-
if (per_process::cli_options->use_largepages == "on" ||
976-
per_process::cli_options->use_largepages == "silent") {
977-
if (node::IsLargePagesEnabled()) {
978-
if (node::MapStaticCodeToLargePages() != 0 &&
979-
per_process::cli_options->use_largepages != "silent") {
980-
fprintf(stderr,
981-
"Mapping code to large pages failed. Reverting to default page "
982-
"size.\n");
983-
}
984-
} else if (per_process::cli_options->use_largepages != "silent") {
985-
fprintf(stderr, "Large pages are not enabled.\n");
986-
}
987-
}
988-
#else
989-
if (per_process::cli_options->use_largepages == "on") {
990-
fprintf(stderr, "Mapping to large pages is not supported.\n");
991-
}
992-
#endif // NODE_ENABLE_LARGE_CODE_PAGES
993-
994984
if (per_process::cli_options->print_version) {
995985
printf("%s\n", NODE_VERSION);
996986
result.exit_code = 0;

src/node_options.cc

-9
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
6565
"used, not both");
6666
}
6767
#endif
68-
if (use_largepages != "off" &&
69-
use_largepages != "on" &&
70-
use_largepages != "silent") {
71-
errors->push_back("invalid value for --use-largepages");
72-
}
7368
per_isolate->CheckOptions(errors);
7469
}
7570

@@ -793,10 +788,6 @@ PerProcessOptionsParser::PerProcessOptionsParser(
793788
kAllowedInEnvironment);
794789
#endif
795790
#endif
796-
AddOption("--use-largepages",
797-
"Map the Node.js static code to large pages",
798-
&PerProcessOptions::use_largepages,
799-
kAllowedInEnvironment);
800791

801792
// v12.x backwards compat flags removed in V8 7.9.
802793
AddOption("--fast_calls_with_arguments_mismatches", "", NoOp{});

src/node_options.h

-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ class PerProcessOptions : public Options {
238238
bool force_fips_crypto = false;
239239
#endif
240240
#endif
241-
std::string use_largepages = "off";
242241

243242
#ifdef NODE_REPORT
244243
std::vector<std::string> cmdline;

test/parallel/test-startup-large-pages.js

-29
This file was deleted.

0 commit comments

Comments
 (0)