|
Thrill
0.1
|
#include <thrill/common/json_logger.hpp>#include <thrill/common/porting.hpp>#include <thrill/common/profile_thread.hpp>#include <thrill/mem/malloc_tracker.hpp>#include <tlx/backtrace.hpp>#include <tlx/define.hpp>#include <algorithm>#include <atomic>#include <chrono>#include <cstdio>#include <cstdlib>#include <cstring>#include <limits>#include <mutex>#include <utility>
Include dependency graph for malloc_tracker.cpp:Go to the source code of this file.
Namespaces | |
| thrill | |
| thrill::mem | |
Macros | |
| #define | _GNU_SOURCE |
| #define | ATTRIBUTE_NO_SANITIZE |
| #define | BYPASS_CHECKER 0 |
| #define | COUNTER_ZERO { 0 } |
| #define | HAVE_THREAD_LOCAL 1 |
| #define | INIT_HEAP_SIZE 1024 * 1024 |
| a simple memory heap for allocations prior to dlsym loading More... | |
| #define | LEAK_CHECKER 0 |
| #define | PPREFIX "malloc_tracker ### " |
| output More... | |
| #define | USE_ATOMICS 0 |
Typedefs | |
| using | aligned_alloc_type = void *(*)(size_t, size_t) |
| using | CounterType = ssize_t |
| using | free_type = void(*)(void *) |
| using | malloc_type = void *(*)(size_t) |
| function pointer to the real procedures, loaded using dlsym() More... | |
| using | realloc_type = void *(*)(void *, size_t) |
Functions | |
| 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... | |
| void * | calloc (size_t nmemb, size_t size) NOEXCEPT |
| 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... | |
| void | free (void *ptr) NOEXCEPT |
| exported free symbol that overrides loading from libc More... | |
| static ssize_t | get (const CounterType &a) |
| static void | inc_count (size_t inc) |
| add allocation to statistics More... | |
| void * | malloc (size_t size) NOEXCEPT |
| exported malloc symbol that overrides loading from libc 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... | |
| static void | preinit_free (void *ptr) |
| static void * | preinit_malloc (size_t size) noexcept |
| static void * | preinit_realloc (void *ptr, size_t size) |
| void * | realloc (void *ptr, size_t size) NOEXCEPT |
| exported realloc() symbol that overrides loading from libc 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 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 } |
| 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 } |
| #define _GNU_SOURCE |
Definition at line 12 of file malloc_tracker.cpp.
| #define ATTRIBUTE_NO_SANITIZE |
Definition at line 54 of file malloc_tracker.cpp.
Referenced by thrill::mem::bypass_aligned_alloc(), thrill::mem::bypass_aligned_free(), thrill::mem::bypass_free(), thrill::mem::bypass_malloc(), calloc(), thrill::mem::flush_memory_statistics(), free(), thrill::mem::get(), thrill::mem::inc_count(), malloc(), thrill::mem::malloc_tracker_print_leaks(), preinit_malloc(), preinit_realloc(), thrill::mem::StartMemProfiler(), thrill::mem::sync_add_and_fetch(), thrill::mem::update_memprofile(), and thrill::mem::update_peak().
| #define BYPASS_CHECKER 0 |
Definition at line 75 of file malloc_tracker.cpp.
| #define COUNTER_ZERO { 0 } |
Definition at line 115 of file malloc_tracker.cpp.
| #define HAVE_THREAD_LOCAL 1 |
Definition at line 186 of file malloc_tracker.cpp.
| #define INIT_HEAP_SIZE 1024 * 1024 |
a simple memory heap for allocations prior to dlsym loading
Definition at line 145 of file malloc_tracker.cpp.
Referenced by preinit_malloc().
| #define LEAK_CHECKER 0 |
Definition at line 78 of file malloc_tracker.cpp.
| #define PPREFIX "malloc_tracker ### " |
output
Definition at line 154 of file malloc_tracker.cpp.
Referenced by thrill::mem::bypass_aligned_alloc(), thrill::mem::bypass_aligned_free(), thrill::mem::bypass_free(), thrill::mem::bypass_malloc(), free(), malloc(), thrill::mem::malloc_tracker_print_leaks(), thrill::mem::malloc_tracker_print_status(), preinit_free(), preinit_malloc(), preinit_realloc(), realloc(), and thrill::mem::StartMemProfiler().
| #define USE_ATOMICS 0 |
Definition at line 101 of file malloc_tracker.cpp.
| void* calloc | ( | size_t | nmemb, |
| size_t | size | ||
| ) |
exported calloc() symbol that overrides loading from libc, implemented using our malloc
Definition at line 1076 of file malloc_tracker.cpp.
References ATTRIBUTE_NO_SANITIZE, and malloc().
Referenced by thrill::mem::malloc_tracker_print_leaks().
| void free | ( | void * | ptr | ) |
exported free symbol that overrides loading from libc
free(nullptr) is no operation
Definition at line 1038 of file malloc_tracker.cpp.
References ATTRIBUTE_NO_SANITIZE, thrill::mem::base_curr, thrill::mem::dec_count(), thrill::mem::float_curr, thrill::mem::init_heap, thrill::mem::init_heap_use, thrill::mem::log_operations, thrill::mem::log_operations_threshold, thrill::mem::padding, PPREFIX, preinit_free(), thrill::mem::real_free, and thrill::mem::sentinel.
Referenced by foxxll::aligned_alloc(), foxxll::aligned_dealloc(), AlignedAllocator< Byte, thrill::mem::Allocator< char > >::allocate_bytes(), thrill::mem::bypass_free(), StackArena< Size >::deallocate(), BufferBuilder::Deallocate(), ReduceBucketHashTable< TableItem, Key, Value, KeyExtractor, ReduceFunction, Emitter, VolatileKey, ReduceConfig, IndexFunction, KeyEqualFunction >::BucketBlockPool::Deallocate(), ReduceBucketHashTable< TableItem, Key, Value, KeyExtractor, ReduceFunction, Emitter, VolatileKey, ReduceConfig, IndexFunction, KeyEqualFunction >::BucketBlockPool::Destroy(), memory_file::discard(), ReduceBucketHashTable< TableItem, Key, Value, KeyExtractor, ReduceFunction, Emitter, VolatileKey, ReduceConfig, IndexFunction, KeyEqualFunction >::BucketBlockPool::GetBlock(), thrill::mem::malloc_tracker_print_leaks(), Buffer::operator=(), BufferBuilder::operator=(), preinit_realloc(), Pool::print(), tlx::print_cxx_backtrace(), realloc(), Buffer::~Buffer(), CSimpleGlobTempl< SOCHAR >::~CSimpleGlobTempl(), and memory_file::~memory_file().
| void* malloc | ( | size_t | size | ) |
exported malloc symbol that overrides loading from libc
call real malloc procedure in libc
prepend allocation size and check sentinel
Definition at line 1013 of file malloc_tracker.cpp.
References ATTRIBUTE_NO_SANITIZE, thrill::mem::base_curr, thrill::mem::float_curr, thrill::mem::inc_count(), thrill::mem::log_operations, thrill::mem::log_operations_threshold, thrill::mem::padding, PPREFIX, preinit_malloc(), thrill::mem::real_malloc, and thrill::mem::sentinel.
Referenced by foxxll::aligned_alloc(), StackArena< Size >::allocate(), thrill::mem::bypass_malloc(), calloc(), memory_file::discard(), thrill::mem::malloc_tracker_print_leaks(), preinit_realloc(), realloc(), and Buffer::Resize().
|
static |
Definition at line 724 of file malloc_tracker.cpp.
References thrill::mem::dec_count(), thrill::mem::log_operations_init_heap, thrill::mem::padding, PPREFIX, and thrill::mem::sentinel.
Referenced by free(), and thrill::mem::malloc_tracker_print_leaks().
|
staticnoexcept |
prepend allocation size and check sentinel
Definition at line 660 of file malloc_tracker.cpp.
References ATTRIBUTE_NO_SANITIZE, thrill::mem::inc_count(), thrill::mem::init_alignment, thrill::mem::init_heap, INIT_HEAP_SIZE, thrill::mem::init_heap_use, thrill::mem::log_operations_init_heap, thrill::mem::padding, PPREFIX, and thrill::mem::sentinel.
Referenced by malloc(), and thrill::mem::malloc_tracker_print_leaks().
|
static |
keep old area
allocate new area and copy data
Definition at line 692 of file malloc_tracker.cpp.
References ATTRIBUTE_NO_SANITIZE, free(), thrill::mem::log_operations_init_heap, malloc(), thrill::mem::padding, PPREFIX, and thrill::mem::sentinel.
Referenced by thrill::mem::malloc_tracker_print_leaks(), and realloc().
| void* realloc | ( | void * | ptr, |
| size_t | size | ||
| ) |
exported realloc() symbol that overrides loading from libc
special case size == 0 -> free()
special case ptr == 0 -> malloc()
Definition at line 1087 of file malloc_tracker.cpp.
References thrill::mem::base_curr, thrill::mem::dec_count(), thrill::mem::float_curr, free(), thrill::mem::inc_count(), thrill::mem::init_heap, thrill::mem::init_heap_use, thrill::mem::log_operations, thrill::mem::log_operations_threshold, malloc(), thrill::mem::padding, PPREFIX, preinit_realloc(), and thrill::mem::sentinel.
Referenced by foxxll::aligned_alloc(), AlignedAllocator< Byte, thrill::mem::Allocator< char > >::allocate_bytes(), CSimpleGlobTempl< SOCHAR >::GrowArgvArray(), CSimpleGlobTempl< SOCHAR >::GrowStringBuffer(), thrill::mem::malloc_tracker_print_leaks(), BufferBuilder::Reserve(), Buffer::Resize(), and memory_file::set_size().