KASKADE 7 development version
Classes | Public Member Functions | Protected Member Functions | List of all members
Kaskade::Kalloc Class Reference

A simple memory manager for NUMA systems. More...

#include <kalloc.hh>

Detailed Description

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.

Definition at line 39 of file kalloc.hh.

Inheritance diagram for Kaskade::Kalloc:
Kaskade::KallocUnlocked

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...
 

Constructor & Destructor Documentation

◆ Kalloc() [1/2]

Kaskade::Kalloc::Kalloc ( int  node_,
int  align_ = 64,
size_t  blocksize_ = 2 *1024 *1024,
bool  checking = true 
)

Constructor.

Parameters
nodeThe NUMA node on which to allocate memory.
alignThe 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.
blocksizeThe size of memory blocks to be requested from libnuma. Has to be a multiple of \( 4096 \). Defaults to 2^21, which is two MB.
checkingIf true, performs additional usage sanity checks for detecting memory management bugs.

◆ Kalloc() [2/2]

Kaskade::Kalloc::Kalloc ( Kalloc &&  kalloc)

Move Constructor.

◆ ~Kalloc()

Kaskade::Kalloc::~Kalloc ( )

Destructor.

Member Function Documentation

◆ alignment()

size_t Kaskade::Kalloc::alignment ( ) const
inline

Reports the alignment size.

Definition at line 119 of file kalloc.hh.

◆ alloc()

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.

Parameters
nrequested memory size in bytes.

◆ allocUnlocked()

void * Kaskade::Kalloc::allocUnlocked ( size_t  n)
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().

◆ free()

void Kaskade::Kalloc::free ( void *  p,
size_t  n 
)

Releases memory range.

The method is thread-safe.

Parameters
ppointer returned previously by alloc
nmemory size as requrested in the corresponding call to alloc

◆ freeUnlocked()

void Kaskade::Kalloc::freeUnlocked ( void *  p,
size_t  n 
)
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().

◆ print()

std::ostream & Kaskade::Kalloc::print ( std::ostream &  out) const

Prints memory management statistics to the given stream.

◆ reserve()

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.

Parameters
nthe size of the memory blocks to be requested
kthe number of the memory blocks to be requested

The documentation for this class was generated from the following file: