summaryrefslogtreecommitdiff
path: root/dbug
diff options
context:
space:
mode:
authorDavi Arnaut <Davi.Arnaut@Sun.COM>2010-07-08 18:20:08 -0300
committerDavi Arnaut <Davi.Arnaut@Sun.COM>2010-07-08 18:20:08 -0300
commitf56dd32bf7c5b8a8cf35984f39f1a253b75945ff (patch)
tree6c88c3c07b30acb464ca8bf81bbef916216da616 /dbug
parentd3b01fef18b20f3ac589f2ecc95d64326570583f (diff)
downloadmariadb-git-f56dd32bf7c5b8a8cf35984f39f1a253b75945ff.tar.gz
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly slow as it checks all allocated blocks for overrun at each memory management primitive, yielding a almost exponential slowdown for the memory management functions (malloc, realloc, free). The overrun check basically consists of verifying some bytes of a block for certain magic keys, which catches some simple forms of overrun. Another minor problem is violation of aliasing rules and that its own internal list of blocks is prone to corruption. Another issue with safemalloc is rather the maintenance cost as the tool has a significant impact on the server code. Given the magnitude of memory debuggers available nowadays, especially those that are provided with the platform malloc implementation, maintenance of a in-house and largely obsolete memory debugger becomes a burden that is not worth the effort due to its slowness and lack of support for detecting more common forms of heap corruption. Since there are third-party tools that can provide the same functionality at a lower or comparable performance cost, the solution is to simply remove safemalloc. Third-party tools can provide the same functionality at a lower or comparable performance cost. The removal of safemalloc also allows a simplification of the malloc wrappers, removing quite a bit of kludge: redefinition of my_malloc, my_free and the removal of the unused second argument of my_free. Since free() always check whether the supplied pointer is null, redudant checks are also removed. Also, this patch adds unit testing for my_malloc and moves my_realloc implementation into the same file as the other memory allocation primitives. client/mysqldump.c: Pass my_free directly as its signature is compatible with the callback type -- which wasn't the case for free_table_ent.
Diffstat (limited to 'dbug')
-rwxr-xr-xdbug/CMakeLists.txt2
-rw-r--r--dbug/Makefile.am2
-rw-r--r--dbug/dbug.c23
-rw-r--r--dbug/sanity.c13
-rw-r--r--dbug/user.r8
5 files changed, 4 insertions, 44 deletions
diff --git a/dbug/CMakeLists.txt b/dbug/CMakeLists.txt
index 16e130fa28a..4cf6dd88cb7 100755
--- a/dbug/CMakeLists.txt
+++ b/dbug/CMakeLists.txt
@@ -17,6 +17,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/dbug
${CMAKE_SOURCE_DIR}/include
)
-SET(DBUG_SOURCES dbug.c sanity.c)
+SET(DBUG_SOURCES dbug.c)
ADD_CONVENIENCE_LIBRARY(dbug ${DBUG_SOURCES})
TARGET_LINK_LIBRARIES(dbug mysys)
diff --git a/dbug/Makefile.am b/dbug/Makefile.am
index 4091858a1af..3581b3597ee 100644
--- a/dbug/Makefile.am
+++ b/dbug/Makefile.am
@@ -19,7 +19,7 @@ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include
LDADD = libdbug.a ../mysys/libmysys.a ../strings/libmystrings.a
pkglib_LIBRARIES = libdbug.a
noinst_HEADERS = dbug_long.h
-libdbug_a_SOURCES = dbug.c sanity.c
+libdbug_a_SOURCES = dbug.c
EXTRA_DIST = CMakeLists.txt example1.c example2.c example3.c \
user.r monty.doc dbug_add_tags.pl \
my_main.c main.c factorial.c dbug_analyze.c \
diff --git a/dbug/dbug.c b/dbug/dbug.c
index 0355d553cff..a4b381f2746 100644
--- a/dbug/dbug.c
+++ b/dbug/dbug.c
@@ -128,9 +128,8 @@
#define PROFILE_ON (1 << 7) /* Print out profiling code */
#define PID_ON (1 << 8) /* Identify each line with process id */
#define TIMESTAMP_ON (1 << 9) /* timestamp every line of output */
-#define SANITY_CHECK_ON (1 << 10) /* Check safemalloc on DBUG_ENTER */
-#define FLUSH_ON_WRITE (1 << 11) /* Flush on every write */
-#define OPEN_APPEND (1 << 12) /* Open for append */
+#define FLUSH_ON_WRITE (1 << 10) /* Flush on every write */
+#define OPEN_APPEND (1 << 11) /* Open for append */
#define TRACE_ON ((uint)1 << 31) /* Trace enabled. MUST be the highest bit!*/
#define TRACING (cs->stack->flags & TRACE_ON)
@@ -184,12 +183,6 @@
static void perror(); /* Fake system/library error print routine */
#endif
-#ifdef SAFEMALLOC
-IMPORT int _sanity(const char *file,uint line); /* safemalloc sanity checker */
-#else
-#define _sanity(X,Y) (1)
-#endif
-
/*
* The user may specify a list of functions to trace or
* debug. These lists are kept in a linear linked list,
@@ -705,12 +698,6 @@ int DbugParse(CODE_STATE *cs, const char *control)
else
stack->flags |= TIMESTAMP_ON;
break;
- case 'S':
- if (sign < 0)
- stack->flags &= ~SANITY_CHECK_ON;
- else
- stack->flags |= SANITY_CHECK_ON;
- break;
}
if (!*end)
break;
@@ -1069,7 +1056,6 @@ int _db_explain_ (CODE_STATE *cs, char *buf, size_t len)
op_bool_to_buf('r', cs->stack->sub_level != 0);
op_intf_to_buf('t', cs->stack->maxdepth, MAXDEPTH, TRACING);
op_bool_to_buf('T', cs->stack->flags & TIMESTAMP_ON);
- op_bool_to_buf('S', cs->stack->flags & SANITY_CHECK_ON);
*buf= '\0';
return 0;
@@ -1187,8 +1173,6 @@ void _db_enter_(const char *_func_, const char *_file_,
if (!TRACING) break;
/* fall through */
case DO_TRACE:
- if ((cs->stack->flags & SANITY_CHECK_ON) && _sanity(_file_,_line_))
- cs->stack->flags &= ~SANITY_CHECK_ON;
if (TRACING)
{
if (!cs->locked)
@@ -1247,9 +1231,6 @@ void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_)
#endif
if (DoTrace(cs) & DO_TRACE)
{
- if ((cs->stack->flags & SANITY_CHECK_ON) &&
- _sanity(_stack_frame_->file,_line_))
- cs->stack->flags &= ~SANITY_CHECK_ON;
if (TRACING)
{
if (!cs->locked)
diff --git a/dbug/sanity.c b/dbug/sanity.c
deleted file mode 100644
index df43fc14ba9..00000000000
--- a/dbug/sanity.c
+++ /dev/null
@@ -1,13 +0,0 @@
-/* Declarate _sanity() if not declared in main program */
-
-#include <my_global.h>
-
-extern int _sanity(const char *file,uint line);
-
-#if defined(SAFEMALLOC) && !defined(MASTER) /* Avoid errors in MySQL */
-int _sanity(const char * file __attribute__((unused)),
- uint line __attribute__((unused)))
-{
- return 0;
-}
-#endif
diff --git a/dbug/user.r b/dbug/user.r
index 847ad80b30f..5628f5a4fa1 100644
--- a/dbug/user.r
+++ b/dbug/user.r
@@ -1019,14 +1019,6 @@ Most useful with
.B DBUG_PUSH
macros used to temporarily alter the
debugger state.
-.LI S
-When compiled with
-.I safemalloc
-this flag forces "sanity" memory checks (for overwrites/underwrites)
-on each
-.B DBUG_ENTER
-and
-.B DBUG_RETURN.
.LI t[,N]
Enable function control flow tracing.
The maximum nesting depth is specified by N, and defaults to