-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Conversation
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, LGTM % some style nits.
configure.py
Outdated
if options.shared or options.enable_static: | ||
raise Exception( | ||
'Large pages are supported only while creating node executable.') | ||
if target_arch!="x64": | ||
raise Exception( | ||
'Large pages are supported only x64 platform.') | ||
if flavor == 'mac': | ||
print("macOS server with 32GB or more is recommended") |
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:
print("macOS server with 32GB or more is recommended") | |
info('macOS server with 32GB or more is recommended') |
src/large_pages/node_large_page.cc
Outdated
|
||
while (true) { | ||
if (vm_region_recurse_64(mach_task_self(), &addr, &size, &depth, | ||
(vm_region_info_64_t)&map, &count) != KERN_SUCCESS) { |
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.
reinterpret_cast
please, no C style casts (and preferably line up the arguments.)
src/large_pages/node_large_page.cc
Outdated
tmem = mmap(start, size, | ||
PROT_READ | PROT_WRITE | PROT_EXEC, | ||
MAP_PRIVATE | MAP_ANONYMOUS, | ||
VM_FLAGS_SUPERPAGE_SIZE_2MB, 0); |
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.
Can you line up the arguments with the ones on the first line?
Proposal to bring the support for this platform. We assume the pse36 cpu flag is present for 2MB large page support present in recent years in mac line (not to be backported to 10.x anyway). Recommended better for mac production servers rather than casual mac books.
One remaining style nit? |
Significant chunk of C++ code added, I think, since previous reviews, so re-requested reviews. |
@@ -382,9 +382,25 @@ MoveTextRegionToLargePages(const text_region& r) { | |||
munmap(nmem, size); | |||
return -1; | |||
} | |||
memcpy(tmem, nmem, size); | |||
ret = mprotect(start, size, PROT_READ | PROT_WRITE | PROT_EXEC); |
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.
Can you explain why this is necessary? It's already mapped rwx, isn't it?
Should the mmap() call include MAP_FIXED
in its flags like it does on Linux and FreeBSD? If not, can you update the comment atop of this function?
Aside: since there are a lot of munmap(nmem, size)
calls now, it'd be nice to DRY it:
nmem = mmap(...);
OnScopeLeave munmap_on_return([nmem, size] () {
if (-1 == munmap(nmem, size)) PrintSystemError(errno);
});
I guess you lose the ability to return an error from MoveTextRegionToLargePages()
on munmap() failure but that doesn't seem too bad, it's not really a fatal error and probably hypothetical to boot. You could simply abort on failure.
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.
To answer your first question it is rx but will add a comment (note that s start address not the new address). Ok for the rest (including the info change in configure.py).
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.
Just to round out this discussion: using MAP_FIXED
is not an option on macos? start
is properly aligned, isn't it?
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.
start is indeed aligned like other platforms, MAP_FIXED failed on this platform though with 24MB close to the start address reservation attempt.
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.
Yeah, I'd have to go digging for the reason again but MAP_FIXED
has long had problems with mmap for large page sizes on macos. Pretty sure the macos api docs recommend not to use it but if I recall correctly they don't really explain why.
src/large_pages/node_large_page.cc
Outdated
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); |
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.
There are a few more munmap(nmem, size)
calls in linux/freebsd code paths. Can you remove those as well?
@@ -382,9 +382,25 @@ MoveTextRegionToLargePages(const text_region& r) { | |||
munmap(nmem, size); | |||
return -1; | |||
} | |||
memcpy(tmem, nmem, size); | |||
ret = mprotect(start, size, PROT_READ | PROT_WRITE | PROT_EXEC); |
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.
Just to round out this discussion: using MAP_FIXED
is not an option on macos? start
is properly aligned, isn't it?
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Then it is fine El Capitan is recent enough :)
Proposal to bring the support for this platform. We assume the pse36 cpu flag is present for 2MB large page support present in recent years in mac line (not to be backported to 10.x anyway). Recommended better for mac production servers rather than casual mac books. PR-URL: #28977 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 32df017. Added |
Proposal to bring the support for this platform. We assume the pse36 cpu flag is present for 2MB large page support present in recent years in mac line (not to be backported to 10.x anyway). Recommended better for mac production servers rather than casual mac books. PR-URL: #28977 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Proposal to bring the support for this platform. We assume the pse36 cpu flag is present for 2MB large page support present in recent years in mac line (not to be backported to 10.x anyway). Recommended better for mac production servers rather than casual mac books. PR-URL: nodejs#28977 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Proposal to bring the support for this platform.
We assume the pse36 cpu flag is present for 2MB large page support present
in recent years in mac line (not to be backported to 10.x anyway).
Recommended better for mac production servers rather than casual mac books.