diff options
author | Davi Arnaut <Davi.Arnaut@Sun.COM> | 2010-07-08 18:20:08 -0300 |
---|---|---|
committer | Davi Arnaut <Davi.Arnaut@Sun.COM> | 2010-07-08 18:20:08 -0300 |
commit | f56dd32bf7c5b8a8cf35984f39f1a253b75945ff (patch) | |
tree | 6c88c3c07b30acb464ca8bf81bbef916216da616 /unittest/mysys | |
parent | d3b01fef18b20f3ac589f2ecc95d64326570583f (diff) | |
download | mariadb-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 'unittest/mysys')
-rw-r--r-- | unittest/mysys/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittest/mysys/Makefile.am | 2 | ||||
-rw-r--r-- | unittest/mysys/my_malloc-t.c | 43 |
3 files changed, 45 insertions, 2 deletions
diff --git a/unittest/mysys/CMakeLists.txt b/unittest/mysys/CMakeLists.txt index 3bf23df6066..56a3d67f25f 100644 --- a/unittest/mysys/CMakeLists.txt +++ b/unittest/mysys/CMakeLists.txt @@ -27,6 +27,6 @@ MACRO (MY_ADD_TEST name) ENDMACRO() -FOREACH(testname bitmap base64 my_vsnprintf my_atomic my_rdtsc lf) +FOREACH(testname bitmap base64 my_vsnprintf my_atomic my_rdtsc lf my_malloc) MY_ADD_TEST(${testname}) ENDFOREACH() diff --git a/unittest/mysys/Makefile.am b/unittest/mysys/Makefile.am index 25b30e331b0..64d2749987e 100644 --- a/unittest/mysys/Makefile.am +++ b/unittest/mysys/Makefile.am @@ -23,7 +23,7 @@ LDADD = $(top_builddir)/unittest/mytap/libmytap.a \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/strings/libmystrings.a -noinst_PROGRAMS = bitmap-t base64-t lf-t my_rdtsc-t my_vsnprintf-t +noinst_PROGRAMS = bitmap-t base64-t lf-t my_rdtsc-t my_vsnprintf-t my_malloc-t if NEED_THREAD # my_atomic-t is used to check thread functions, so it is safe to diff --git a/unittest/mysys/my_malloc-t.c b/unittest/mysys/my_malloc-t.c new file mode 100644 index 00000000000..00cac0d21b7 --- /dev/null +++ b/unittest/mysys/my_malloc-t.c @@ -0,0 +1,43 @@ +/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include <my_global.h> +#include <my_sys.h> +#include "tap.h" + +int main(void) +{ + void *p; + MY_INIT("my_malloc-t"); + + plan(4); + + p= my_malloc(0, MYF(0)); + ok(p != NULL, "Zero-sized block allocation."); + + p= my_realloc(p, 32, MYF(0)); + ok(p != NULL, "Reallocated zero-sized block."); + + p= my_realloc(p, 16, MYF(0)); + ok(p != NULL, "Trimmed block."); + + my_free(p); + p= NULL; + + ok((my_free(p), 1), "Free NULL pointer."); + + return exit_status(); +} + |