-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
[v12.x] src: make --use-largepages a runtime option #31063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
gabrielschulhof
wants to merge
5
commits into
nodejs:v12.x-staging
from
gabrielschulhof:backport-largepages-runtime-to-v12.x
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3dffd75
src: make --use-largepages a runtime option
a06a137
build: re-introduce --use-largepages as no-op
40afe3d
build: switch realpath to pwd
b74afb3
src: make large_pages node.cc include conditional
lundibundi c48f9d1
build: warn upon --use-largepages config option
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,7 @@ | |
| // Map a new area and copy the original code there | ||
| // Use mmap using the start address with MAP_FIXED so we get exactly the | ||
| // same virtual address | ||
| // Use madvise with MADV_HUGE_PAGE to use Anonymous 2M Pages | ||
| // Use madvise with MADV_HUGEPAGE to use Anonymous 2M Pages | ||
| // If successful copy the code there and unmap the original region. | ||
|
|
||
| extern char __nodetext; | ||
|
|
@@ -308,7 +308,7 @@ static bool IsSuperPagesEnabled() { | |
| // a. map a new area and copy the original code there | ||
| // b. mmap using the start address with MAP_FIXED so we get exactly | ||
| // the same virtual address (except on macOS). | ||
| // c. madvise with MADV_HUGE_PAGE | ||
| // c. madvise with MADV_HUGEPAGE | ||
| // d. If successful copy the code there and unmap the original region | ||
| int | ||
| #if !defined(__APPLE__) | ||
|
|
@@ -333,9 +333,6 @@ MoveTextRegionToLargePages(const text_region& r) { | |
| PrintSystemError(errno); | ||
| return -1; | ||
| } | ||
| OnScopeLeave munmap_on_return([nmem, size]() { | ||
|
||
| if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| }); | ||
|
|
||
| memcpy(nmem, r.from, size); | ||
|
|
||
|
|
@@ -352,13 +349,14 @@ MoveTextRegionToLargePages(const text_region& r) { | |
| return -1; | ||
| } | ||
|
|
||
| ret = madvise(tmem, size, MADV_HUGEPAGE); | ||
| ret = madvise(tmem, size, 14 /* MADV_HUGEPAGE */); | ||
| if (ret == -1) { | ||
| PrintSystemError(errno); | ||
| ret = munmap(tmem, size); | ||
| if (ret == -1) { | ||
| PrintSystemError(errno); | ||
| } | ||
| if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| return -1; | ||
| } | ||
| memcpy(start, nmem, size); | ||
|
|
@@ -369,6 +367,7 @@ MoveTextRegionToLargePages(const text_region& r) { | |
| MAP_ALIGNED_SUPER, -1 , 0); | ||
| if (tmem == MAP_FAILED) { | ||
| PrintSystemError(errno); | ||
| if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| return -1; | ||
| } | ||
| #elif defined(__APPLE__) | ||
|
|
@@ -383,6 +382,7 @@ MoveTextRegionToLargePages(const text_region& r) { | |
| VM_FLAGS_SUPERPAGE_SIZE_2MB, 0); | ||
| if (tmem == MAP_FAILED) { | ||
| PrintSystemError(errno); | ||
| if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| return -1; | ||
| } | ||
| memcpy(tmem, nmem, size); | ||
|
|
@@ -393,6 +393,7 @@ MoveTextRegionToLargePages(const text_region& r) { | |
| if (ret == -1) { | ||
| PrintSystemError(errno); | ||
| } | ||
| if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| return -1; | ||
| } | ||
| memcpy(start, tmem, size); | ||
|
|
@@ -405,8 +406,10 @@ MoveTextRegionToLargePages(const text_region& r) { | |
| if (ret == -1) { | ||
| PrintSystemError(errno); | ||
| } | ||
| if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| return -1; | ||
| } | ||
| if (-1 == munmap(nmem, size)) PrintSystemError(errno); | ||
| return ret; | ||
| } | ||
|
|
||
|
|
@@ -418,12 +421,12 @@ int MapStaticCodeToLargePages() { | |
| return -1; | ||
| } | ||
|
|
||
| #if defined(__linux__) | ||
| #if defined(__linux__) || defined(__FreeBSD__) | ||
| if (r.from > reinterpret_cast<void*>(&MoveTextRegionToLargePages)) | ||
| return MoveTextRegionToLargePages(r); | ||
|
|
||
| return -1; | ||
| #elif defined(__FreeBSD__) || defined(__APPLE__) | ||
| #elif defined(__APPLE__) | ||
| return MoveTextRegionToLargePages(r); | ||
| #endif | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| 'use strict'; | ||
|
|
||
| // Make sure that Node.js runs correctly with the --use-largepages option. | ||
|
|
||
| require('../common'); | ||
| const assert = require('assert'); | ||
| const { spawnSync } = require('child_process'); | ||
|
|
||
| { | ||
| const child = spawnSync(process.execPath, | ||
| [ '--use-largepages=on', '-p', '42' ]); | ||
| const stdout = child.stdout.toString().match(/\S+/g); | ||
| assert.strictEqual(child.status, 0); | ||
| assert.strictEqual(child.signal, null); | ||
| assert.strictEqual(stdout.length, 1); | ||
| assert.strictEqual(stdout[0], '42'); | ||
| } | ||
|
|
||
| { | ||
| const child = spawnSync(process.execPath, | ||
| [ '--use-largepages=xyzzy', '-p', '42' ]); | ||
| assert.strictEqual(child.status, 9); | ||
| assert.strictEqual(child.signal, null); | ||
| assert.strictEqual(child.stderr.toString().match(/\S+/g).slice(1).join(' '), | ||
| 'invalid value for --use-largepages'); | ||
| } | ||
|
|
||
| // TODO(gabrielschulhof): Make assertions about the stderr, which may or may not | ||
| // contain a message indicating that mapping to large pages has failed. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.