+/*
+ * 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 <sys/mman.h>
-#include <unistd.h>
+#include <cstdint>
+
+#include <folly/portability/SysMman.h>
+#include <folly/portability/Unistd.h>
namespace folly { namespace detail {
// 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;
}