Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0a76c7e
Initial Large Page (2M) support for node.js
suresh-srinivas Mar 23, 2018
fa0e324
Add support for checking if explicitHugePages and transparentHugePage…
suresh-srinivas Mar 26, 2018
fdb45cd
Added License headers
suresh-srinivas Mar 30, 2018
b7791c2
Get rid of waring messages & code cleanup
suresh-srinivas Mar 30, 2018
6631eea
Protect the large pages under #ifdef NODE_ENABLE_LARGE_CODE_PAGES and…
suresh-srinivas Apr 4, 2018
843089c
Added configure option to enable huge pages
uttampawar Apr 9, 2018
077bc01
Added else clause to set node_use_large_pages=false by default
uttampawar Apr 9, 2018
7bdd9fc
Merge branch 'configure_fixes' into 2M-Pages-For-Code-16198
uttampawar Apr 9, 2018
b91de5a
Finished adding checks at appropriate places to handle possible error…
uttampawar May 8, 2018
7ef956a
Changed return type for two function from void to int
uttampawar May 9, 2018
b02e7a9
Fixed lint errors.
uttampawar May 24, 2018
2af82b1
Added one more condition check for verify the start address of newly …
uttampawar May 26, 2018
cae9285
Fixed syntax error due to wring data type. int64 to int64_t
uttampawar May 30, 2018
30114b6
Removed explictHugePages code
suresh-srinivas May 30, 2018
39e1f0d
Merge branch 'add-checks' into 2M-Pages-For-Code-16198
suresh-srinivas May 30, 2018
49cd0de
Merge branch '2M-Pages-For-Code-16198' of https://github.intel.com/DS…
suresh-srinivas May 30, 2018
2dd9e8c
Added Large Page Support
suresh-srinivas May 30, 2018
51d0f02
Merge branch 'intel-large-pages' of https://github.com/suresh-sriniva…
suresh-srinivas May 31, 2018
2f672ee
Update PR based on feedback
suresh-srinivas Jun 1, 2018
31504cc
Addressing the additional PR feedback
suresh-srinivas Jun 3, 2018
f998c58
Fix the gypi style issue
suresh-srinivas Jun 3, 2018
9f15cfc
Update with stylistic changes (eg char* instead of char *, IsLargePag…
suresh-srinivas Jun 4, 2018
d6de361
Add additional guard so large pages is only under Linux and target_ar…
suresh-srinivas Jun 4, 2018
29c7d13
Style fixes according to the Node C++ Style Guide
suresh-srinivas Jun 4, 2018
9828036
Eliminate ld.script and use implicit script
suresh-srinivas Jun 7, 2018
600cf54
Add #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
suresh-srinivas Jun 7, 2018
bf259e2
Fix the test failures
suresh-srinivas Jun 7, 2018
f0a6dcb
Add detailed help message to configure --with-largepages
suresh-srinivas Jun 8, 2018
4610793
Fix style issues and created inline functions instead of macros for a…
suresh-srinivas Jun 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed return type for two function from void to int
  • Loading branch information
uttampawar committed May 9, 2018
commit 7ef956adaf3dd892fadce91f7f5a642c0f7492e3
5 changes: 3 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4487,8 +4487,9 @@ int Start(int argc, char** argv) {

#ifdef NODE_ENABLE_LARGE_CODE_PAGES
if (node::largepages::isLargePagesEnabled()) {
// fprintf(stderr, "Mapping static code to large pages\n");
node::largepages::map_static_code_to_large_pages();
if ( (node::largepages::map_static_code_to_large_pages()) != 0) {
fprintf(stderr, "Warning: Mapping of static code to large pages failed.\n");
}
}
#endif

Expand Down
34 changes: 14 additions & 20 deletions src/node_large_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

Expand All @@ -73,7 +73,7 @@ namespace node {
const size_t hugePageSize = 2L * 1024 * 1024;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

@suresh-srinivas suresh-srinivas Jun 1, 2018

Choose a reason for hiding this comment

The 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
/proc/[pid]/maps
A file containing the currently mapped memory regions and their access permissions.

          The format of the file is:
   address           perms offset  dev   inode       pathname
   00400000-00452000 r-xp 00000000 08:02 173521      /usr/bin/dbus-daemon
   00651000-00652000 r--p 00051000 08:02 173521      /usr/bin/dbus-daemon
   00652000-00655000 rw-p 00052000 08:02 173521      /usr/bin/dbus-daemon
   00e03000-00e24000 rw-p 00000000 00:00 0           [heap]
   00e24000-011f7000 rw-p 00000000 00:00 0           [heap]
   ...
   35b1800000-35b1820000 r-xp 00000000 08:02 135522  /usr/lib64/ld-2.15.so
   35b1a1f000-35b1a20000 r--p 0001f000 08:02 135522  /usr/lib64/ld-2.15.so
   35b1a20000-35b1a21000 rw-p 00020000 08:02 135522  /usr/lib64/ld-2.15.so
   35b1a21000-35b1a22000 rw-p 00000000 00:00 0

For the node process it looks like this.

00400000-02168000 r-xp 00000000 08:01 541586     /home/dslo/node-ssuresh-fork/node
02367000-02369000 r--p 01d67000 08:01 541586      /home/dslo/node-ssuresh-fork/node
02369000-02380000 rw-p 01d69000 08:01 541586     /home/dslo/node-ssuresh-fork/node
02380000-0248f000 rw-p 00000000 00:00 0                                  [heap]

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.

00400000-00a00000 r-xp 00000000 08:01 541593    /home/dslo/node-ssuresh-fork/node.large
00a00000-02200000 r-xp 00000000 00:00 0 
02200000-02397000 r-xp 01e00000 08:01 541593    /home/dslo/node-ssuresh-fork/node.large
02597000-02598000 r--p 01f97000 08:01 541593     /home/dslo/node-ssuresh-fork/node.large
02598000-025af000 rw-p 01f98000 08:01 541593     /home/dslo/node-ssuresh-fork/node.large
025af000-025c7000 rw-p 00000000 00:00 0 
036df000-037d2000 rw-p 00000000 00:00 0                                  [heap]

struct TextRegion nregion;

nregion.found_text_region = 0;
nregion.found_text_region = false;

f = fopen("/proc/self/maps", "r");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catpure fopen failure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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",
Expand All @@ -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;
Expand Down Expand Up @@ -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__))
Expand All @@ -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,
Expand All @@ -192,7 +186,7 @@ namespace node {
if (tmem == MAP_FAILED) {
printSystemError(errno);
munmap(nmem, size);
return;
return -1;
}

ret = madvise(start, size, MADV_HUGEPAGE);
Expand All @@ -207,7 +201,7 @@ namespace node {
printSystemError(errno);
}

return;
return -1;
}
}

Expand All @@ -223,7 +217,7 @@ namespace node {
if (ret == -1) {
printSystemError(errno);
}
return;
return -1;
}

// Release the old/temporary mapped region
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/node_large_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SPDX-License-Identifier: MIT
namespace node {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Expand Down