/** Total amount of free memory */
size_t freemem;
+/** Total amount of used memory */
+size_t usedmem;
+
+/** Maximum amount of used memory */
+size_t maxusedmem;
+
/**
* Heap size
*
VALGRIND_MAKE_MEM_NOACCESS ( pre,
sizeof ( *pre ) );
}
- /* Update total free memory */
+ /* Update memory usage statistics */
freemem -= actual_size;
+ usedmem += actual_size;
+ if ( usedmem > maxusedmem )
+ maxusedmem = usedmem;
/* Return allocated block */
DBGC2 ( &heap, "Allocated [%p,%p)\n", block,
( ( ( void * ) block ) + size ) );
VALGRIND_MAKE_MEM_NOACCESS ( block, sizeof ( *block ) );
}
- /* Update free memory counter */
+ /* Update memory usage statistics */
freemem += actual_size;
+ usedmem -= actual_size;
check_blocks();
valgrind_make_blocks_noaccess();
* @c start must be aligned to at least a multiple of sizeof(void*).
*/
void mpopulate ( void *start, size_t len ) {
+
/* Prevent free_memblock() from rounding up len beyond the end
* of what we were actually given...
*/
- free_memblock ( start, ( len & ~( MIN_MEMBLOCK_SIZE - 1 ) ) );
+ len &= ~( MIN_MEMBLOCK_SIZE - 1 );
+
+ /* Add to allocation pool */
+ free_memblock ( start, len );
+
+ /* Fix up memory usage statistics */
+ usedmem += len;
}
/**
*/
static void shutdown_cache ( int booting __unused ) {
discard_all_cache();
+ DBGC ( &heap, "Maximum heap usage %zdkB\n", ( maxusedmem >> 10 ) );
}
/** Memory allocator shutdown function */