From: Wez Furlong Date: Wed, 27 Jul 2016 04:07:55 +0000 (-0700) Subject: folly: fix AtomicUnorderedMap compilation on macOS X-Git-Tag: v2016.07.29.00~7 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=84e863f65b838e27ce94bc41b25f46f4c8bc26ac;p=folly.git 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 --- 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; }