|
KASKADE 7 development version
|
A simple memory manager for NUMA systems. More...
#include <kalloc.hh>
A simple memory manager for NUMA systems.
The memory manager is not intended to be a drop-in replacement for the standard malloc (and relies itself on standard malloc). It is intended to implement standard allocators for containers that need to store their data on a particular NUMA node.
The memory is managed in two groups.
Public Member Functions | |
| Kalloc (int node_, int align_=64, size_t blocksize_=2 *1024 *1024, bool checking=true) | |
| Constructor. More... | |
| Kalloc (Kalloc &&kalloc) | |
| Move Constructor. More... | |
| ~Kalloc () | |
| Destructor. More... | |
| void * | alloc (size_t n) |
| Allocates n bytes of memory. More... | |
| void | free (void *p, size_t n) |
| Releases memory range. More... | |
| void | reserve (size_t n, size_t k) |
| Tells the allocator that subsequently several blocks of the same size will be requested. More... | |
| size_t | alignment () const |
| Reports the alignment size. More... | |
| std::ostream & | print (std::ostream &out) const |
| Prints memory management statistics to the given stream. More... | |
Protected Member Functions | |
| void * | allocUnlocked (size_t n) |
| Allocates n bytes of memory. More... | |
| void | freeUnlocked (void *p, size_t n) |
| Releases memory range. More... | |
| Kaskade::Kalloc::Kalloc | ( | int | node_, |
| int | align_ = 64, |
||
| size_t | blocksize_ = 2 *1024 *1024, |
||
| bool | checking = true |
||
| ) |
Constructor.
| node | The NUMA node on which to allocate memory. |
| align | The alignment of the memory to return. Has to be a power of 2, and significantly below blocksize. Defaults to common cache line size of 64 bytes. |
| blocksize | The size of memory blocks to be requested from libnuma. Has to be a multiple of \( 4096 \). Defaults to 2^21, which is two MB. |
| checking | If true, performs additional usage sanity checks for detecting memory management bugs. |
| Kaskade::Kalloc::Kalloc | ( | Kalloc && | kalloc | ) |
Move Constructor.
| Kaskade::Kalloc::~Kalloc | ( | ) |
Destructor.
|
inline |
| void * Kaskade::Kalloc::alloc | ( | size_t | n | ) |
Allocates n bytes of memory.
If n exceeds the alignment size, the returned memory range is guaranteed to be aligned as to the value specified on construction.
The method is thread-safe.
| n | requested memory size in bytes. |
|
protected |
Allocates n bytes of memory.
This method is NOT thread-safe. Use this only if you know exactly there's only one thread accessing the allocator.
Referenced by Kaskade::KallocUnlocked::alloc().
| void Kaskade::Kalloc::free | ( | void * | p, |
| size_t | n | ||
| ) |
Releases memory range.
The method is thread-safe.
| p | pointer returned previously by alloc |
| n | memory size as requrested in the corresponding call to alloc |
|
protected |
Releases memory range.
This method is NOT thread-safe. Use this only if you know exactly there's only one thread accessing the allocator.
Referenced by Kaskade::KallocUnlocked::free().
| std::ostream & Kaskade::Kalloc::print | ( | std::ostream & | out | ) | const |
Prints memory management statistics to the given stream.
| void Kaskade::Kalloc::reserve | ( | size_t | n, |
| size_t | k | ||
| ) |
Tells the allocator that subsequently several blocks of the same size will be requested.
This is a hint to the allocator that can improve its performance.
| n | the size of the memory blocks to be requested |
| k | the number of the memory blocks to be requested |