Commit 3366420b authored by marko's avatar marko

Port extra Valgrind instrumentation (UNIV_DEBUG_VALGRIND) from branches/zip.

parent 4d1a51bb
......@@ -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)) {
......
......@@ -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;
}
......
......@@ -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);
}
}
......
......@@ -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 <valgrind/memcheck.h>
# 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
......@@ -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 */
......
......@@ -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,
......
......@@ -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);
......
......@@ -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,
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment