16 #ifndef IMPALA_RUNTIME_FREE_POOL_H
17 #define IMPALA_RUNTIME_FREE_POOL_H
56 if (FLAGS_disable_mem_pools)
return reinterpret_cast<uint8_t*
>(malloc(size));
59 if (size == 0)
return reinterpret_cast<uint8_t*
>(0x1);
66 if (allocation == NULL) {
68 size = 1 << free_list_idx;
75 DCHECK(allocation != NULL);
79 return reinterpret_cast<uint8_t*
>(allocation) +
sizeof(
FreeListNode);
84 if (FLAGS_disable_mem_pools) {
88 if (ptr == NULL || reinterpret_cast<int64_t>(ptr) == 0x1)
return;
103 if (FLAGS_disable_mem_pools) {
104 return reinterpret_cast<uint8_t*
>(realloc(reinterpret_cast<void*>(ptr), size));
106 if (ptr == NULL || reinterpret_cast<int64_t>(ptr) == 0x1)
return Allocate(size);
112 int bucket_idx = (list - &
lists_[0]);
114 int allocation_size = 1 << bucket_idx;
117 if (allocation_size >= size)
return ptr;
122 memcpy(new_ptr, ptr, allocation_size);
144 for (
int i = 0; i <
NUM_LISTS && !found; ++i) {
145 if (computed_list_ptr == &
lists_[i]) found =
true;
147 DCHECK(found) <<
"Could not find list for ptr: "
148 <<
reinterpret_cast<void*
>(allocation)
149 <<
". Allocation could have already been freed." << std::endl
154 std::stringstream ss;
155 ss <<
"FreePool: " <<
this << std::endl;
158 if (n == NULL)
continue;
161 uint8_t* ptr =
reinterpret_cast<uint8_t*
>(n);
163 ss << reinterpret_cast<void*>(ptr);
165 if (n != NULL) ss <<
"->";
int64_t net_allocations_
Diagnostic counter that tracks (# Allocates - # Frees)
MemTracker * mem_tracker()
FreeListNode lists_[NUM_LISTS]
uint8_t * Reallocate(uint8_t *ptr, int size)
uint8_t * Allocate(int size)
Allocates a buffer of size.
static const int NUM_LISTS
MemTracker * mem_tracker()
std::string DebugString() const
FreePool(MemPool *mem_pool)
This class is thread-safe.
void CheckValidAllocation(FreeListNode *computed_list_ptr, uint8_t *allocation) const
DECLARE_bool(disable_mem_pools)
int64_t net_allocations() const
MemPool * mem_pool_
MemPool to allocate from. Unowned.
uint8_t * Allocate(int size)
static int Log2(uint64_t x)