src: large page support for macOS#28977
src: large page support for macOS#28977devnexen wants to merge 3 commits intonodejs:masterfrom devnexen:osx_large_page_support
Conversation
bnoordhuis
left a comment
There was a problem hiding this comment.
Thanks, LGTM % some style nits.
configure.py
Outdated
There was a problem hiding this comment.
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.
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
There was a problem hiding this comment.
reinterpret_cast please, no C style casts (and preferably line up the arguments.)
src/large_pages/node_large_page.cc
Outdated
There was a problem hiding this comment.
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. |
| return -1; | ||
| } | ||
| memcpy(tmem, nmem, size); | ||
| ret = mprotect(start, size, PROT_READ | PROT_WRITE | PROT_EXEC); |
There was a problem hiding this comment.
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.
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.
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.
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.
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
There was a problem hiding this comment.
There are a few more munmap(nmem, size) calls in linux/freebsd code paths. Can you remove those as well?
| return -1; | ||
| } | ||
| memcpy(tmem, nmem, size); | ||
| ret = mprotect(start, size, PROT_READ | PROT_WRITE | PROT_EXEC); |
There was a problem hiding this comment.
Just to round out this discussion: using MAP_FIXED is not an option on macos? start is properly aligned, isn't it?
| #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.
How recent is recent? Node.js supports macOS 10.11 and up.
There was a problem hiding this comment.
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.