-
Notifications
You must be signed in to change notification settings - Fork 30k
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
src: large page support for macOS #28977
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ | |
#if defined(__FreeBSD__) | ||
#include <sys/sysctl.h> | ||
#include <sys/user.h> | ||
#elif defined(__APPLE__) | ||
#include <mach/vm_map.h> | ||
#endif | ||
#include <unistd.h> // readlink | ||
|
||
|
@@ -212,6 +214,42 @@ static struct text_region FindNodeTextRegion() { | |
} | ||
start += cursz; | ||
} | ||
#elif defined(__APPLE__) | ||
struct text_region nregion; | ||
nregion.found_text_region = false; | ||
struct vm_region_submap_info_64 map; | ||
mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT_64; | ||
vm_address_t addr = 0UL; | ||
vm_size_t size = 0; | ||
natural_t depth = 1; | ||
|
||
while (true) { | ||
if (vm_region_recurse_64(mach_task_self(), &addr, &size, &depth, | ||
reinterpret_cast<vm_region_info_64_t>(&map), | ||
&count) != KERN_SUCCESS) { | ||
break; | ||
} | ||
|
||
if (map.is_submap) { | ||
depth++; | ||
} else { | ||
char* start = reinterpret_cast<char*>(hugepage_align_up(addr)); | ||
char* end = reinterpret_cast<char*>(hugepage_align_down(addr+size)); | ||
size_t esize = end - start; | ||
|
||
if (end > start && (map.protection & VM_PROT_READ) != 0 && | ||
(map.protection & VM_PROT_EXECUTE) != 0) { | ||
nregion.found_text_region = true; | ||
nregion.from = start; | ||
nregion.to = end; | ||
nregion.total_hugepages = esize / hps; | ||
break; | ||
} | ||
|
||
addr += size; | ||
size = 0; | ||
} | ||
} | ||
#endif | ||
return nregion; | ||
} | ||
|
@@ -271,7 +309,11 @@ static bool IsSuperPagesEnabled() { | |
// c. madvise with MADV_HUGE_PAGE | ||
// d. If successful copy the code there and unmap the original region | ||
int | ||
#if !defined(__APPLE__) | ||
__attribute__((__section__(".lpstub"))) | ||
#else | ||
__attribute__((__section__("__TEXT,__lpstub"))) | ||
#endif | ||
__attribute__((__aligned__(hps))) | ||
__attribute__((__noinline__)) | ||
MoveTextRegionToLargePages(const text_region& r) { | ||
|
@@ -330,6 +372,16 @@ MoveTextRegionToLargePages(const text_region& r) { | |
munmap(nmem, size); | ||
return -1; | ||
} | ||
#elif defined(__APPLE__) | ||
tmem = mmap(start, size, | ||
PROT_READ | PROT_WRITE | PROT_EXEC, | ||
MAP_PRIVATE | MAP_ANONYMOUS, | ||
VM_FLAGS_SUPERPAGE_SIZE_2MB, 0); | ||
if (tmem == MAP_FAILED) { | ||
PrintSystemError(errno); | ||
munmap(nmem, size); | ||
return -1; | ||
} | ||
#endif | ||
|
||
memcpy(start, nmem, size); | ||
|
@@ -369,16 +421,19 @@ int MapStaticCodeToLargePages() { | |
return MoveTextRegionToLargePages(r); | ||
|
||
return -1; | ||
#elif defined(__FreeBSD__) | ||
#elif defined(__FreeBSD__) || defined(__APPLE__) | ||
return MoveTextRegionToLargePages(r); | ||
#endif | ||
} | ||
|
||
bool IsLargePagesEnabled() { | ||
#if defined(__linux__) | ||
return IsTransparentHugePagesEnabled(); | ||
#else | ||
#elif defined(__FreeBSD__) | ||
return IsSuperPagesEnabled(); | ||
#elif defined(__APPLE__) | ||
// pse-36 flag is present in recent mac x64 products. | ||
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. How recent is recent? Node.js supports macOS 10.11 and up. 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. Then it is fine El Capitan is recent enough :) |
||
return true; | ||
#endif | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: single quotes
Substance:
info('macOS server...')
might be better although plain print() isn't exactly wrong either, it's used in plenty of places.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.
Putting @bnoordhuis's comment above as a suggestion for ease of adoption: