Skip to content
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
wants to merge 3 commits into from
Closed

src: large page support for macOS #28977

wants to merge 3 commits into from

Conversation

devnexen
Copy link
Contributor

@devnexen devnexen commented Aug 5, 2019

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.

@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++. labels Aug 5, 2019
Copy link
Member

@bnoordhuis bnoordhuis left a 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")
Copy link
Member

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.

Copy link
Member

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:

Suggested change
print("macOS server with 32GB or more is recommended")
info('macOS server with 32GB or more is recommended')


while (true) {
if (vm_region_recurse_64(mach_task_self(), &addr, &size, &depth,
(vm_region_info_64_t)&map, &count) != KERN_SUCCESS) {
Copy link
Member

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.)

tmem = mmap(start, size,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS,
VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
Copy link
Member

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.
@nodejs-github-bot
Copy link
Collaborator

@Trott
Copy link
Member

Trott commented Aug 8, 2019

One remaining style nit?

@Trott Trott requested review from jasnell and bnoordhuis August 19, 2019 02:07
@Trott
Copy link
Member

Trott commented Aug 19, 2019

Significant chunk of C++ code added, I think, since previous reviews, so re-requested reviews.

@nodejs-github-bot
Copy link
Collaborator

@@ -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);
Copy link
Member

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.

Copy link
Contributor Author

@devnexen devnexen Aug 20, 2019

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).

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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 Show resolved Hide resolved
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);
Copy link
Member

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);
Copy link
Member

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.
Copy link
Member

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.

Copy link
Contributor Author

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 :)

@nodejs-github-bot
Copy link
Collaborator

@Trott Trott added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. dont-land-on-v10.x labels Aug 20, 2019
Trott pushed a commit that referenced this pull request Aug 20, 2019
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>
@Trott
Copy link
Member

Trott commented Aug 20, 2019

Landed in 32df017.

Added dont-land-on-v10.x and dont-land-on-v8.x based on the commit message.

@Trott Trott closed this Aug 20, 2019
BridgeAR pushed a commit that referenced this pull request Sep 3, 2019
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>
@BridgeAR BridgeAR mentioned this pull request Sep 3, 2019
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Mar 6, 2020
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants