mirror of
https://github.com/ipxe/ipxe.git
synced 2025-02-25 18:55:24 -06:00
[malloc] Clean up debug messages
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
c85de315a6
commit
6f076efa65
@ -310,7 +310,7 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) {
|
|||||||
assert ( actual_size >= size );
|
assert ( actual_size >= size );
|
||||||
align_mask = ( ( align - 1 ) | ( MIN_MEMBLOCK_SIZE - 1 ) );
|
align_mask = ( ( align - 1 ) | ( MIN_MEMBLOCK_SIZE - 1 ) );
|
||||||
|
|
||||||
DBGC2 ( &heap, "Allocating %#zx (aligned %#zx+%zx)\n",
|
DBGC2 ( &heap, "HEAP allocating %#zx (aligned %#zx+%zx)\n",
|
||||||
size, align, offset );
|
size, align, offset );
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
/* Search through blocks for the first one with enough space */
|
/* Search through blocks for the first one with enough space */
|
||||||
@ -329,7 +329,8 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) {
|
|||||||
pre = block;
|
pre = block;
|
||||||
block = ( ( ( void * ) pre ) + pre_size );
|
block = ( ( ( void * ) pre ) + pre_size );
|
||||||
post = ( ( ( void * ) block ) + actual_size );
|
post = ( ( ( void * ) block ) + actual_size );
|
||||||
DBGC2 ( &heap, "[%p,%p) -> [%p,%p) + [%p,%p)\n", pre,
|
DBGC2 ( &heap, "HEAP splitting [%p,%p) -> [%p,%p) "
|
||||||
|
"+ [%p,%p)\n", pre,
|
||||||
( ( ( void * ) pre ) + pre->size ), pre, block,
|
( ( ( void * ) pre ) + pre->size ), pre, block,
|
||||||
post, ( ( ( void * ) pre ) + pre->size ) );
|
post, ( ( ( void * ) pre ) + pre->size ) );
|
||||||
/* If there is a "post" block, add it in to
|
/* If there is a "post" block, add it in to
|
||||||
@ -364,7 +365,7 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) {
|
|||||||
if ( usedmem > maxusedmem )
|
if ( usedmem > maxusedmem )
|
||||||
maxusedmem = usedmem;
|
maxusedmem = usedmem;
|
||||||
/* Return allocated block */
|
/* Return allocated block */
|
||||||
DBGC2 ( &heap, "Allocated [%p,%p)\n", block,
|
DBGC2 ( &heap, "HEAP allocated [%p,%p)\n", block,
|
||||||
( ( ( void * ) block ) + size ) );
|
( ( ( void * ) block ) + size ) );
|
||||||
ptr = block;
|
ptr = block;
|
||||||
VALGRIND_MAKE_MEM_UNDEFINED ( ptr, size );
|
VALGRIND_MAKE_MEM_UNDEFINED ( ptr, size );
|
||||||
@ -372,15 +373,16 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Try discarding some cached data to free up memory */
|
/* Try discarding some cached data to free up memory */
|
||||||
DBGC ( &heap, "Attempting discard for %#zx (aligned %#zx+%zx), "
|
DBGC ( &heap, "HEAP attempting discard for %#zx (aligned "
|
||||||
"used %zdkB\n", size, align, offset, ( usedmem >> 10 ) );
|
"%#zx+%zx), used %zdkB\n", size, align, offset,
|
||||||
|
( usedmem >> 10 ) );
|
||||||
valgrind_make_blocks_noaccess();
|
valgrind_make_blocks_noaccess();
|
||||||
discarded = discard_cache();
|
discarded = discard_cache();
|
||||||
valgrind_make_blocks_defined();
|
valgrind_make_blocks_defined();
|
||||||
check_blocks();
|
check_blocks();
|
||||||
if ( ! discarded ) {
|
if ( ! discarded ) {
|
||||||
/* Nothing available to discard */
|
/* Nothing available to discard */
|
||||||
DBGC ( &heap, "Failed to allocate %#zx (aligned "
|
DBGC ( &heap, "HEAP failed to allocate %#zx (aligned "
|
||||||
"%#zx)\n", size, align );
|
"%#zx)\n", size, align );
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
goto done;
|
goto done;
|
||||||
@ -426,7 +428,7 @@ void free_memblock ( void *ptr, size_t size ) {
|
|||||||
~( MIN_MEMBLOCK_SIZE - 1 ) );
|
~( MIN_MEMBLOCK_SIZE - 1 ) );
|
||||||
freeing = ptr;
|
freeing = ptr;
|
||||||
VALGRIND_MAKE_MEM_UNDEFINED ( freeing, sizeof ( *freeing ) );
|
VALGRIND_MAKE_MEM_UNDEFINED ( freeing, sizeof ( *freeing ) );
|
||||||
DBGC2 ( &heap, "Freeing [%p,%p)\n",
|
DBGC2 ( &heap, "HEAP freeing [%p,%p)\n",
|
||||||
freeing, ( ( ( void * ) freeing ) + size ) );
|
freeing, ( ( ( void * ) freeing ) + size ) );
|
||||||
|
|
||||||
/* Check that this block does not overlap the free list */
|
/* Check that this block does not overlap the free list */
|
||||||
@ -437,7 +439,7 @@ void free_memblock ( void *ptr, size_t size ) {
|
|||||||
( ( void * ) freeing <
|
( ( void * ) freeing <
|
||||||
( ( void * ) block + block->size ) ) ) {
|
( ( void * ) block + block->size ) ) ) {
|
||||||
assert ( 0 );
|
assert ( 0 );
|
||||||
DBGC ( &heap, "Double free of [%p,%p) "
|
DBGC ( &heap, "HEAP double free of [%p,%p) "
|
||||||
"overlapping [%p,%p) detected from %p\n",
|
"overlapping [%p,%p) detected from %p\n",
|
||||||
freeing,
|
freeing,
|
||||||
( ( ( void * ) freeing ) + size ), block,
|
( ( ( void * ) freeing ) + size ), block,
|
||||||
@ -457,7 +459,8 @@ void free_memblock ( void *ptr, size_t size ) {
|
|||||||
( ( ( void * ) freeing ) + freeing->size ) );
|
( ( ( void * ) freeing ) + freeing->size ) );
|
||||||
/* Merge with immediately preceding block, if possible */
|
/* Merge with immediately preceding block, if possible */
|
||||||
if ( gap_before == 0 ) {
|
if ( gap_before == 0 ) {
|
||||||
DBGC2 ( &heap, "[%p,%p) + [%p,%p) -> [%p,%p)\n", block,
|
DBGC2 ( &heap, "HEAP merging [%p,%p) + [%p,%p) -> "
|
||||||
|
"[%p,%p)\n", block,
|
||||||
( ( ( void * ) block ) + block->size ), freeing,
|
( ( ( void * ) block ) + block->size ), freeing,
|
||||||
( ( ( void * ) freeing ) + freeing->size ),
|
( ( ( void * ) freeing ) + freeing->size ),
|
||||||
block,
|
block,
|
||||||
@ -477,13 +480,13 @@ void free_memblock ( void *ptr, size_t size ) {
|
|||||||
* possible, merge the following block into the "freeing"
|
* possible, merge the following block into the "freeing"
|
||||||
* block.
|
* block.
|
||||||
*/
|
*/
|
||||||
DBGC2 ( &heap, "[%p,%p)\n",
|
DBGC2 ( &heap, "HEAP freed [%p,%p)\n",
|
||||||
freeing, ( ( ( void * ) freeing ) + freeing->size ) );
|
freeing, ( ( ( void * ) freeing ) + freeing->size ) );
|
||||||
list_add_tail ( &freeing->list, &block->list );
|
list_add_tail ( &freeing->list, &block->list );
|
||||||
if ( gap_after == 0 ) {
|
if ( gap_after == 0 ) {
|
||||||
DBGC2 ( &heap, "[%p,%p) + [%p,%p) -> [%p,%p)\n", freeing,
|
DBGC2 ( &heap, "HEAP merging [%p,%p) + [%p,%p) -> [%p,%p)\n",
|
||||||
( ( ( void * ) freeing ) + freeing->size ), block,
|
freeing, ( ( ( void * ) freeing ) + freeing->size ),
|
||||||
( ( ( void * ) block ) + block->size ), freeing,
|
block, ( ( ( void * ) block ) + block->size ), freeing,
|
||||||
( ( ( void * ) block ) + block->size ) );
|
( ( ( void * ) block ) + block->size ) );
|
||||||
freeing->size += block->size;
|
freeing->size += block->size;
|
||||||
list_del ( &block->list );
|
list_del ( &block->list );
|
||||||
@ -565,8 +568,8 @@ void * realloc ( void *old_ptr, size_t new_size ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ASSERTED ) {
|
if ( ASSERTED ) {
|
||||||
DBGC ( &heap, "Possible memory corruption detected from %p\n",
|
DBGC ( &heap, "HEAP detected possible memory corruption "
|
||||||
__builtin_return_address ( 0 ) );
|
"from %p\n", __builtin_return_address ( 0 ) );
|
||||||
}
|
}
|
||||||
return new_ptr;
|
return new_ptr;
|
||||||
}
|
}
|
||||||
@ -585,8 +588,8 @@ void * malloc ( size_t size ) {
|
|||||||
|
|
||||||
ptr = realloc ( NULL, size );
|
ptr = realloc ( NULL, size );
|
||||||
if ( ASSERTED ) {
|
if ( ASSERTED ) {
|
||||||
DBGC ( &heap, "Possible memory corruption detected from %p\n",
|
DBGC ( &heap, "HEAP detected possible memory corruption "
|
||||||
__builtin_return_address ( 0 ) );
|
"from %p\n", __builtin_return_address ( 0 ) );
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
@ -605,8 +608,8 @@ void free ( void *ptr ) {
|
|||||||
|
|
||||||
realloc ( ptr, 0 );
|
realloc ( ptr, 0 );
|
||||||
if ( ASSERTED ) {
|
if ( ASSERTED ) {
|
||||||
DBGC ( &heap, "Possible memory corruption detected from %p\n",
|
DBGC ( &heap, "HEAP detected possible memory corruption "
|
||||||
__builtin_return_address ( 0 ) );
|
"from %p\n", __builtin_return_address ( 0 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -628,8 +631,8 @@ void * zalloc ( size_t size ) {
|
|||||||
if ( data )
|
if ( data )
|
||||||
memset ( data, 0, size );
|
memset ( data, 0, size );
|
||||||
if ( ASSERTED ) {
|
if ( ASSERTED ) {
|
||||||
DBGC ( &heap, "Possible memory corruption detected from %p\n",
|
DBGC ( &heap, "HEAP detected possible memory corruption "
|
||||||
__builtin_return_address ( 0 ) );
|
"from %p\n", __builtin_return_address ( 0 ) );
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -680,7 +683,7 @@ struct init_fn heap_init_fn __init_fn ( INIT_EARLY ) = {
|
|||||||
*/
|
*/
|
||||||
static void shutdown_cache ( int booting __unused ) {
|
static void shutdown_cache ( int booting __unused ) {
|
||||||
discard_all_cache();
|
discard_all_cache();
|
||||||
DBGC ( &heap, "Maximum heap usage %zdkB\n", ( maxusedmem >> 10 ) );
|
DBGC ( &heap, "HEAP maximum usage %zdkB\n", ( maxusedmem >> 10 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Memory allocator shutdown function */
|
/** Memory allocator shutdown function */
|
||||||
@ -689,19 +692,17 @@ struct startup_fn heap_startup_fn __startup_fn ( STARTUP_EARLY ) = {
|
|||||||
.shutdown = shutdown_cache,
|
.shutdown = shutdown_cache,
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
|
||||||
#include <stdio.h>
|
|
||||||
/**
|
/**
|
||||||
* Dump free block list
|
* Dump free block list (for debugging)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void mdumpfree ( void ) {
|
void mdumpfree ( void ) {
|
||||||
struct memory_block *block;
|
struct memory_block *block;
|
||||||
|
|
||||||
printf ( "Free block list:\n" );
|
dbg_printf ( "HEAP free block list:\n" );
|
||||||
list_for_each_entry ( block, &free_blocks, list ) {
|
list_for_each_entry ( block, &free_blocks, list ) {
|
||||||
printf ( "[%p,%p] (size %#zx)\n", block,
|
dbg_printf ( "...[%p,%p] (size %#zx)\n", block,
|
||||||
( ( ( void * ) block ) + block->size ), block->size );
|
( ( ( void * ) block ) + block->size ),
|
||||||
|
block->size );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user