8 namespace folly { namespace detail {
12 size_t computeSize(size_t size) {
13 long pagesize = sysconf(_SC_PAGESIZE);
14 size_t mmapLength = ((size - 1) & ~(pagesize - 1)) + pagesize;
15 assert(size <= mmapLength && mmapLength < size + pagesize);
16 assert((mmapLength % pagesize) == 0);
21 void* allocate(size_t size) {
22 auto len = computeSize(size);
24 // MAP_HUGETLB is a perf win, but requires cooperation from the
25 // deployment environment (and a change to computeSize()).
26 void* mem = static_cast<void*>(mmap(
29 PROT_READ | PROT_WRITE,
30 MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE,
33 if (mem == reinterpret_cast<void*>(-1)) {
34 throw std::system_error(errno, std::system_category());
40 void deallocate(void* p, size_t size) {
41 auto len = computeSize(size);
46 template<typename Allocator>
47 struct GivesZeroFilledMemory : public std::false_type {};
50 struct GivesZeroFilledMemory<MMapAlloc> : public std::true_type{};