folly: fix AtomicUnorderedMap compilation on macOS
authorWez Furlong <wez@fb.com>
Wed, 27 Jul 2016 04:07:55 +0000 (21:07 -0700)
committerFacebook Github Bot 9 <facebook-github-bot-9-bot@fb.com>
Wed, 27 Jul 2016 04:08:29 +0000 (21:08 -0700)
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

index 53aba01f44a9252510997a42b6f66e274b4da4ad..77fa735f4c39281cf3589bd08e06c340497d41af 100644 (file)
@@ -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<void*>(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<void*>(-1)) {
       throw std::system_error(errno, std::system_category());
     }
+#if !defined(MAP_POPULATE) && defined(MADV_WILLNEED)
+    madvise(mem, size, MADV_WILLNEED);
+#endif
 
     return mem;
   }