Sort #include lines
[folly.git] / folly / detail / AtomicUnorderedMapUtils.h
index 4142ade82ff7675983c7ea91a7bec8d7de4ef1b4..83ef6672eedf037a1d0d93efbca52a7b4e908e6d 100644 (file)
@@ -1,10 +1,26 @@
+/*
+ * Copyright 2004-present Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #pragma once
 
 #include <atomic>
-#include <stdint.h>
-#include <unistd.h>
+#include <cstdint>
 
 #include <folly/portability/SysMman.h>
+#include <folly/portability/Unistd.h>
 
 namespace folly { namespace detail {
 
@@ -25,15 +41,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;
   }