| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a83d338 commit 49a7e73
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -404,17 +404,6 @@ | |||
| 404 | 404 | dest='with_etw', | |
| 405 | 405 | help='build with ETW (default is true on Windows)') | |
| 406 | 406 | ||
| 407 | - parser.add_option('--use-largepages', | ||
| 408 | - action='store_true', | ||
| 409 | - dest='node_use_large_pages', | ||
| 410 | - help='build with Large Pages support. This feature is supported only on Linux kernel' + | ||
| 411 | - '>= 2.6.38 with Transparent Huge pages enabled and FreeBSD') | ||
| 412 | - | ||
| 413 | - parser.add_option('--use-largepages-script-lld', | ||
| 414 | - action='store_true', | ||
| 415 | - dest='node_use_large_pages_script_lld', | ||
| 416 | - help='link against the LLVM ld linker script. Implies -fuse-ld=lld in the linker flags') | ||
| 417 | - | ||
| 418 | 407 | intl_optgroup.add_option('--with-intl', | |
| 419 | 408 | action='store', | |
| 420 | 409 | dest='with_intl', | |
@@ -1068,28 +1057,6 @@ def configure_node(o): | |||
| 1068 | 1057 | else: | |
| 1069 | 1058 | o['variables']['node_use_dtrace'] = 'false' | |
| 1070 | 1059 | ||
| 1071 | - if options.node_use_large_pages and not flavor in ('linux', 'freebsd', 'mac'): | ||
| 1072 | - raise Exception( | ||
| 1073 | - 'Large pages are supported only on Linux, FreeBSD and MacOS Systems.') | ||
| 1074 | - if options.node_use_large_pages and flavor in ('linux', 'freebsd', 'mac'): | ||
| 1075 | - if options.shared or options.enable_static: | ||
| 1076 | - raise Exception( | ||
| 1077 | - 'Large pages are supported only while creating node executable.') | ||
| 1078 | - if target_arch!="x64": | ||
| 1079 | - raise Exception( | ||
| 1080 | - 'Large pages are supported only x64 platform.') | ||
| 1081 | - if flavor == 'mac': | ||
| 1082 | - info('macOS server with 32GB or more is recommended') | ||
| 1083 | - if flavor == 'linux': | ||
| 1084 | - # Example full version string: 2.6.32-696.28.1.el6.x86_64 | ||
| 1085 | - FULL_KERNEL_VERSION=os.uname()[2] | ||
| 1086 | - KERNEL_VERSION=FULL_KERNEL_VERSION.split('-')[0] | ||
| 1087 | - if KERNEL_VERSION < "2.6.38" and flavor == 'linux': | ||
| 1088 | - raise Exception( | ||
| 1089 | - 'Large pages need Linux kernel version >= 2.6.38') | ||
| 1090 | - o['variables']['node_use_large_pages'] = b(options.node_use_large_pages) | ||
| 1091 | - o['variables']['node_use_large_pages_script_lld'] = b(options.node_use_large_pages_script_lld) | ||
| 1092 | - | ||
| 1093 | 1060 | if options.no_ifaddrs: | |
| 1094 | 1061 | o['defines'] += ['SUNOS_NO_IFADDRS'] | |
| 1095 | 1062 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -876,6 +876,22 @@ environment variables. | |||
| 876 | 876 | ||
| 877 | 877 | See `SSL_CERT_DIR` and `SSL_CERT_FILE`. | |
| 878 | 878 | ||
| 879 | + ### `--use-largepages=mode` | ||
| 880 | + <!-- YAML | ||
| 881 | + added: REPLACEME | ||
| 882 | + --> | ||
| 883 | + | ||
| 884 | + Re-map the Node.js static code to large memory pages at startup. If supported on | ||
| 885 | + the target system, this will cause the Node.js static code to be moved onto 2 | ||
| 886 | + MiB pages instead of 4 KiB pages. | ||
| 887 | + | ||
| 888 | + The following values are valid for `mode`: | ||
| 889 | + * `off`: No mapping will be attempted. This is the default. | ||
| 890 | + * `on`: If supported by the OS, mapping will be attempted. Failure to map will | ||
| 891 | + be ignored and a message will be printed to standard error. | ||
| 892 | + * `silent`: If supported by the OS, mapping will be attempted. Failure to map | ||
| 893 | + will be ignored and will not be reported. | ||
| 894 | + | ||
| 879 | 895 | ### `--v8-options` | |
| 880 | 896 | <!-- YAML | |
| 881 | 897 | added: v0.1.3 | |
@@ -1133,6 +1149,7 @@ Node.js options that are allowed are: | |||
| 1133 | 1149 | * `--track-heap-objects` | |
| 1134 | 1150 | * `--unhandled-rejections` | |
| 1135 | 1151 | * `--use-bundled-ca` | |
| 1152 | + * `--use-largepages` | ||
| 1136 | 1153 | * `--use-openssl-ca` | |
| 1137 | 1154 | * `--v8-pool-size` | |
| 1138 | 1155 | * `--zero-fill-buffers` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -402,6 +402,16 @@ See | |||
| 402 | 402 | and | |
| 403 | 403 | .Ev SSL_CERT_FILE . | |
| 404 | 404 | . | |
| 405 | + .It Fl -use-largepages Ns = Ns Ar mode | ||
| 406 | + Re-map the Node.js static code to large memory pages at startup. If supported on | ||
| 407 | + the target system, this will cause the Node.js static code to be moved onto 2 | ||
| 408 | + MiB pages instead of 4 KiB pages. | ||
| 409 | + .Pp | ||
| 410 | + .Ar mode | ||
| 411 | + must have one of the following values: | ||
| 412 | + `off` (the default value, meaning do not map), `on` (map and ignore failure, | ||
| 413 | + reporting it to stderr), or `silent` (map and silently ignore failure). | ||
| 414 | + . | ||
| 405 | 415 | .It Fl -v8-options | |
| 406 | 416 | Print V8 command-line options. | |
| 407 | 417 | . | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -836,10 +836,9 @@ | |||
| 836 | 836 | }], | |
| 837 | 837 | ], | |
| 838 | 838 | }], | |
| 839 | - [ 'node_use_large_pages=="true" and OS in "linux freebsd mac"', { | ||
| 839 | + [ 'OS in "linux freebsd mac" and ' | ||
| 840 | + 'target_arch=="x64"', { | ||
| 840 | 841 | 'defines': [ 'NODE_ENABLE_LARGE_CODE_PAGES=1' ], | |
| 841 | - # The current implementation of Large Pages is under Linux. | ||
| 842 | - # Other implementations are possible but not currently supported. | ||
| 843 | 842 | 'sources': [ | |
| 844 | 843 | 'src/large_pages/node_large_page.cc', | |
| 845 | 844 | 'src/large_pages/node_large_page.h' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -308,17 +308,15 @@ | |||
| 308 | 308 | }], | |
| 309 | 309 | [ 'OS=="linux" and ' | |
| 310 | 310 | 'target_arch=="x64" and ' | |
| 311 | - 'node_use_large_pages=="true" and ' | ||
| 312 | - 'node_use_large_pages_script_lld=="false"', { | ||
| 311 | + 'llvm_version=="0.0"', { | ||
| 313 | 312 | 'ldflags': [ | |
| 314 | 313 | '-Wl,-T', | |
| 315 | 314 | '<!(realpath src/large_pages/ld.implicit.script)', | |
| 316 | 315 | ] | |
| 317 | 316 | }], | |
| 318 | 317 | [ 'OS=="linux" and ' | |
| 319 | 318 | 'target_arch=="x64" and ' | |
| 320 | - 'node_use_large_pages=="true" and ' | ||
| 321 | - 'node_use_large_pages_script_lld=="true"', { | ||
| 319 | + 'llvm_version!="0.0"', { | ||
| 322 | 320 | 'ldflags': [ | |
| 323 | 321 | '-Wl,-T', | |
| 324 | 322 | '<!(realpath src/large_pages/ld.implicit.script.lld)', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,7 +62,7 @@ | |||
| 62 | 62 | // Map a new area and copy the original code there | |
| 63 | 63 | // Use mmap using the start address with MAP_FIXED so we get exactly the | |
| 64 | 64 | // same virtual address | |
| 65 | - // Use madvise with MADV_HUGE_PAGE to use Anonymous 2M Pages | ||
| 65 | + // Use madvise with MADV_HUGEPAGE to use Anonymous 2M Pages | ||
| 66 | 66 | // If successful copy the code there and unmap the original region. | |
| 67 | 67 | ||
| 68 | 68 | extern char __nodetext; | |
@@ -308,7 +308,7 @@ static bool IsSuperPagesEnabled() { | |||
| 308 | 308 | // a. map a new area and copy the original code there | |
| 309 | 309 | // b. mmap using the start address with MAP_FIXED so we get exactly | |
| 310 | 310 | // the same virtual address (except on macOS). | |
| 311 | - // c. madvise with MADV_HUGE_PAGE | ||
| 311 | + // c. madvise with MADV_HUGEPAGE | ||
| 312 | 312 | // d. If successful copy the code there and unmap the original region | |
| 313 | 313 | int | |
| 314 | 314 | #if !defined(__APPLE__) | |
@@ -333,9 +333,6 @@ MoveTextRegionToLargePages(const text_region& r) { | |||
| 333 | 333 | PrintSystemError(errno); | |
| 334 | 334 | return -1; | |
| 335 | 335 | } | |
| 336 | - auto munmap_on_return = OnScopeLeave([nmem, size]() { | ||
| 337 | - if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| 338 | - }); | ||
| 339 | 336 | ||
| 340 | 337 | memcpy(nmem, r.from, size); | |
| 341 | 338 | ||
@@ -352,13 +349,14 @@ MoveTextRegionToLargePages(const text_region& r) { | |||
| 352 | 349 | return -1; | |
| 353 | 350 | } | |
| 354 | 351 | ||
| 355 | - ret = madvise(tmem, size, MADV_HUGEPAGE); | ||
| 352 | + ret = madvise(tmem, size, 14 /* MADV_HUGEPAGE */); | ||
| 356 | 353 | if (ret == -1) { | |
| 357 | 354 | PrintSystemError(errno); | |
| 358 | 355 | ret = munmap(tmem, size); | |
| 359 | 356 | if (ret == -1) { | |
| 360 | 357 | PrintSystemError(errno); | |
| 361 | 358 | } | |
| 359 | + if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| 362 | 360 | return -1; | |
| 363 | 361 | } | |
| 364 | 362 | memcpy(start, nmem, size); | |
@@ -369,6 +367,7 @@ MoveTextRegionToLargePages(const text_region& r) { | |||
| 369 | 367 | MAP_ALIGNED_SUPER, -1 , 0); | |
| 370 | 368 | if (tmem == MAP_FAILED) { | |
| 371 | 369 | PrintSystemError(errno); | |
| 370 | + if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| 372 | 371 | return -1; | |
| 373 | 372 | } | |
| 374 | 373 | #elif defined(__APPLE__) | |
@@ -383,6 +382,7 @@ MoveTextRegionToLargePages(const text_region& r) { | |||
| 383 | 382 | VM_FLAGS_SUPERPAGE_SIZE_2MB, 0); | |
| 384 | 383 | if (tmem == MAP_FAILED) { | |
| 385 | 384 | PrintSystemError(errno); | |
| 385 | + if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| 386 | 386 | return -1; | |
| 387 | 387 | } | |
| 388 | 388 | memcpy(tmem, nmem, size); | |
@@ -393,6 +393,7 @@ MoveTextRegionToLargePages(const text_region& r) { | |||
| 393 | 393 | if (ret == -1) { | |
| 394 | 394 | PrintSystemError(errno); | |
| 395 | 395 | } | |
| 396 | + if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| 396 | 397 | return -1; | |
| 397 | 398 | } | |
| 398 | 399 | memcpy(start, tmem, size); | |
@@ -405,8 +406,10 @@ MoveTextRegionToLargePages(const text_region& r) { | |||
| 405 | 406 | if (ret == -1) { | |
| 406 | 407 | PrintSystemError(errno); | |
| 407 | 408 | } | |
| 409 | + if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| 408 | 410 | return -1; | |
| 409 | 411 | } | |
| 412 | + if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| 410 | 413 | return ret; | |
| 411 | 414 | } | |
| 412 | 415 | ||
@@ -418,12 +421,12 @@ int MapStaticCodeToLargePages() { | |||
| 418 | 421 | return -1; | |
| 419 | 422 | } | |
| 420 | 423 | ||
| 421 | - #if defined(__linux__) | ||
| 424 | + #if defined(__linux__) || defined(__FreeBSD__) | ||
| 422 | 425 | if (r.from > reinterpret_cast<void*>(&MoveTextRegionToLargePages)) | |
| 423 | 426 | return MoveTextRegionToLargePages(r); | |
| 424 | 427 | ||
| 425 | 428 | return -1; | |
| 426 | - #elif defined(__FreeBSD__) || defined(__APPLE__) | ||
| 429 | + #elif defined(__APPLE__) | ||
| 427 | 430 | return MoveTextRegionToLargePages(r); | |
| 428 | 431 | #endif | |
| 429 | 432 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,9 +64,7 @@ | |||
| 64 | 64 | #include "inspector/worker_inspector.h" // ParentInspectorHandle | |
| 65 | 65 | #endif | |
| 66 | 66 | ||
| 67 | - #ifdef NODE_ENABLE_LARGE_CODE_PAGES | ||
| 68 | 67 | #include "large_pages/node_large_page.h" | |
| 69 | - #endif | ||
| 70 | 68 | ||
| 71 | 69 | #ifdef NODE_REPORT | |
| 72 | 70 | #include "node_report.h" | |
@@ -1000,14 +998,6 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) { | |||
| 1000 | 998 | ||
| 1001 | 999 | CHECK_GT(argc, 0); | |
| 1002 | 1000 | ||
| 1003 | - #ifdef NODE_ENABLE_LARGE_CODE_PAGES | ||
| 1004 | - if (node::IsLargePagesEnabled()) { | ||
| 1005 | - if (node::MapStaticCodeToLargePages() != 0) { | ||
| 1006 | - fprintf(stderr, "Reverting to default page size\n"); | ||
| 1007 | - } | ||
| 1008 | - } | ||
| 1009 | - #endif | ||
| 1010 | - | ||
| 1011 | 1001 | // Hack around with the argv pointer. Used for process.title = "blah". | |
| 1012 | 1002 | argv = uv_setup_args(argc, argv); | |
| 1013 | 1003 | ||
@@ -1027,6 +1017,26 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) { | |||
| 1027 | 1017 | } | |
| 1028 | 1018 | } | |
| 1029 | 1019 | ||
| 1020 | + #if defined(NODE_ENABLE_LARGE_CODE_PAGES) && NODE_ENABLE_LARGE_CODE_PAGES | ||
| 1021 | + if (per_process::cli_options->use_largepages == "on" || | ||
| 1022 | + per_process::cli_options->use_largepages == "silent") { | ||
| 1023 | + if (node::IsLargePagesEnabled()) { | ||
| 1024 | + if (node::MapStaticCodeToLargePages() != 0 && | ||
| 1025 | + per_process::cli_options->use_largepages != "silent") { | ||
| 1026 | + fprintf(stderr, | ||
| 1027 | + "Mapping code to large pages failed. Reverting to default page " | ||
| 1028 | + "size.\n"); | ||
| 1029 | + } | ||
| 1030 | + } else if (per_process::cli_options->use_largepages != "silent") { | ||
| 1031 | + fprintf(stderr, "Large pages are not enabled.\n"); | ||
| 1032 | + } | ||
| 1033 | + } | ||
| 1034 | + #else | ||
| 1035 | + if (per_process::cli_options->use_largepages == "on") { | ||
| 1036 | + fprintf(stderr, "Mapping to large pages is not supported.\n"); | ||
| 1037 | + } | ||
| 1038 | + #endif // NODE_ENABLE_LARGE_CODE_PAGES | ||
| 1039 | + | ||
| 1030 | 1040 | if (per_process::cli_options->print_version) { | |
| 1031 | 1041 | printf("%s\n", NODE_VERSION); | |
| 1032 | 1042 | result.exit_code = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,11 @@ void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) { | |||
| 63 | 63 | "used, not both"); | |
| 64 | 64 | } | |
| 65 | 65 | #endif | |
| 66 | + if (use_largepages != "off" && | ||
| 67 | + use_largepages != "on" && | ||
| 68 | + use_largepages != "silent") { | ||
| 69 | + errors->push_back("invalid value for --use-largepages"); | ||
| 70 | + } | ||
| 66 | 71 | per_isolate->CheckOptions(errors); | |
| 67 | 72 | } | |
| 68 | 73 | ||
@@ -752,6 +757,10 @@ PerProcessOptionsParser::PerProcessOptionsParser( | |||
| 752 | 757 | kAllowedInEnvironment); | |
| 753 | 758 | #endif | |
| 754 | 759 | #endif | |
| 760 | + AddOption("--use-largepages", | ||
| 761 | + "Map the Node.js static code to large pages", | ||
| 762 | + &PerProcessOptions::use_largepages, | ||
| 763 | + kAllowedInEnvironment); | ||
| 755 | 764 | ||
| 756 | 765 | Insert(iop, &PerProcessOptions::get_per_isolate_options); | |
| 757 | 766 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -237,6 +237,7 @@ class PerProcessOptions : public Options { | |||
| 237 | 237 | bool force_fips_crypto = false; | |
| 238 | 238 | #endif | |
| 239 | 239 | #endif | |
| 240 | + std::string use_largepages = "off"; | ||
| 240 | 241 | ||
| 241 | 242 | #ifdef NODE_REPORT | |
| 242 | 243 | std::vector<std::string> cmdline; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Make sure that Node.js runs correctly with the --use-largepages option. | ||
| 4 | + | ||
| 5 | + require('../common'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const { spawnSync } = require('child_process'); | ||
| 8 | + | ||
| 9 | + { | ||
| 10 | + const child = spawnSync(process.execPath, | ||
| 11 | + [ '--use-largepages=on', '-p', '42' ]); | ||
| 12 | + const stdout = child.stdout.toString().match(/\S+/g); | ||
| 13 | + assert.strictEqual(child.status, 0); | ||
| 14 | + assert.strictEqual(child.signal, null); | ||
| 15 | + assert.strictEqual(stdout.length, 1); | ||
| 16 | + assert.strictEqual(stdout[0], '42'); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + { | ||
| 20 | + const child = spawnSync(process.execPath, | ||
| 21 | + [ '--use-largepages=xyzzy', '-p', '42' ]); | ||
| 22 | + assert.strictEqual(child.status, 9); | ||
| 23 | + assert.strictEqual(child.signal, null); | ||
| 24 | + assert.strictEqual(child.stderr.toString().match(/\S+/g).slice(1).join(' '), | ||
| 25 | + 'invalid value for --use-largepages'); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + // TODO(gabrielschulhof): Make assertions about the stderr, which may or may not | ||
| 29 | + // contain a message indicating that mapping to large pages has failed. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments