-
-
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 |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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, | ||
| PROT_READ | PROT_WRITE | PROT_EXEC, | ||
| MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1 , 0); | ||
|
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. what is the rationale behind predefining the memory attributes? ideally we want to inherit the attribute from the old small pages?
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 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.
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. Updated the code comments |
||
| 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); | ||
|
|
@@ -250,7 +226,7 @@ struct TextRegion { | |
| } | ||
|
|
||
| bool isLargePagesEnabled() { | ||
| return isExplicitHugePagesEnabled() || isTransparentHugePagesEnabled(); | ||
| return isTransparentHugePagesEnabled(); | ||
| } | ||
|
|
||
| } // namespace largepages | ||
|
|
||
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.
what are the chances you get what you want at the same location?
startis already mapped, right? how about passing a nullptr here and get the huge pages wherever available?Uh oh!
There was an error while loading. Please reload this page.
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.
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.
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.
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.