@ -28,6 +28,7 @@ class Arena {
Arena ( const Arena & ) = delete ;
Arena ( const Arena & ) = delete ;
void operator = ( const Arena & ) = delete ;
void operator = ( const Arena & ) = delete ;
static const size_t kInlineSize = 2048 ;
static const size_t kMinBlockSize ;
static const size_t kMinBlockSize ;
static const size_t kMaxBlockSize ;
static const size_t kMaxBlockSize ;
@ -36,18 +37,19 @@ class Arena {
char * Allocate ( size_t bytes ) ;
char * Allocate ( size_t bytes ) ;
// huge_page_tlb_size: if >0, allocate bytes from huge page TLB and the size
// huge_page_size: if >0, will try to allocate from huage page TLB.
// of the huge page TLB. Bytes will be rounded up to multiple and 2MB and
// The argument will be the size of the page size for huge page TLB. Bytes
// allocate huge pages through mmap anonymous option with huge page on.
// will be rounded up to multiple of the page size to allocate through mmap
// The extra space allocated will be wasted. To enable it, need to reserve
// anonymous option with huge page on. The extra space allocated will be
// huge pages for it to be allocated, like:
// wasted. If allocation fails, will fall back to normal case. To enable it,
// need to reserve huge pages for it to be allocated, like:
// sysctl -w vm.nr_hugepages=20
// sysctl -w vm.nr_hugepages=20
// See linux doc Documentation/vm/hugetlbpage.txt for details.
// See linux doc Documentation/vm/hugetlbpage.txt for details.
// huge page allocation can fail. In this case it will fail back to
// huge page allocation can fail. In this case it will fail back to
// normal cases. The messages will be logged to logger. So when calling with
// normal cases. The messages will be logged to logger. So when calling with
// huge_page_tlb_size > 0, we highly recommend a logger is passed in.
// huge_page_tlb_size > 0, we highly recommend a logger is passed in.
// Otherwise, the error message will be printed out to stderr directly.
// Otherwise, the error message will be printed out to stderr directly.
char * AllocateAligned ( size_t bytes , size_t huge_page_tlb_ size = 0 ,
char * AllocateAligned ( size_t bytes , size_t huge_page_size = 0 ,
Logger * logger = nullptr ) ;
Logger * logger = nullptr ) ;
// Returns an estimate of the total memory usage of data allocated
// Returns an estimate of the total memory usage of data allocated
@ -69,6 +71,7 @@ class Arena {
size_t BlockSize ( ) const { return kBlockSize ; }
size_t BlockSize ( ) const { return kBlockSize ; }
private :
private :
char inline_block_ [ kInlineSize ] ;
// Number of bytes allocated in one block
// Number of bytes allocated in one block
const size_t kBlockSize ;
const size_t kBlockSize ;
// Array of new[] allocated memory blocks
// Array of new[] allocated memory blocks