Skip to content

Commit

Permalink
add stat check for actual mapped pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansson committed Apr 27, 2018
1 parent 0201ced commit 0a763fe
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion rpmalloc/rpmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ static atomic32_t _reserved_spans;
static atomic32_t _mapped_total;
//! Running counter of total number of unmapped memory pages since start
static atomic32_t _unmapped_total;
//! Total number of currently mapped memory pages in OS calls
static atomic32_t _mapped_pages_os;
#endif

//! Current thread heap
Expand Down Expand Up @@ -1450,6 +1452,7 @@ rpmalloc_initialize_config(const rpmalloc_config_t* config) {
atomic_store32(&_mapped_pages, 0);
atomic_store32(&_mapped_total, 0);
atomic_store32(&_unmapped_total, 0);
atomic_store32(&_mapped_pages_os, 0);
#endif

//Setup all small and medium size classes
Expand Down Expand Up @@ -1526,6 +1529,7 @@ rpmalloc_finalize(void) {
//If you hit these asserts you probably have memory leaks or double frees in your code
assert(!atomic_load32(&_mapped_pages));
assert(!atomic_load32(&_reserved_spans));
assert(!atomic_load32(&_mapped_pages_os));
#endif

#if defined(__APPLE__) && ENABLE_PRELOAD
Expand Down Expand Up @@ -1626,7 +1630,9 @@ _memory_map_os(size_t size, size_t* offset) {
return 0;
}
#endif

#if ENABLE_STATISTICS
atomic_add32(&_mapped_pages_os, (int32_t)((size + padding) >> _memory_page_size_shift));
#endif
if (padding) {
size_t final_padding = padding - ((uintptr_t)ptr & ~_memory_span_mask);
void* final_ptr = pointer_offset(ptr, final_padding);
Expand Down Expand Up @@ -1692,6 +1698,10 @@ _memory_unmap_os(void* address, size_t size, size_t offset, size_t release) {
}
#endif
#endif
#if ENABLE_STATISTICS
if (release)
atomic_add32(&_mapped_pages_os, -(int32_t)(release >> _memory_page_size_shift));
#endif
}

// Extern interface
Expand Down

0 comments on commit 0a763fe

Please sign in to comment.