-
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: simplify large pages mapping code #32396
src: simplify large pages mapping code #32396
Conversation
45c73c3
to
9f2adb5
Compare
I've been trying to verify the OSX port as well as the FreeBSD port, but the FreeBSD port fails to map to large pages in order to avoid a segfault, and I have not been able to build on our OSX test machines: test-macstadium-macos10.10-x64-1: #32467 Things work well on Linux though, so I removed the WIP. |
* Introduce `OnScopeLeave` handler for cleaning up mmap()ed range(s). * Factor out failure scenario at the bottom of the function with `fail` label for use with `goto`. * Do not allocate temporary range (`nmem`) on FreeBSD, because it is not used. The intention is that the steps involved in re-mapping to large pages become more clearly visible. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
9f2adb5
to
470d2d2
Compare
@devnexen is there a combination involving FreeBSD under which the mapping actually works? |
@devnexen I tried building on test-digitalocean-freebsd11-x64-2 and on FreeBSD 12.1 from https://www.osboxes.org/freebsd/ and they both refuse to re-map because of the requirement that the region to map not precede the mapping function: node/src/large_pages/node_large_page.cc Lines 454 to 457 in 066bdec
|
Codecov Report
@@ Coverage Diff @@
## master #32396 +/- ##
==========================================
+ Coverage 97.16% 97.46% +0.30%
==========================================
Files 197 195 -2
Lines 65781 65701 -80
==========================================
+ Hits 63914 64037 +123
+ Misses 1867 1664 -203
Continue to review full report at Codecov.
|
@devnexen NM - I got it to work. |
if (nmem != nullptr && nmem != MAP_FAILED && munmap(nmem, size) == -1) | ||
PrintSystemError(errno); | ||
if (tmem != nullptr && tmem != MAP_FAILED && munmap(tmem, size) == -1) | ||
PrintSystemError(errno); |
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 (nmem != nullptr && nmem != MAP_FAILED && munmap(nmem, size) == -1) | |
PrintSystemError(errno); | |
if (tmem != nullptr && tmem != MAP_FAILED && munmap(tmem, size) == -1) | |
PrintSystemError(errno); | |
if ((nmem != nullptr && nmem != MAP_FAILED && munmap(nmem, size) == -1) || | |
(tmem != nullptr && tmem != MAP_FAILED && munmap(tmem, size) == -1)) { | |
PrintSystemError(errno); | |
} |
Alternatively, it may be a bit cleaner to use a custom smart pointer with a deleter for these...
e.g. bit more verbose...
struct Mmap {
void* mem = nullptr;
size_t size = 0;
Mmap(void* start, size_t size, int prot, int flags) {
mem = mmap(start, size, prot, flags, -1, 0);
}
};
struct MmapDeleter {
void operator()(Mmap* ptr) const noexcept {
if (ptr.mem != nullptr &&
ptr.mem != MAP_FAILED &&
munmap(ptr.mem, ptr.size) == -1)
PrintSystemError(errno);
}
};
using MmapPointer = std::unique_ptr<Mmap, MmapDeleter>;
then...
MmapPointer nmem;
MmapPointer tmem;
// ...
size_t size = r.to - r.from;
// ...
nmem = std::make_unique(nullptr, size,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS);
if (nmem.mem == MAP_FAILED)
goto fail;
// ...
tmem = std::make_unique(start, size,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED);
if (tmem.mem == MAP_FAILED)
goto fail;
Landed in fa3fd78. |
* Introduce `OnScopeLeave` handler for cleaning up mmap()ed range(s). * Factor out failure scenario at the bottom of the function with `fail` label for use with `goto`. * Do not allocate temporary range (`nmem`) on FreeBSD, because it is not used. The intention is that the steps involved in re-mapping to large pages become more clearly visible. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl> PR-URL: #32396 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: David Carlier <devnexen@gmail.com>
* Introduce `OnScopeLeave` handler for cleaning up mmap()ed range(s). * Factor out failure scenario at the bottom of the function with `fail` label for use with `goto`. * Do not allocate temporary range (`nmem`) on FreeBSD, because it is not used. The intention is that the steps involved in re-mapping to large pages become more clearly visible. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl> PR-URL: #32396 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: David Carlier <devnexen@gmail.com>
Depends on the large pages change to land on v12.x |
* Introduce `OnScopeLeave` handler for cleaning up mmap()ed range(s). * Factor out failure scenario at the bottom of the function with `fail` label for use with `goto`. * Do not allocate temporary range (`nmem`) on FreeBSD, because it is not used. The intention is that the steps involved in re-mapping to large pages become more clearly visible. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl> PR-URL: nodejs#32396 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: David Carlier <devnexen@gmail.com>
* Introduce `OnScopeLeave` handler for cleaning up mmap()ed range(s). * Factor out failure scenario at the bottom of the function with `fail` label for use with `goto`. * Do not allocate temporary range (`nmem`) on FreeBSD, because it is not used. The intention is that the steps involved in re-mapping to large pages become more clearly visible. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl> PR-URL: #32396 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: David Carlier <devnexen@gmail.com>
OnScopeLeave
handler for cleaning up mmap()ed range(s).fail
label for use withgoto
.nmem
) on FreeBSD, because it isnot used.
The intention is that the steps involved in re-mapping to large pages
become more clearly visible.
Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes