Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
|
#include <free-pool.h>
Classes | |
struct | FreeListNode |
Public Member Functions | |
FreePool (MemPool *mem_pool) | |
uint8_t * | Allocate (int size) |
Allocates a buffer of size. More... | |
void | Free (uint8_t *ptr) |
uint8_t * | Reallocate (uint8_t *ptr, int size) |
MemTracker * | mem_tracker () |
int64_t | net_allocations () const |
Private Member Functions | |
void | CheckValidAllocation (FreeListNode *computed_list_ptr, uint8_t *allocation) const |
std::string | DebugString () const |
Private Attributes | |
MemPool * | mem_pool_ |
MemPool to allocate from. Unowned. More... | |
FreeListNode | lists_ [NUM_LISTS] |
int64_t | net_allocations_ |
Diagnostic counter that tracks (# Allocates - # Frees) More... | |
Static Private Attributes | |
static const int | NUM_LISTS = 64 |
Implementation of a free pool to recycle allocations. The pool is broken up into 64 lists, one for each power of 2. Each allocation is rounded up to the next power of 2. When the allocation is freed, it is added to the corresponding free list. Each allocation has an 8 byte header that immediately precedes the actual allocation. If the allocation is owned by the user, the header contains the ptr to the list that it should be added to on Free(). When the allocation is in the pool (i.e. available to be handed out), it contains the link to the next allocation. This has O(1) Allocate() and Free(). This is not thread safe. TODO: consider integrating this with MemPool. TODO: consider changing to something more granular than doubling.
Definition at line 43 of file free-pool.h.
|
inline |
C'tor, initializes the FreePool to be empty. All allocations come from the 'mem_pool'.
Definition at line 47 of file free-pool.h.
References lists_.
|
inline |
Allocates a buffer of size.
This is the typical malloc behavior. NULL is reserved for failures.
Do ceil(log_2(size))
Definition at line 54 of file free-pool.h.
References impala::MemPool::Allocate(), impala::FreePool::FreeListNode::list, lists_, impala::BitUtil::Log2(), mem_pool_, net_allocations_, impala::FreePool::FreeListNode::next, and NUM_LISTS.
Referenced by impala::FunctionContextImpl::AllocateLocal(), Reallocate(), and impala::TEST().
|
inlineprivate |
Definition at line 141 of file free-pool.h.
References DebugString(), lists_, and NUM_LISTS.
Referenced by Free(), and Reallocate().
|
inlineprivate |
Definition at line 153 of file free-pool.h.
References lists_, impala::FreePool::FreeListNode::next, and NUM_LISTS.
Referenced by CheckValidAllocation().
|
inline |
Definition at line 82 of file free-pool.h.
References CheckValidAllocation(), impala::FreePool::FreeListNode::list, net_allocations_, and impala::FreePool::FreeListNode::next.
Referenced by impala::FunctionContextImpl::FreeLocalAllocations(), Reallocate(), and impala::TEST().
|
inline |
Definition at line 127 of file free-pool.h.
References mem_pool_, and impala::MemPool::mem_tracker().
|
inline |
Definition at line 128 of file free-pool.h.
References net_allocations_.
Referenced by impala::FunctionContextImpl::Close().
|
inline |
Returns an allocation that is at least 'size'. If the current allocation backing 'ptr' is big enough, 'ptr' is returned. Otherwise a new one is made and the contents of ptr are copied into it.
Definition at line 102 of file free-pool.h.
References Allocate(), CheckValidAllocation(), Free(), impala::FreePool::FreeListNode::list, and lists_.
Referenced by impala::TEST().
|
private |
One list head for each allocation size indexed by the LOG_2 of the allocation size. While it doesn't make too much sense to use this for very small (e.g. 8 byte) allocations, it makes the indexing easy.
Definition at line 178 of file free-pool.h.
Referenced by Allocate(), CheckValidAllocation(), DebugString(), FreePool(), and Reallocate().
|
private |
MemPool to allocate from. Unowned.
Definition at line 173 of file free-pool.h.
Referenced by Allocate(), and mem_tracker().
|
private |
Diagnostic counter that tracks (# Allocates - # Frees)
Definition at line 181 of file free-pool.h.
Referenced by Allocate(), Free(), and net_allocations().
|
staticprivate |
Definition at line 131 of file free-pool.h.
Referenced by Allocate(), CheckValidAllocation(), and DebugString().