proxygen
folly::detail::MMapAlloc Class Reference

#include <AtomicUnorderedMapUtils.h>

Public Member Functions

void * allocate (size_t size)
 
void deallocate (void *p, size_t size)
 

Private Member Functions

size_t computeSize (size_t size)
 

Detailed Description

Definition at line 30 of file AtomicUnorderedMapUtils.h.

Member Function Documentation

void* folly::detail::MMapAlloc::allocate ( size_t  size)
inline

Definition at line 41 of file AtomicUnorderedMapUtils.h.

References computeSize(), and MAP_POPULATE.

41  {
42  auto len = computeSize(size);
43 
44  int extraflags = 0;
45 #if defined(MAP_POPULATE)
46  extraflags |= MAP_POPULATE;
47 #endif
48  // MAP_HUGETLB is a perf win, but requires cooperation from the
49  // deployment environment (and a change to computeSize()).
50  void* mem = static_cast<void*>(mmap(
51  nullptr,
52  len,
53  PROT_READ | PROT_WRITE,
54  MAP_PRIVATE | MAP_ANONYMOUS | extraflags,
55  -1,
56  0));
57  if (mem == reinterpret_cast<void*>(-1)) {
58  throw std::system_error(errno, std::system_category());
59  }
60 #if !defined(MAP_POPULATE) && defined(MADV_WILLNEED)
61  madvise(mem, size, MADV_WILLNEED);
62 #endif
63 
64  return mem;
65  }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
#define MAP_POPULATE
size_t folly::detail::MMapAlloc::computeSize ( size_t  size)
inlineprivate

Definition at line 32 of file AtomicUnorderedMapUtils.h.

Referenced by allocate(), and deallocate().

32  {
33  long pagesize = sysconf(_SC_PAGESIZE);
34  size_t mmapLength = ((size - 1) & ~(pagesize - 1)) + pagesize;
35  assert(size <= mmapLength && mmapLength < size + pagesize);
36  assert((mmapLength % pagesize) == 0);
37  return mmapLength;
38  }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
void folly::detail::MMapAlloc::deallocate ( void *  p,
size_t  size 
)
inline

Definition at line 67 of file AtomicUnorderedMapUtils.h.

References computeSize().

67  {
68  auto len = computeSize(size);
69  munmap(p, len);
70  }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45

The documentation for this class was generated from the following file: