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 | a10ae35328ec800eff63c0bbb06d279e44c0a5a1 (patch) | |
tree | 6c88c3c07b30acb464ca8bf81bbef916216da616 /storage/archive | |
parent | d4cd1f843da60019664dfad2b0ad6987f82f01c6 (diff) | |
download | mariadb-git-a10ae35328ec800eff63c0bbb06d279e44c0a5a1.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.
Diffstat (limited to 'storage/archive')
-rw-r--r-- | storage/archive/archive_reader.c | 6 | ||||
-rw-r--r-- | storage/archive/ha_archive.cc | 15 |
2 files changed, 10 insertions, 11 deletions
diff --git a/storage/archive/archive_reader.c b/storage/archive/archive_reader.c index bad02835d86..ce4be92a521 100644 --- a/storage/archive/archive_reader.c +++ b/storage/archive/archive_reader.c @@ -201,7 +201,7 @@ int main(int argc, char *argv[]) ptr= (char *)my_malloc(sizeof(char) * reader_handle.frm_length, MYF(0)); azread_frm(&reader_handle, ptr); azwrite_frm(&writer_handle, ptr, reader_handle.frm_length); - my_free(ptr, MYF(0)); + my_free(ptr); } if (reader_handle.comment_length) @@ -210,7 +210,7 @@ int main(int argc, char *argv[]) ptr= (char *)my_malloc(sizeof(char) * reader_handle.comment_length, MYF(0)); azread_comment(&reader_handle, ptr); azwrite_comment(&writer_handle, ptr, reader_handle.comment_length); - my_free(ptr, MYF(0)); + my_free(ptr); } while ((read= azread(&reader_handle, (uchar *)size_buffer, @@ -265,7 +265,7 @@ int main(int argc, char *argv[]) azread_frm(&reader_handle, ptr); my_write(frm_file, (uchar*) ptr, reader_handle.frm_length, MYF(0)); my_close(frm_file, MYF(0)); - my_free(ptr, MYF(0)); + my_free(ptr); } end: diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index 2bcfc3ff672..63848370ff1 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -387,7 +387,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc) { *rc= my_errno ? my_errno : -1; mysql_mutex_unlock(&archive_mutex); - my_free(share, MYF(0)); + my_free(share); DBUG_RETURN(NULL); } stats.auto_increment_value= archive_tmp.auto_increment + 1; @@ -447,7 +447,7 @@ int ha_archive::free_share() if (azclose(&(share->archive_write))) rc= 1; } - my_free((uchar*) share, MYF(0)); + my_free(share); } mysql_mutex_unlock(&archive_mutex); @@ -706,7 +706,7 @@ int ha_archive::create(const char *name, TABLE *table_arg, { my_read(frm_file, frm_ptr, file_stat.st_size, MYF(0)); azwrite_frm(&create_stream, (char *)frm_ptr, file_stat.st_size); - my_free((uchar*)frm_ptr, MYF(0)); + my_free(frm_ptr); } } my_close(frm_file, MYF(0)); @@ -932,8 +932,7 @@ int ha_archive::write_row(uchar *buf) rc= real_write_row(buf, &(share->archive_write)); error: mysql_mutex_unlock(&share->mutex); - if (read_buf) - my_free((uchar*) read_buf, MYF(0)); + my_free(read_buf); DBUG_RETURN(rc); } @@ -1696,7 +1695,7 @@ archive_record_buffer *ha_archive::create_record_buffer(unsigned int length) if (!(r->buffer= (uchar*) my_malloc(r->length, MYF(MY_WME)))) { - my_free((char*) r, MYF(MY_ALLOW_ZERO_PTR)); + my_free(r); DBUG_RETURN(NULL); /* purecov: inspected */ } @@ -1706,8 +1705,8 @@ archive_record_buffer *ha_archive::create_record_buffer(unsigned int length) void ha_archive::destroy_record_buffer(archive_record_buffer *r) { DBUG_ENTER("ha_archive::destroy_record_buffer"); - my_free((char*) r->buffer, MYF(MY_ALLOW_ZERO_PTR)); - my_free((char*) r, MYF(MY_ALLOW_ZERO_PTR)); + my_free(r->buffer); + my_free(r); DBUG_VOID_RETURN; } |