Thrill  0.1
thrill::mem Namespace Reference

Classes

class  AlignedAllocator
 
struct  AlignedAllocatorSettings
 
class  Allocator
 
class  Allocator< void >
 
class  Deleter
 std::default_deleter with Manager tracking More...
 
class  FixedAllocator
 
class  FixedAllocator< void, manager_ >
 
class  FixedPoolAllocator
 
class  GPoolDeleter
 deleter for unique_ptr with memory from mem::g_pool. More...
 
class  Manager
 Object shared by allocators and other classes to track memory allocations. More...
 
class  Pool
 A simple memory allocation manager. More...
 
class  PoolAllocator
 

Typedefs

using aligned_alloc_type = void *(*)(size_t, size_t)
 
template<typename T >
using by_deque = std::deque< T, BypassAllocator< T > >
 deque without malloc tracking More...
 
using by_string = std::basic_string< char, std::char_traits< char >, BypassAllocator< char > >
 string without malloc tracking More...
 
using by_stringbuf = std::basic_stringbuf< char, std::char_traits< char >, BypassAllocator< char > >
 stringbuf without malloc tracking More...
 
template<typename T >
using by_vector = std::vector< T, BypassAllocator< T > >
 vector without malloc tracking More...
 
template<typename Type >
using BypassAllocator = FixedAllocator< Type, g_bypass_manager >
 instantiate FixedAllocator as BypassAllocator More...
 
using CounterType = ssize_t
 
template<typename T >
using deque = std::deque< T, Allocator< T > >
 deque with Manager tracking More...
 
using free_type = void(*)(void *)
 
template<typename Type >
using GPoolAllocator = FixedPoolAllocator< Type, GPool >
 template alias for allocating from mem::g_pool. More...
 
using malloc_type = void *(*)(size_t)
 function pointer to the real procedures, loaded using dlsym() More...
 
using realloc_type = void *(*)(void *, size_t)
 
using safe_ostringstream = std::basic_ostringstream< char, std::char_traits< char >, mem::GPoolAllocator< char > >
 
using safe_string = std::basic_string< char, std::char_traits< char >, mem::GPoolAllocator< char > >
 
template<typename T >
using safe_unique_ptr = std::unique_ptr< T, GPoolDeleter< T > >
 unique_ptr with memory from mem::g_pool. More...
 
using string = std::basic_string< char, std::char_traits< char >, Allocator< char > >
 string with Manager tracking More...
 
using stringbuf = std::basic_stringbuf< char, std::char_traits< char >, Allocator< char > >
 stringbuf with Manager tracking More...
 
template<typename T >
using unique_ptr = std::unique_ptr< T, Deleter< T > >
 unique_ptr with Manager tracking More...
 
template<typename T >
using vector = std::vector< T, Allocator< T > >
 vector with Manager tracking More...
 

Functions

static void * aligned_alloc (size_t size, size_t meta_info_size=0)
 
static void aligned_dealloc (void *ptr, size_t size, size_t meta_info_size=0)
 
static size_t bin_lower_bound (size_t bin)
 lowest size still in bin More...
 
template<typename T >
void by_delete (T *value)
 operator delete with our Allocator More...
 
template<typename T , typename... Args>
Tby_new (Args &&... args)
 operator new with our Allocator More...
 
void * bypass_aligned_alloc (size_t alignment, size_t size) noexcept
 bypass malloc tracker and access aligned_alloc() directly More...
 
void bypass_aligned_free (void *ptr, size_t size) noexcept
 bypass malloc tracker and access aligned_alloc() directly More...
 
void bypass_free (void *ptr, size_t size) noexcept
 bypass malloc tracker and access free() directly More...
 
void * bypass_malloc (size_t size) noexcept
 bypass malloc tracker and access malloc() directly More...
 
static size_t calc_bin_for_size (size_t size)
 determine bin for size. More...
 
static void dec_count (size_t dec)
 decrement allocation to statistics More...
 
void flush_memory_statistics ()
 method to flush thread-local memory statistics when memory_exceeded More...
 
Manager g_bypass_manager (nullptr, "Bypass")
 
static ssize_t get (const CounterType &a)
 
PoolGPool ()
 singleton instance of global pool for I/O data structures More...
 
static void inc_count (size_t inc)
 add allocation to statistics More...
 
template<typename T , typename... Args>
unique_ptr< Tmake_unique (Manager &manager, Args &&... args)
 make_unique with Manager tracking More...
 
ssize_t malloc_tracker_current ()
 user function to return the currently allocated amount of memory More...
 
ssize_t malloc_tracker_peak ()
 user function to return the peak allocation More...
 
void malloc_tracker_print_leaks ()
 user function which prints new unfreed areas to stdout since the last call More...
 
void malloc_tracker_print_status ()
 user function which prints current and peak allocation to stderr More...
 
void malloc_tracker_reset_peak ()
 user function to reset the peak allocation to current More...
 
ssize_t malloc_tracker_total_allocs ()
 user function to return total number of allocations More...
 
template<typename T >
void mm_delete (Manager &manager, T *value)
 operator delete with our Allocator More...
 
template<typename T , typename... Args>
Tmm_new (Manager &manager, Args &&... args)
 operator new with our Allocator More...
 
template<typename T , typename... Args>
safe_unique_ptr< Tsafe_make_unique (Args &&... args)
 make_unique with Manager tracking More...
 
void set_memory_limit_indication (ssize_t size)
 
void StartMemProfiler (common::ProfileThread &sched, common::JsonLogger &logger)
 launch profiler task More...
 
static ssize_t sync_add_and_fetch (CounterType &curr, ssize_t inc)
 
static ssize_t sync_sub_and_fetch (CounterType &curr, ssize_t dec)
 
static by_string to_string (int val)
 convert to string More...
 
static by_string to_string (unsigned val)
 convert to string More...
 
static by_string to_string (long val)
 convert to string More...
 
static by_string to_string (unsigned long val)
 convert to string More...
 
static by_string to_string (long long val)
 convert to string More...
 
static by_string to_string (unsigned long long val)
 convert to string More...
 
static void update_memprofile (ssize_t float_current, ssize_t base_current)
 
void update_peak (ssize_t float_curr, ssize_t base_curr)
 

Variables

static CounterType base_curr { 0 }
 
static CounterType current_allocs { 0 }
 
static CounterType float_curr { 0 }
 
Manager g_bypass_manager
 global bypass memory manager More...
 
static constexpr size_t init_alignment = sizeof(size_t)
 align allocations to init_heap to this number by rounding up allocations More...
 
static char init_heap [1024 *1024]
 
static CounterType init_heap_use { 0 }
 
static constexpr bool log_bypass_operations = 0
 
static constexpr size_t log_bypass_operations_threshold = 100000
 
static constexpr bool log_operations = 0
 
static constexpr int log_operations_init_heap = 0
 
static constexpr size_t log_operations_threshold = 100000
 
bool memory_exceeded = false
 memory limit exceeded indicator More...
 
ssize_t memory_limit_indication = std::numeric_limits<ssize_t>::max()
 
static OhlcBar mp_base
 
static constexpr bool mp_enable = true
 
static OhlcBar mp_float
 
static CounterType mp_next_bar { 0 }
 
static constexpr size_t padding = 16
 
static CounterType peak_bytes { 0 }
 
static constexpr bool profile_bypass_operations = 0
 
static constexpr bool profile_operations = 0
 
static aligned_alloc_type real_aligned_alloc = nullptr
 
static free_type real_free = nullptr
 
static malloc_type real_malloc = nullptr
 
static realloc_type real_realloc = nullptr
 
static constexpr size_t sentinel = 0xDEADC0DE
 a sentinel value prefixed to each allocation More...
 
static const ssize_t tl_delay_threshold = 1024 * 1024
 
static thread_local LocalStats tl_stats = { 0, 0, 0 }
 
static CounterType total_allocs { 0 }
 
static CounterType total_bytes { 0 }
 

Typedef Documentation

◆ aligned_alloc_type

using aligned_alloc_type = void* (*)(size_t, size_t)

Definition at line 91 of file malloc_tracker.cpp.

◆ by_deque

using by_deque = std::deque<T, BypassAllocator<T> >

deque without malloc tracking

Definition at line 188 of file allocator_base.hpp.

◆ by_string

using by_string = std::basic_string< char, std::char_traits<char>, BypassAllocator<char> >

string without malloc tracking

Definition at line 176 of file allocator_base.hpp.

◆ by_stringbuf

using by_stringbuf = std::basic_stringbuf< char, std::char_traits<char>, BypassAllocator<char> >

stringbuf without malloc tracking

Definition at line 180 of file allocator_base.hpp.

◆ by_vector

using by_vector = std::vector<T, BypassAllocator<T> >

vector without malloc tracking

Definition at line 184 of file allocator_base.hpp.

◆ BypassAllocator

instantiate FixedAllocator as BypassAllocator

Definition at line 152 of file allocator_base.hpp.

◆ CounterType

using CounterType = ssize_t

CounterType is used for atomic counters, and get to retrieve their contents. Due to the thread-local cached statistics, the overall memory usage counter can actually go negative!

Definition at line 111 of file malloc_tracker.cpp.

◆ deque

using deque = std::deque<T, Allocator<T> >

deque with Manager tracking

Definition at line 232 of file allocator.hpp.

◆ free_type

using free_type = void (*)(void*)

Definition at line 89 of file malloc_tracker.cpp.

◆ GPoolAllocator

template alias for allocating from mem::g_pool.

Definition at line 330 of file pool.hpp.

◆ malloc_type

using malloc_type = void* (*)(size_t)

function pointer to the real procedures, loaded using dlsym()

Definition at line 88 of file malloc_tracker.cpp.

◆ realloc_type

using realloc_type = void* (*)(void*, size_t)

Definition at line 90 of file malloc_tracker.cpp.

◆ safe_ostringstream

using safe_ostringstream = std::basic_ostringstream< char, std::char_traits<char>, mem::GPoolAllocator<char> >

alias for std::ostringstream except that it uses the safer g_pool as allocator for the internal string buffer

Definition at line 362 of file pool.hpp.

◆ safe_string

using safe_string = std::basic_string< char, std::char_traits<char>, mem::GPoolAllocator<char> >

alias for std::string except that its memory is allocated in the safer g_pool.

Definition at line 357 of file pool.hpp.

◆ safe_unique_ptr

using safe_unique_ptr = std::unique_ptr<T, GPoolDeleter<T> >

unique_ptr with memory from mem::g_pool.

Definition at line 345 of file pool.hpp.

◆ string

using string = std::basic_string< char, std::char_traits<char>, Allocator<char> >

string with Manager tracking

Examples:
examples/tutorial/k-means_step5.cpp, and examples/tutorial/k-means_step6.cpp.

Definition at line 220 of file allocator.hpp.

◆ stringbuf

using stringbuf = std::basic_stringbuf< char, std::char_traits<char>, Allocator<char> >

stringbuf with Manager tracking

Definition at line 224 of file allocator.hpp.

◆ unique_ptr

using unique_ptr = std::unique_ptr<T, Deleter<T> >

unique_ptr with Manager tracking

Definition at line 208 of file allocator.hpp.

◆ vector

using vector = std::vector<T, Allocator<T> >

vector with Manager tracking

Definition at line 228 of file allocator.hpp.

Function Documentation

◆ aligned_alloc()

static void* thrill::mem::aligned_alloc ( size_t  size,
size_t  meta_info_size = 0 
)
inlinestatic

Definition at line 207 of file aligned_allocator.hpp.

◆ aligned_dealloc()

static void thrill::mem::aligned_dealloc ( void *  ptr,
size_t  size,
size_t  meta_info_size = 0 
)
inlinestatic

Definition at line 212 of file aligned_allocator.hpp.

◆ bin_lower_bound()

static size_t thrill::mem::bin_lower_bound ( size_t  bin)
inlinestatic

lowest size still in bin

Definition at line 398 of file pool.cpp.

Referenced by Pool::ArenaFindFree().

◆ by_delete()

void thrill::mem::by_delete ( T value)

operator delete with our Allocator

Definition at line 165 of file allocator_base.hpp.

References FixedAllocator< Type, manager_ >::deallocate(), and AllocatorBase< Type >::destroy().

◆ by_new()

T* thrill::mem::by_new ( Args &&...  args)

◆ bypass_aligned_alloc()

void * bypass_aligned_alloc ( size_t  alignment,
size_t  size 
)
noexcept

◆ bypass_aligned_free()

void bypass_aligned_free ( void *  ptr,
size_t  size 
)
noexcept

◆ bypass_free()

void bypass_free ( void *  ptr,
size_t  size 
)
noexcept

◆ bypass_malloc()

◆ calc_bin_for_size()

static size_t thrill::mem::calc_bin_for_size ( size_t  size)
inlinestatic

determine bin for size.

Definition at line 390 of file pool.cpp.

References tlx::integer_log2_floor_template().

Referenced by Pool::allocate(), Pool::AllocateFreeArena(), Pool::ArenaFindFree(), Pool::deallocate(), and Pool::print().

◆ dec_count()

static void thrill::mem::dec_count ( size_t  dec)
static

◆ flush_memory_statistics()

void flush_memory_statistics ( )

method to flush thread-local memory statistics when memory_exceeded

Definition at line 203 of file malloc_tracker.cpp.

References ATTRIBUTE_NO_SANITIZE, base_curr, current_allocs, float_curr, memory_limit_indication, sync_add_and_fetch(), total_allocs, total_bytes, update_memprofile(), and update_peak().

Referenced by dec_count(), and inc_count().

◆ g_bypass_manager()

Manager thrill::mem::g_bypass_manager ( nullptr  ,
"Bypass"   
)

◆ get()

◆ GPool()

◆ inc_count()

static void thrill::mem::inc_count ( size_t  inc)
static

◆ make_unique()

unique_ptr<T> thrill::mem::make_unique ( Manager manager,
Args &&...  args 
)

make_unique with Manager tracking

Definition at line 212 of file allocator.hpp.

◆ malloc_tracker_current()

ssize_t malloc_tracker_current ( )

user function to return the currently allocated amount of memory

returns the currently allocated amount of memory

Definition at line 267 of file malloc_tracker.cpp.

References float_curr.

◆ malloc_tracker_peak()

ssize_t malloc_tracker_peak ( )

user function to return the peak allocation

returns the current peak memory allocation

Definition at line 272 of file malloc_tracker.cpp.

References peak_bytes.

◆ malloc_tracker_print_leaks()

◆ malloc_tracker_print_status()

void malloc_tracker_print_status ( )

user function which prints current and peak allocation to stderr

Definition at line 287 of file malloc_tracker.cpp.

References base_curr, float_curr, peak_bytes, and PPREFIX.

Referenced by thrill::data::OurNewHandler(), and DIABase::RunScope().

◆ malloc_tracker_reset_peak()

void malloc_tracker_reset_peak ( )

user function to reset the peak allocation to current

resets the peak memory allocation to current

Definition at line 277 of file malloc_tracker.cpp.

References float_curr, and peak_bytes.

◆ malloc_tracker_total_allocs()

ssize_t malloc_tracker_total_allocs ( )

user function to return total number of allocations

returns the total number of allocations

Definition at line 282 of file malloc_tracker.cpp.

References total_allocs.

◆ mm_delete()

void thrill::mem::mm_delete ( Manager manager,
T value 
)

operator delete with our Allocator

Definition at line 180 of file allocator.hpp.

References Allocator< Type >::deallocate(), and AllocatorBase< Type >::destroy().

◆ mm_new()

T* thrill::mem::mm_new ( Manager manager,
Args &&...  args 
)

operator new with our Allocator

Definition at line 171 of file allocator.hpp.

References Allocator< Type >::allocate(), AllocatorBase< Type >::construct(), and gen_data::value.

◆ safe_make_unique()

safe_unique_ptr<T> thrill::mem::safe_make_unique ( Args &&...  args)

make_unique with Manager tracking

Definition at line 349 of file pool.hpp.

References GPool(), and Pool::make().

◆ set_memory_limit_indication()

void set_memory_limit_indication ( ssize_t  size)

set the malloc tracking system to set memory_exceeded when this limit is exceed. it does not actually limit allocation!

Definition at line 292 of file malloc_tracker.cpp.

Referenced by MemoryConfig::apply().

◆ StartMemProfiler()

void StartMemProfiler ( common::ProfileThread sched,
common::JsonLogger logger 
)

◆ sync_add_and_fetch()

static ssize_t thrill::mem::sync_add_and_fetch ( CounterType curr,
ssize_t  inc 
)
inlinestatic

◆ sync_sub_and_fetch()

static ssize_t thrill::mem::sync_sub_and_fetch ( CounterType curr,
ssize_t  dec 
)
inlinestatic

Definition at line 136 of file malloc_tracker.cpp.

Referenced by bypass_aligned_free(), bypass_free(), and dec_count().

◆ to_string() [1/6]

◆ to_string() [2/6]

static by_string thrill::mem::to_string ( unsigned  val)
inlinestatic

convert to string

Definition at line 196 of file allocator_base.hpp.

◆ to_string() [3/6]

static by_string thrill::mem::to_string ( long  val)
inlinestatic

convert to string

Definition at line 201 of file allocator_base.hpp.

◆ to_string() [4/6]

static by_string thrill::mem::to_string ( unsigned long  val)
inlinestatic

convert to string

Definition at line 206 of file allocator_base.hpp.

◆ to_string() [5/6]

static by_string thrill::mem::to_string ( long long  val)
inlinestatic

convert to string

Definition at line 211 of file allocator_base.hpp.

◆ to_string() [6/6]

static by_string thrill::mem::to_string ( unsigned long long  val)
inlinestatic

convert to string

Definition at line 216 of file allocator_base.hpp.

◆ update_memprofile()

static void update_memprofile ( ssize_t  float_current,
ssize_t  base_current 
)
static

◆ update_peak()

void thrill::mem::update_peak ( ssize_t  float_curr,
ssize_t  base_curr 
)

Variable Documentation

◆ base_curr

◆ current_allocs

◆ float_curr

◆ g_bypass_manager

Manager g_bypass_manager(nullptr, "Bypass")

global bypass memory manager

Referenced by Manager::~Manager().

◆ init_alignment

constexpr size_t init_alignment = sizeof(size_t)
static

align allocations to init_heap to this number by rounding up allocations

Definition at line 151 of file malloc_tracker.cpp.

Referenced by preinit_malloc().

◆ init_heap

char init_heap[1024 *1024]
static

Definition at line 146 of file malloc_tracker.cpp.

Referenced by free(), malloc_tracker_print_leaks(), preinit_malloc(), and realloc().

◆ init_heap_use

CounterType init_heap_use { 0 }
static

Definition at line 147 of file malloc_tracker.cpp.

Referenced by free(), malloc_tracker_print_leaks(), preinit_malloc(), and realloc().

◆ log_bypass_operations

constexpr bool log_bypass_operations = 0
static

Definition at line 65 of file malloc_tracker.cpp.

◆ log_bypass_operations_threshold

constexpr size_t log_bypass_operations_threshold = 100000
static

Definition at line 68 of file malloc_tracker.cpp.

◆ log_operations

constexpr bool log_operations = 0
static

Definition at line 64 of file malloc_tracker.cpp.

Referenced by free(), malloc(), malloc_tracker_print_leaks(), and realloc().

◆ log_operations_init_heap

constexpr int log_operations_init_heap = 0
static

Definition at line 148 of file malloc_tracker.cpp.

Referenced by preinit_free(), preinit_malloc(), and preinit_realloc().

◆ log_operations_threshold

constexpr size_t log_operations_threshold = 100000
static

Definition at line 67 of file malloc_tracker.cpp.

Referenced by free(), malloc(), malloc_tracker_print_leaks(), and realloc().

◆ memory_exceeded

◆ memory_limit_indication

ssize_t memory_limit_indication = std::numeric_limits<ssize_t>::max()

Definition at line 173 of file malloc_tracker.cpp.

Referenced by dec_count(), flush_memory_statistics(), and inc_count().

◆ mp_base

OhlcBar mp_base
static

Definition at line 321 of file malloc_tracker.cpp.

Referenced by update_memprofile().

◆ mp_enable

constexpr bool mp_enable = true
static

Definition at line 300 of file malloc_tracker.cpp.

◆ mp_float

OhlcBar mp_float
static

Definition at line 321 of file malloc_tracker.cpp.

◆ mp_next_bar

CounterType mp_next_bar { 0 }
static

Definition at line 302 of file malloc_tracker.cpp.

Referenced by update_memprofile().

◆ padding

◆ peak_bytes

◆ profile_bypass_operations

constexpr bool profile_bypass_operations = 0
static

Definition at line 72 of file malloc_tracker.cpp.

◆ profile_operations

constexpr bool profile_operations = 0
static

Definition at line 71 of file malloc_tracker.cpp.

Referenced by malloc_tracker_print_leaks().

◆ real_aligned_alloc

aligned_alloc_type real_aligned_alloc = nullptr
static

Definition at line 96 of file malloc_tracker.cpp.

Referenced by bypass_aligned_alloc().

◆ real_free

free_type real_free = nullptr
static

◆ real_malloc

malloc_type real_malloc = nullptr
static

◆ real_realloc

realloc_type real_realloc = nullptr
static

Definition at line 95 of file malloc_tracker.cpp.

◆ sentinel

◆ tl_delay_threshold

const ssize_t tl_delay_threshold = 1024 * 1024
static

Definition at line 193 of file malloc_tracker.cpp.

◆ tl_stats

thread_local LocalStats tl_stats = { 0, 0, 0 }
static

Definition at line 192 of file malloc_tracker.cpp.

◆ total_allocs

◆ total_bytes

CounterType total_bytes { 0 }
static