-
-
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
…eEnabled instead of isLargePageEnabled)
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,8 +63,8 @@ namespace node { | |
| #define PAGE_ALIGN_DOWN(x, a) ((x) & ~((a) - 1)) | ||
|
|
||
| struct TextRegion { | ||
| char * from; | ||
| char * to; | ||
| char* from; | ||
| char* to; | ||
| int total_hugepages; | ||
| bool found_text_region; | ||
| }; | ||
|
|
@@ -105,8 +105,8 @@ struct TextRegion { | |
|
|
||
| if (permission.compare("r-xp") == 0) { | ||
| start = reinterpret_cast<unsigned int64_t>(&__nodetext); | ||
| char *from = reinterpret_cast<char *>PAGE_ALIGN_UP(start, hps); | ||
| char *to = reinterpret_cast<char *>PAGE_ALIGN_DOWN(end, hps); | ||
| char* from = reinterpret_cast<char *>PAGE_ALIGN_UP(start, hps); | ||
| char* to = reinterpret_cast<char *>PAGE_ALIGN_DOWN(end, hps); | ||
|
|
||
| if (from < to) { | ||
| size_t size = to - from; | ||
|
|
@@ -120,7 +120,7 @@ struct TextRegion { | |
| return nregion; | ||
|
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. the frame will be overwritten after return, so the local structure will be stale in the caller?
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. We are not returning a pointer to this but the actual structure which will be returned as a copy. So we are ok.
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. sorry for that, my mis-understanding. |
||
| } | ||
|
|
||
| static bool isTransparentHugePagesEnabled() { | ||
| static bool IsTransparentHugePagesEnabled() { | ||
| std::ifstream ifs; | ||
|
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. any reason for using C++ style file I/O and C style elsewhere?
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. Will make it consistent and use C++ everywhere. |
||
|
|
||
| ifs.open("/sys/kernel/mm/transparent_hugepage/enabled"); | ||
|
|
@@ -163,11 +163,12 @@ struct TextRegion { | |
| __attribute__((__noinline__)) | ||
| __attribute__((__optimize__("2"))) | ||
| move_text_region_to_large_pages(struct TextRegion r) { | ||
| void *nmem = nullptr, *tmem = nullptr; | ||
| void* nmem = nullptr; | ||
| void* tmem = nullptr; | ||
| int ret = 0; | ||
|
|
||
| size_t size = r.to - r.from; | ||
| void *start = r.from; | ||
| void* start = r.from; | ||
|
|
||
| // Allocate temporary region preparing for copy | ||
| nmem = mmap(nullptr, size, | ||
|
|
@@ -192,13 +193,6 @@ struct TextRegion { | |
| 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); | ||
| if (ret == -1) { | ||
| printSystemError(errno); | ||
|
|
@@ -252,8 +246,8 @@ struct TextRegion { | |
| return -1; | ||
| } | ||
|
|
||
| bool isLargePagesEnabled() { | ||
| return isTransparentHugePagesEnabled(); | ||
| bool IsLargePagesEnabled() { | ||
| return IsTransparentHugePagesEnabled(); | ||
| } | ||
|
|
||
| } // namespace node | ||
|
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. I admit I kinda checked out after the first 100 lines. This file has so many style errors, can you fix those first, please?
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. Could you be specific? I ran the make -s lint and fixed all the ones pointed to by that.
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. The linter doesn't catch everything but to name three things:
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 have updated the PR with 2) and 3). I am using standard indentation of 2 spaces.
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. @suresh-srinivas There’s https://github.com/nodejs/node/blob/master/CPP_STYLE_GUIDE.md that would help a lot with this. Also, comparing with other code in our codebase if you’re unsure. :) (In particular, we don’t indent code inside namespaces)
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. @addaleax thanks much. I will look at this and fix styles accordingly.
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. @addaleax @bnoordhuis @gireeshpunathil fixed the style errors. Let me know if you see anything else. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ | |
| #define SRC_NODE_LARGE_PAGE_H_ | ||
|
|
||
| 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. |
||
| bool isLargePagesEnabled(); | ||
| bool IsLargePagesEnabled(); | ||
| int map_static_code_to_large_pages(); | ||
| } // 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.
style nit: these could all be inline functions, right?
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.
Thanks. Yes fixed them to be inline functions.