|
@@ -93,6 +93,12 @@ static LIST_HEAD ( free_blocks );
|
93
|
93
|
/** Total amount of free memory */
|
94
|
94
|
size_t freemem;
|
95
|
95
|
|
|
96
|
+/** Total amount of used memory */
|
|
97
|
+size_t usedmem;
|
|
98
|
+
|
|
99
|
+/** Maximum amount of used memory */
|
|
100
|
+size_t maxusedmem;
|
|
101
|
+
|
96
|
102
|
/**
|
97
|
103
|
* Heap size
|
98
|
104
|
*
|
|
@@ -351,8 +357,11 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) {
|
351
|
357
|
VALGRIND_MAKE_MEM_NOACCESS ( pre,
|
352
|
358
|
sizeof ( *pre ) );
|
353
|
359
|
}
|
354
|
|
- /* Update total free memory */
|
|
360
|
+ /* Update memory usage statistics */
|
355
|
361
|
freemem -= actual_size;
|
|
362
|
+ usedmem += actual_size;
|
|
363
|
+ if ( usedmem > maxusedmem )
|
|
364
|
+ maxusedmem = usedmem;
|
356
|
365
|
/* Return allocated block */
|
357
|
366
|
DBGC2 ( &heap, "Allocated [%p,%p)\n", block,
|
358
|
367
|
( ( ( void * ) block ) + size ) );
|
|
@@ -474,8 +483,9 @@ void free_memblock ( void *ptr, size_t size ) {
|
474
|
483
|
VALGRIND_MAKE_MEM_NOACCESS ( block, sizeof ( *block ) );
|
475
|
484
|
}
|
476
|
485
|
|
477
|
|
- /* Update free memory counter */
|
|
486
|
+ /* Update memory usage statistics */
|
478
|
487
|
freemem += actual_size;
|
|
488
|
+ usedmem -= actual_size;
|
479
|
489
|
|
480
|
490
|
check_blocks();
|
481
|
491
|
valgrind_make_blocks_noaccess();
|
|
@@ -629,10 +639,17 @@ void * zalloc ( size_t size ) {
|
629
|
639
|
* @c start must be aligned to at least a multiple of sizeof(void*).
|
630
|
640
|
*/
|
631
|
641
|
void mpopulate ( void *start, size_t len ) {
|
|
642
|
+
|
632
|
643
|
/* Prevent free_memblock() from rounding up len beyond the end
|
633
|
644
|
* of what we were actually given...
|
634
|
645
|
*/
|
635
|
|
- free_memblock ( start, ( len & ~( MIN_MEMBLOCK_SIZE - 1 ) ) );
|
|
646
|
+ len &= ~( MIN_MEMBLOCK_SIZE - 1 );
|
|
647
|
+
|
|
648
|
+ /* Add to allocation pool */
|
|
649
|
+ free_memblock ( start, len );
|
|
650
|
+
|
|
651
|
+ /* Fix up memory usage statistics */
|
|
652
|
+ usedmem += len;
|
636
|
653
|
}
|
637
|
654
|
|
638
|
655
|
/**
|
|
@@ -656,6 +673,7 @@ struct init_fn heap_init_fn __init_fn ( INIT_EARLY ) = {
|
656
|
673
|
*/
|
657
|
674
|
static void shutdown_cache ( int booting __unused ) {
|
658
|
675
|
discard_all_cache();
|
|
676
|
+ DBGC ( &heap, "Maximum heap usage %zdkB\n", ( maxusedmem >> 10 ) );
|
659
|
677
|
}
|
660
|
678
|
|
661
|
679
|
/** Memory allocator shutdown function */
|