From 3366420bd2e704bc2870bf1e85452e77e89b6f4b Mon Sep 17 00:00:00 2001 From: marko <> Date: Thu, 14 Jun 2007 08:34:23 +0000 Subject: [PATCH] Port extra Valgrind instrumentation (UNIV_DEBUG_VALGRIND) from branches/zip. --- buf/buf0buf.c | 9 +++++++++ buf/buf0lru.c | 13 +++++++++++++ include/mem0mem.ic | 6 ++++++ include/univ.i | 14 ++++++++++++++ mem/mem0mem.c | 1 + mem/mem0pool.c | 6 ++++++ rem/rem0rec.c | 6 +++++- trx/trx0sys.c | 11 ++++++++++- ut/ut0mem.c | 2 ++ 9 files changed, 66 insertions(+), 2 deletions(-) diff --git a/buf/buf0buf.c b/buf/buf0buf.c index c847b8db9e2..5f72d152c6c 100644 --- a/buf/buf0buf.c +++ b/buf/buf0buf.c @@ -1648,6 +1648,15 @@ buf_page_init( block->lock_hash_val = lock_rec_hash(space, offset); +#ifdef UNIV_DEBUG_VALGRIND + if (!space) { + /* Silence valid Valgrind warnings about uninitialized + data being written to data files. There are some unused + bytes on some pages that InnoDB does not initialize. */ + UNIV_MEM_VALID(block->frame, UNIV_PAGE_SIZE); + } +#endif /* UNIV_DEBUG_VALGRIND */ + /* Insert into the hash table of file pages */ if (buf_page_hash_get(space, offset)) { diff --git a/buf/buf0lru.c b/buf/buf0lru.c index 1e27144bdbf..7b49a7641af 100644 --- a/buf/buf0lru.c +++ b/buf/buf0lru.c @@ -244,7 +244,15 @@ buf_LRU_search_and_free_block( frame at all */ if (block->frame) { + /* The page was declared uninitialized + by buf_LRU_block_remove_hashed_page(). + We need to flag the contents of the + page valid (which it still is) in + order to avoid bogus Valgrind + warnings. */ + UNIV_MEM_VALID(block->frame, UNIV_PAGE_SIZE); btr_search_drop_page_hash_index(block->frame); + UNIV_MEM_INVALID(block->frame, UNIV_PAGE_SIZE); } ut_a(block->buf_fix_count == 0); @@ -449,6 +457,7 @@ loop: mutex_enter(&block->mutex); block->state = BUF_BLOCK_READY_FOR_USE; + UNIV_MEM_ALLOC(block->frame, UNIV_PAGE_SIZE); mutex_exit(&block->mutex); @@ -864,6 +873,7 @@ buf_LRU_block_free_non_file_page( block->state = BUF_BLOCK_NOT_USED; + UNIV_MEM_ALLOC(block->frame, UNIV_PAGE_SIZE); #ifdef UNIV_DEBUG /* Wipe contents of page to reveal possible stale pointers to it */ memset(block->frame, '\0', UNIV_PAGE_SIZE); @@ -871,6 +881,8 @@ buf_LRU_block_free_non_file_page( UT_LIST_ADD_FIRST(free, buf_pool->free, block); block->in_free_list = TRUE; + UNIV_MEM_FREE(block->frame, UNIV_PAGE_SIZE); + if (srv_use_awe && block->frame) { /* Add to the list of mapped pages */ @@ -939,6 +951,7 @@ buf_LRU_block_remove_hashed_page( buf_page_address_fold(block->space, block->offset), block); + UNIV_MEM_INVALID(block->frame, UNIV_PAGE_SIZE); block->state = BUF_BLOCK_REMOVE_HASH; } diff --git a/include/mem0mem.ic b/include/mem0mem.ic index cb8fbe92cf0..e59443da73d 100644 --- a/include/mem0mem.ic +++ b/include/mem0mem.ic @@ -167,6 +167,8 @@ mem_heap_alloc( mem_block_set_free(block, free + MEM_SPACE_NEEDED(n)); #ifdef UNIV_MEM_DEBUG + UNIV_MEM_ALLOC(buf, + n + MEM_FIELD_HEADER_SIZE + MEM_FIELD_TRAILER_SIZE); /* In the debug version write debugging info to the field */ mem_field_init((byte*)buf, n); @@ -177,8 +179,10 @@ mem_heap_alloc( #endif #ifdef UNIV_SET_MEM_TO_ZERO + UNIV_MEM_ALLOC(buf, n); memset(buf, '\0', n); #endif + UNIV_MEM_ALLOC(buf, n); return(buf); } @@ -369,6 +373,8 @@ mem_heap_free_top( if ((heap != block) && (mem_block_get_free(block) == mem_block_get_start(block))) { mem_heap_block_free(heap, block); + } else { + UNIV_MEM_FREE((byte*) block + mem_block_get_free(block), n); } } diff --git a/include/univ.i b/include/univ.i index 957baa0391f..39865c10e5e 100644 --- a/include/univ.i +++ b/include/univ.i @@ -83,6 +83,8 @@ memory is read outside the allocated blocks. */ /* Make a non-inline debug version */ #if 0 +#define UNIV_DEBUG_VALGRIND /* Enable extra + Valgrind instrumentation */ #define UNIV_DEBUG /* Enable ut_ad() assertions */ #define UNIV_LIST_DEBUG /* debug UT_LIST_ macros */ #define UNIV_MEM_DEBUG /* detect memory leaks etc */ @@ -298,5 +300,17 @@ typedef void* os_thread_ret_t; #include "ut0dbg.h" #include "ut0ut.h" #include "db0err.h" +#ifdef UNIV_DEBUG_VALGRIND +# include +# define UNIV_MEM_VALID(addr, size) VALGRIND_MAKE_MEM_DEFINED(addr, size) +# define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) +# define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size) +# define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) +#else +# define UNIV_MEM_VALID(addr, size) do {} while(0) +# define UNIV_MEM_INVALID(addr, size) do {} while(0) +# define UNIV_MEM_FREE(addr, size) do {} while(0) +# define UNIV_MEM_ALLOC(addr, size) do {} while(0) +#endif #endif diff --git a/mem/mem0mem.c b/mem/mem0mem.c index 10b359e8e67..d89a3a55d88 100644 --- a/mem/mem0mem.c +++ b/mem/mem0mem.c @@ -514,6 +514,7 @@ mem_heap_block_free( mem_erase_buf((byte*)block, len); #endif + UNIV_MEM_FREE(block, len); if (init_block) { /* Do not have to free: do nothing */ diff --git a/mem/mem0pool.c b/mem/mem0pool.c index c010ae61160..27da86a0309 100644 --- a/mem/mem0pool.c +++ b/mem/mem0pool.c @@ -229,6 +229,8 @@ mem_pool_create( mem_area_set_size(area, ut_2_exp(i)); mem_area_set_free(area, TRUE); + UNIV_MEM_FREE(MEM_AREA_EXTRA_SIZE + (byte*) area, + ut_2_exp(i) - MEM_AREA_EXTRA_SIZE); UT_LIST_ADD_FIRST(free_list, pool->free_list[i], area); @@ -300,6 +302,7 @@ mem_pool_fill_free_list( UT_LIST_REMOVE(free_list, pool->free_list[i + 1], area); area2 = (mem_area_t*)(((byte*)area) + ut_2_exp(i)); + UNIV_MEM_ALLOC(area2, MEM_AREA_EXTRA_SIZE); mem_area_set_size(area2, ut_2_exp(i)); mem_area_set_free(area2, TRUE); @@ -400,6 +403,8 @@ mem_area_alloc( mutex_exit(&(pool->mutex)); ut_ad(mem_pool_validate(pool)); + UNIV_MEM_ALLOC(MEM_AREA_EXTRA_SIZE + (byte*)area, + ut_2_exp(n) - MEM_AREA_EXTRA_SIZE); return((void*)(MEM_AREA_EXTRA_SIZE + ((byte*)area))); } @@ -482,6 +487,7 @@ mem_area_free( } size = mem_area_get_size(area); + UNIV_MEM_FREE(ptr, size - MEM_AREA_EXTRA_SIZE); if (size == 0) { fprintf(stderr, diff --git a/rem/rem0rec.c b/rem/rem0rec.c index 3bc73eca9ea..64f8e2d319c 100644 --- a/rem/rem0rec.c +++ b/rem/rem0rec.c @@ -753,7 +753,11 @@ rec_convert_dtuple_to_rec_old( /* Calculate the offset of the origin in the physical record */ rec = buf + rec_get_converted_extra_size(data_size, n_fields); - +#ifdef UNIV_DEBUG + /* Suppress Valgrind warnings of ut_ad() + in mach_write_to_1(), mach_write_to_2() et al. */ + memset(buf, 0xff, rec - buf + data_size); +#endif /* UNIV_DEBUG */ /* Store the number of fields */ rec_set_n_fields_old(rec, n_fields); diff --git a/trx/trx0sys.c b/trx/trx0sys.c index 307a03bfbc3..144721150b6 100644 --- a/trx/trx0sys.c +++ b/trx/trx0sys.c @@ -868,7 +868,16 @@ trx_sysf_create( trx_sysf_rseg_set_page_no(sys_header, i, FIL_NULL, mtr); } - /* The remaining area (up to the page trailer) is uninitialized. */ + /* The remaining area (up to the page trailer) is uninitialized. + Silence Valgrind warnings about it. */ + UNIV_MEM_VALID(sys_header + (TRX_SYS_RSEGS + + TRX_SYS_N_RSEGS * TRX_SYS_RSEG_SLOT_SIZE + + TRX_SYS_RSEG_SPACE), + (UNIV_PAGE_SIZE - FIL_PAGE_DATA_END + - (TRX_SYS_RSEGS + + TRX_SYS_N_RSEGS * TRX_SYS_RSEG_SLOT_SIZE + + TRX_SYS_RSEG_SPACE)) + + page - sys_header); /* Create the first rollback segment in the SYSTEM tablespace */ page_no = trx_rseg_header_create(TRX_SYS_SPACE, ULINT_MAX, &slot_no, diff --git a/ut/ut0mem.c b/ut/ut0mem.c index 4fd515c35e6..b466a5f6872 100644 --- a/ut/ut0mem.c +++ b/ut/ut0mem.c @@ -162,6 +162,8 @@ retry: #endif } + UNIV_MEM_ALLOC(ret, n + sizeof(ut_mem_block_t)); + ((ut_mem_block_t*)ret)->size = n + sizeof(ut_mem_block_t); ((ut_mem_block_t*)ret)->magic_n = UT_MEM_MAGIC_N;