Skip to content

Commit

Permalink
restore redundancy for the sake of OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Schulhof committed Mar 28, 2020
1 parent 5457085 commit e29bd96
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/large_pages/node_large_page.cc
Expand Up @@ -331,13 +331,16 @@ MoveTextRegionToLargePages(const text_region& r) {
tmem = mmap(start, size,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1 , 0);
if (tmem != MAP_FAILED)
if (madvise(tmem, size, 14 /* MADV_HUGEPAGE */) == -1) goto fail;
if (tmem == MAP_FAILED) goto fail;
if (madvise(tmem, size, 14 /* MADV_HUGEPAGE */) == -1) goto fail;
memcpy(start, nmem, size);
#elif defined(__FreeBSD__)
tmem = mmap(start, size,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED |
MAP_ALIGNED_SUPER, -1 , 0);
if (tmem == MAP_FAILED) goto fail;
memcpy(start, nmem, size);
#elif defined(__APPLE__)
// There is not enough room to reserve the mapping close
// to the region address so we content to give a hint
Expand All @@ -348,9 +351,12 @@ MoveTextRegionToLargePages(const text_region& r) {
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS,
VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
#endif
if (tmem == MAP_FAILED) goto fail;
memcpy(start, nmem, size);
memcpy(tmem, nmem, size);
if (mprotect(start, size, PROT_READ | PROT_WRITE | PROT_EXEC) == -1)
goto fail;
memcpy(start, tmem, size);
#endif

if (mprotect(start, size, PROT_READ | PROT_EXEC) == -1) goto fail;
// We need not `munmap(tmem, size)` in the above `OnScopeLeave` on success.
Expand Down

0 comments on commit e29bd96

Please sign in to comment.