Skip to content
Closed
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
Removed explictHugePages code
  • Loading branch information
suresh-srinivas committed May 30, 2018
commit 30114b63628570b242f7e38ef75d432855b0db5e
74 changes: 25 additions & 49 deletions src/node_large_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,6 @@ struct TextRegion {
return ret_status;
}

static bool isExplicitHugePagesEnabled() {
int ret_status = false;
std::string kw;
std::ifstream file("/proc/meminfo");
while (file >> kw) {
if (kw == "HugePages_Total:") {
int64_t hp_tot;
file >> hp_tot;
if (hp_tot > 0)
ret_status = true;
else
ret_status = false;

break;
}
}

file.close();
return ret_status;
}

// Moving the text region to large pages. We need to be very careful.
// a) This function itself should not be moved.
// We use a gcc option to put it outside the ".text" section
Expand Down Expand Up @@ -177,38 +156,35 @@ struct TextRegion {

memcpy(nmem, r.from, size);

// use for transparent huge pages if enabled
if (isTransparentHugePagesEnabled()) {
tmem = mmap(start, size,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1 , 0);
if (tmem == MAP_FAILED) {
printSystemError(errno);
munmap(nmem, size);
return -1;
}
tmem = mmap(start, size,
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.

what are the chances you get what you want at the same location? start is already mapped, right? how about passing a nullptr here and get the huge pages wherever available?

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.

If addr is not NULL, then the kernel takes it as a hint about where to place the mapping. Since we are using MAP_FIXED it is not a hint but a requirement. We are relying on the new mapping being at the same virtual address so we dont have to do any fix up of the code. Otherwise we will have to fixup the branches, offsets etc.

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.

ok - I was thinking on the lines on mremap , but looking at the man page for that and your implementation, I guess it is one and the same.

PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1 , 0);
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.

what is the rationale behind predefining the memory attributes? ideally we want to inherit the attribute from the old small pages?

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.

We do want to be able to write to this so PROT_WRITE is needed. We are using MAP_FIXED to place the mapping at exactly that address.

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.

Updated the code comments
We already know the original page is r-xp (PROT_READ, PROT_EXEC, MAP_PRIVATE)
We want PROT_WRITE because we are writing into it.
We want it at the fixed address and we use MAP_FIXED.
We are using MAP_ANONYMOUS so it's contents are initialized to zero and it is also not backed by any file.

if (tmem == MAP_FAILED) {
printSystemError(errno);
munmap(nmem, size);
return -1;
}

if (tmem != start) {
fprintf(stderr, "Unable to allocate hugepages.n");
munmap(nmem, size);
munmap(tmem, size);
return -1;
}
if (tmem != start) {
fprintf(stderr, "Unable to allocate hugepages.n");
munmap(nmem, size);
munmap(tmem, size);
return -1;
}

ret = madvise(tmem, size, MADV_HUGEPAGE);
ret = madvise(tmem, size, MADV_HUGEPAGE);
if (ret == -1) {
printSystemError(errno);
ret = munmap(tmem, size);
if (ret == -1) {
printSystemError(errno);
}
ret = munmap(nmem, size);
if (ret == -1) {
printSystemError(errno);
ret = munmap(tmem, size);
if (ret == -1) {
printSystemError(errno);
}
ret = munmap(nmem, size);
if (ret == -1) {
printSystemError(errno);
}

return -1;
}

return -1;
}

memcpy(start, nmem, size);
Expand Down Expand Up @@ -250,7 +226,7 @@ struct TextRegion {
}

bool isLargePagesEnabled() {
return isExplicitHugePagesEnabled() || isTransparentHugePagesEnabled();
return isTransparentHugePagesEnabled();
}

} // namespace largepages
Expand Down