From 84e863f65b838e27ce94bc41b25f46f4c8bc26ac Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 26 Jul 2016 21:07:55 -0700 Subject: [PATCH] folly: fix AtomicUnorderedMap compilation on macOS Summary: MAP_POPULATE is not defined on this system. Instead we will `madvise` the kernel that we will need it so that it will populate the mapping. Reviewed By: yfeldblum Differential Revision: D3584325 fbshipit-source-id: ece52f3d55c475bcd41367f4e9744d6f41001cd5 --- folly/detail/AtomicUnorderedMapUtils.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/folly/detail/AtomicUnorderedMapUtils.h b/folly/detail/AtomicUnorderedMapUtils.h index 53aba01f..77fa735f 100644 --- a/folly/detail/AtomicUnorderedMapUtils.h +++ b/folly/detail/AtomicUnorderedMapUtils.h @@ -25,15 +25,23 @@ class MMapAlloc { // MAP_HUGETLB is a perf win, but requires cooperation from the // deployment environment (and a change to computeSize()). void* mem = static_cast(mmap( - nullptr, - len, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, - -1, - 0)); + nullptr, + len, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS +#ifdef MAP_POPULATE + | + MAP_POPULATE +#endif + , + -1, + 0)); if (mem == reinterpret_cast(-1)) { throw std::system_error(errno, std::system_category()); } +#if !defined(MAP_POPULATE) && defined(MADV_WILLNEED) + madvise(mem, size, MADV_WILLNEED); +#endif return mem; } -- 2.34.1