CernVM-FS
2.12.0
|
#include <malloc_heap.h>
Classes | |
struct | BlockPtr |
struct | Tag |
Public Types | |
typedef Callbackable< BlockPtr > ::CallbackTN * | CallbackPtr |
Public Member Functions | |
MallocHeap (uint64_t capacity, CallbackPtr callback_ptr) | |
~MallocHeap () | |
void * | Allocate (uint64_t size, void *header, unsigned header_size) |
void * | Expand (void *block, uint64_t new_size) |
void | MarkFree (void *block) |
uint64_t | GetSize (void *block) |
void | Compact () |
uint64_t | num_blocks () |
uint64_t | used_bytes () |
uint64_t | stored_bytes () |
uint64_t | compacted_bytes () |
uint64_t | capacity () |
double | utilization () |
bool | HasSpaceFor (uint64_t nbytes) |
Private Attributes | |
CallbackPtr | callback_ptr_ |
uint64_t | capacity_ |
uint64_t | gauge_ |
uint64_t | stored_ |
uint64_t | num_blocks_ |
unsigned char * | heap_ |
Static Private Attributes | |
static const unsigned | kMinCapacity = 1024 |
This file is part of the CernVM File System. Fills an ever-growing heap. Free calls simply mark a block as free but allocation continues to take place at the top of the heap. Hence Realloc() is inefficient. For the common pattern of doubling a buffer with realloc, twice the final buffer size is required.
The allocator is copying and can collect garbage. In order to react on the move of a block, a callback can be registered that gets called with the new pointer address. The user of the MallocHeap has to make sure to identify any block based on the first bytes. Therefore, allocation requires these first bytes, a user-defined "header" if you will. Note that during a Compact() not even reading from any of the pointers is allowed!
MallocHeap is used by the in-memory object cache. The header is the object's content hash, so the cache manager can identify any block in its hash table and move the pointers when MallocHeap runs a garbage collection.
All memory blocks are 8-byte aligned and they have an 8-byte header containing their size. The size is negative for free blocks.
Definition at line 36 of file malloc_heap.h.
typedef Callbackable<BlockPtr>::CallbackTN* MallocHeap::CallbackPtr |
Definition at line 46 of file malloc_heap.h.
MallocHeap::MallocHeap | ( | uint64_t | capacity, |
CallbackPtr | callback_ptr | ||
) |
MallocHeap::~MallocHeap | ( | ) |
Definition at line 128 of file malloc_heap.cc.
void * MallocHeap::Allocate | ( | uint64_t | size, |
void * | header, | ||
unsigned | header_size | ||
) |
Definition at line 16 of file malloc_heap.cc.
Referenced by MemoryKvStore::DoMalloc().
|
inline |
Definition at line 63 of file malloc_heap.h.
void MallocHeap::Compact | ( | ) |
Definition at line 39 of file malloc_heap.cc.
Referenced by MemoryKvStore::CompactMemory().
|
inline |
Definition at line 60 of file malloc_heap.h.
void * MallocHeap::Expand | ( | void * | block, |
uint64_t | new_size | ||
) |
uint64_t MallocHeap::GetSize | ( | void * | block | ) |
bool MallocHeap::HasSpaceFor | ( | uint64_t | nbytes | ) |
void MallocHeap::MarkFree | ( | void * | block | ) |
Definition at line 94 of file malloc_heap.cc.
Referenced by MemoryKvStore::DoFree().
|
inline |
Definition at line 57 of file malloc_heap.h.
|
inline |
Definition at line 59 of file malloc_heap.h.
|
inline |
Definition at line 58 of file malloc_heap.h.
|
inline |
Definition at line 64 of file malloc_heap.h.
Referenced by MemoryKvStore::CompactMemory().
|
private |
Invoked when a block is moved during compact.
Definition at line 103 of file malloc_heap.h.
|
private |
Total size of mmap'd arena.
Definition at line 107 of file malloc_heap.h.
Referenced by capacity(), MallocHeap(), and ~MallocHeap().
|
private |
End of the area of reserved blocks, used for the next allocation.
Definition at line 111 of file malloc_heap.h.
Referenced by used_bytes(), and utilization().
|
private |
The big mmap'd memory block used to serve allocation requests.
Definition at line 123 of file malloc_heap.h.
Referenced by MallocHeap(), and ~MallocHeap().
|
staticprivate |
Minimum number of bytes of the heap.
Definition at line 73 of file malloc_heap.h.
Referenced by MallocHeap().
|
private |
Number of reserved blocks
Definition at line 119 of file malloc_heap.h.
Referenced by compacted_bytes(), and num_blocks().
|
private |
Sum of the non-free block sizes.
Definition at line 115 of file malloc_heap.h.
Referenced by compacted_bytes(), stored_bytes(), and utilization().