proxygen
folly::CoreRawAllocator< Stripes >::Allocator Class Reference

#include <CacheLocality.h>

Public Member Functions

void * allocate (size_t size)
 
void deallocate (void *mem, size_t=0)
 

Private Member Functions

uint8_t sizeClass (size_t size)
 

Private Attributes

std::array< SimpleAllocator, 4 > allocators_
 

Static Private Attributes

static constexpr size_t AllocSize {4096}
 

Detailed Description

template<size_t Stripes>
class folly::CoreRawAllocator< Stripes >::Allocator

Definition at line 458 of file CacheLocality.h.

Member Function Documentation

template<size_t Stripes>
void* folly::CoreRawAllocator< Stripes >::Allocator::allocate ( size_t  size)
inline

Definition at line 479 of file CacheLocality.h.

References folly::aligned_malloc(), and folly::hardware_destructive_interference_size.

479  {
480  auto cl = sizeClass(size);
481  if (cl == 4) {
482  // Align to a cacheline
485  void* mem =
487  if (!mem) {
488  throw_exception<std::bad_alloc>();
489  }
490  return mem;
491  }
492  return allocators_[cl].allocate();
493  }
constexpr std::size_t hardware_destructive_interference_size
Definition: Align.h:107
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
void * aligned_malloc(size_t size, size_t align)
Definition: Memory.h:85
std::array< SimpleAllocator, 4 > allocators_
template<size_t Stripes>
void folly::CoreRawAllocator< Stripes >::Allocator::deallocate ( void *  mem,
size_t  = 0 
)
inline

Definition at line 494 of file CacheLocality.h.

References addr, folly::aligned_free(), and folly::SimpleAllocator::deallocate().

494  {
495  if (!mem) {
496  return;
497  }
498 
499  // See if it came from this allocator or malloc.
500  if (intptr_t(mem) % 128 != 0) {
501  auto addr =
502  reinterpret_cast<void*>(intptr_t(mem) & ~intptr_t(AllocSize - 1));
503  auto allocator = *static_cast<SimpleAllocator**>(addr);
504  allocator->deallocate(mem);
505  } else {
506  aligned_free(mem);
507  }
508  }
void aligned_free(void *aligned_ptr)
Definition: Memory.h:89
static constexpr size_t AllocSize
ThreadPoolListHook * addr
template<size_t Stripes>
uint8_t folly::CoreRawAllocator< Stripes >::Allocator::sizeClass ( size_t  size)
inlineprivate

Definition at line 461 of file CacheLocality.h.

461  {
462  if (size <= 8) {
463  return 0;
464  } else if (size <= 16) {
465  return 1;
466  } else if (size <= 32) {
467  return 2;
468  } else if (size <= 64) {
469  return 3;
470  } else { // punt to malloc.
471  return 4;
472  }
473  }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45

Member Data Documentation

template<size_t Stripes>
std::array<SimpleAllocator, 4> folly::CoreRawAllocator< Stripes >::Allocator::allocators_
private
Initial value:
{
{{AllocSize, 8}, {AllocSize, 16}, {AllocSize, 32}, {AllocSize, 64}}}

Definition at line 475 of file CacheLocality.h.

template<size_t Stripes>
constexpr size_t folly::CoreRawAllocator< Stripes >::Allocator::AllocSize {4096}
staticprivate

Definition at line 459 of file CacheLocality.h.


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