-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Large Page Support for Code Issue: 16198 #21064
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
Changes from 1 commit
0a76c7e
fa0e324
fdb45cd
b7791c2
6631eea
843089c
077bc01
7bdd9fc
b91de5a
7ef956a
b02e7a9
2af82b1
cae9285
30114b6
39e1f0d
49cd0de
2dd9e8c
51d0f02
2f672ee
31504cc
f998c58
9f15cfc
d6de361
29c7d13
9828036
600cf54
bf259e2
f0a6dcb
4610793
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,11 +52,11 @@ namespace node { | |
| #define PAGE_ALIGN_DOWN(x,a) ((x) & ~((a) - 1)) | ||
|
|
||
| struct TextRegion { | ||
| int found_text_region; | ||
| void * from; | ||
| void * to; | ||
| int totalHugePages; | ||
| long offset; | ||
| bool found_text_region; | ||
| char name[PATH_MAX]; | ||
| }; | ||
|
|
||
|
|
@@ -73,7 +73,7 @@ namespace node { | |
| const size_t hugePageSize = 2L * 1024 * 1024; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it have a bearing to existing Linux attributes? Are they same across releases and vendors? are they tunable at OS level?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The structure of /proc//maps is consistent across many different releases/vendors. man proc For the node process it looks like this. After we map part of the area, you will see the text spilt into 3 executable pages. I will put this in the code comment as well. |
||
| struct TextRegion nregion; | ||
|
|
||
| nregion.found_text_region = 0; | ||
| nregion.found_text_region = false; | ||
|
|
||
| f = fopen("/proc/self/maps", "r"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. catpure fopen failure
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If /proc/self/maps is not there things are really messed up. |
||
| ret = fscanf(f, "%lx-%lx %4s %lx %5s %ld %s\n", | ||
|
|
@@ -90,7 +90,7 @@ namespace node { | |
|
|
||
| if (from < to) { | ||
| size_t size = (intptr_t)to - (intptr_t)from; | ||
| nregion.found_text_region = 1; | ||
| nregion.found_text_region = true; | ||
| nregion.from = from; | ||
| nregion.to = to; | ||
| nregion.offset = offset; | ||
|
|
@@ -156,7 +156,7 @@ namespace node { | |
| // 1. We map a new area and copy the original code there | ||
| // 2. We mmap using HUGE_TLB | ||
| // 3. If successful we copy the code there and unmap the original region. | ||
| void | ||
| int | ||
| __attribute__((__section__(".eh_frame"))) | ||
| __attribute__((__aligned__(2 * 1024 * 1024))) | ||
| __attribute__((__noinline__)) | ||
|
|
@@ -173,17 +173,11 @@ namespace node { | |
| PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
| if (nmem == MAP_FAILED) { | ||
| printSystemError(errno); | ||
| return; | ||
| return -1; | ||
| } | ||
|
|
||
| memcpy(nmem, r.from, size); | ||
|
|
||
| #if 0 // use for explicit huge pages | ||
| mmap(start, size, | ||
| PROT_READ | PROT_WRITE | PROT_EXEC, | ||
| MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED | MAP_HUGETLB, -1 , 0); | ||
| #endif | ||
|
|
||
| // use for transparent huge pages if enabled | ||
| if (isTransparentHugePagesEnabled()) { | ||
| tmem = mmap(start, size, | ||
|
|
@@ -192,7 +186,7 @@ namespace node { | |
| if (tmem == MAP_FAILED) { | ||
| printSystemError(errno); | ||
| munmap(nmem, size); | ||
| return; | ||
| return -1; | ||
| } | ||
|
|
||
| ret = madvise(start, size, MADV_HUGEPAGE); | ||
|
|
@@ -207,7 +201,7 @@ namespace node { | |
| printSystemError(errno); | ||
| } | ||
|
|
||
| return; | ||
| return -1; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -223,7 +217,7 @@ namespace node { | |
| if (ret == -1) { | ||
| printSystemError(errno); | ||
| } | ||
| return; | ||
| return -1; | ||
| } | ||
|
|
||
| // Release the old/temporary mapped region | ||
|
|
@@ -232,21 +226,21 @@ namespace node { | |
| printSystemError(errno); | ||
| } | ||
|
|
||
| return; | ||
| return ret; | ||
| } | ||
|
|
||
| // This is the primary API called from main | ||
| void map_static_code_to_large_pages() { | ||
| int map_static_code_to_large_pages() { | ||
| struct TextRegion n = find_node_text_region(); | ||
| if (n.found_text_region != 1) { | ||
| if (n.found_text_region == false) { | ||
| fprintf(stderr, "Hugepages WARNING: failed to map static code\n"); | ||
| return; | ||
| return -1; | ||
| } | ||
|
|
||
| if (n.to <= (void *) & move_text_region_to_large_pages) | ||
| move_text_region_to_large_pages(n); | ||
| return move_text_region_to_large_pages(n); | ||
|
|
||
| return; | ||
| return -1; | ||
| } | ||
|
|
||
| bool isLargePagesEnabled() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ SPDX-License-Identifier: MIT | |
| namespace node { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be enclosed in #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks I fixed it. |
||
| namespace largepages { | ||
| bool isLargePagesEnabled(); | ||
| void map_static_code_to_large_pages(); | ||
| int map_static_code_to_large_pages(); | ||
| } // namespace largepages | ||
| } // namespace node | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how many of these fields are used?
can we follow a consistent variable naming convention? (camel casing vs snake casing etc.) I suggest look around in node.cc for the prevailing nomenclature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will look and make it consistent.