From a10ae35328ec800eff63c0bbb06d279e44c0a5a1 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 8 Jul 2010 18:20:08 -0300 Subject: 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. --- extra/comp_err.c | 24 ++++++++++++------------ extra/my_print_defaults.c | 2 +- extra/replace.c | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 24 deletions(-) (limited to 'extra') diff --git a/extra/comp_err.c b/extra/comp_err.c index 53d8c18262b..c85aef7bcc5 100644 --- a/extra/comp_err.c +++ b/extra/comp_err.c @@ -387,15 +387,15 @@ static void clean_up(struct languages *lang_head, struct errors *error_head) struct errors *tmp_error, *next_error; uint count, i; - my_free((uchar*) default_language, MYF(0)); + my_free((void*) default_language); for (tmp_lang= lang_head; tmp_lang; tmp_lang= next_language) { next_language= tmp_lang->next_lang; - my_free(tmp_lang->lang_short_name, MYF(0)); - my_free(tmp_lang->lang_long_name, MYF(0)); - my_free(tmp_lang->charset, MYF(0)); - my_free((uchar*) tmp_lang, MYF(0)); + my_free(tmp_lang->lang_short_name); + my_free(tmp_lang->lang_long_name); + my_free(tmp_lang->charset); + my_free(tmp_lang); } for (tmp_error= error_head; tmp_error; tmp_error= next_error) @@ -406,17 +406,17 @@ static void clean_up(struct languages *lang_head, struct errors *error_head) { struct message *tmp; tmp= dynamic_element(&tmp_error->msg, i, struct message*); - my_free((uchar*) tmp->lang_short_name, MYF(0)); - my_free((uchar*) tmp->text, MYF(0)); + my_free(tmp->lang_short_name); + my_free(tmp->text); } delete_dynamic(&tmp_error->msg); if (tmp_error->sql_code1[0]) - my_free((uchar*) tmp_error->sql_code1, MYF(0)); + my_free((void*) tmp_error->sql_code1); if (tmp_error->sql_code2[0]) - my_free((uchar*) tmp_error->sql_code2, MYF(0)); - my_free((uchar*) tmp_error->er_name, MYF(0)); - my_free((uchar*) tmp_error, MYF(0)); + my_free((void*) tmp_error->sql_code2); + my_free((void*) tmp_error->er_name); + my_free(tmp_error); } } @@ -559,7 +559,7 @@ static uint parse_error_offset(char *str) end= 0; ioffset= (uint) my_strtoll10(soffset, &end, &error); - my_free((uchar*) soffset, MYF(0)); + my_free(soffset); DBUG_RETURN(ioffset); } diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c index 9595e1b2df8..81416df2922 100644 --- a/extra/my_print_defaults.c +++ b/extra/my_print_defaults.c @@ -200,7 +200,7 @@ int main(int argc, char **argv) for (argument= arguments+1 ; *argument ; argument++) if (*argument != args_separator) /* skip arguments separator */ puts(*argument); - my_free((char*) load_default_groups,MYF(0)); + my_free(load_default_groups); free_defaults(arguments); exit(0); diff --git a/extra/replace.c b/extra/replace.c index 3f07183807c..1a887ac3e21 100644 --- a/extra/replace.c +++ b/extra/replace.c @@ -262,7 +262,7 @@ static int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name) if (!(pa->str= (uchar*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD), MYF(MY_WME)))) { - my_free((uchar*) pa->typelib.type_names,MYF(0)); + my_free(pa->typelib.type_names); DBUG_RETURN (-1); } pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(uchar*)+ @@ -324,9 +324,9 @@ static void free_pointer_array(reg1 POINTER_ARRAY *pa) if (pa->typelib.count) { pa->typelib.count=0; - my_free((uchar*) pa->typelib.type_names,MYF(0)); + my_free(pa->typelib.type_names); pa->typelib.type_names=0; - my_free((uchar*) pa->str,MYF(0)); + my_free(pa->str); } return; } /* free_pointer_array */ @@ -441,7 +441,7 @@ static REPLACE *init_replace(char * *from, char * *to,uint count, if (!(follow=(FOLLOWS*) my_malloc((states+2)*sizeof(FOLLOWS),MYF(MY_WME)))) { free_sets(&sets); - my_free((uchar*) found_set,MYF(0)); + my_free(found_set); DBUG_RETURN(0); } @@ -663,9 +663,9 @@ static REPLACE *init_replace(char * *from, char * *to,uint count, replace[i].next[j]=(REPLACE*) (rep_str+(-sets.set[i].next[j]-1)); } } - my_free((uchar*) follow,MYF(0)); + my_free(follow); free_sets(&sets); - my_free((uchar*) found_set,MYF(0)); + my_free(found_set); DBUG_PRINT("exit",("Replace table has %d states",sets.count)); DBUG_RETURN(replace); } @@ -681,7 +681,7 @@ static int init_sets(REP_SETS *sets,uint states) if (!(sets->bit_buffer=(uint*) my_malloc(sizeof(uint)*sets->size_of_bits* SET_MALLOC_HUNC,MYF(MY_WME)))) { - my_free((uchar*) sets->set,MYF(0)); + my_free(sets->set); return 1; } return 0; @@ -742,8 +742,8 @@ static void free_last_set(REP_SETS *sets) static void free_sets(REP_SETS *sets) { - my_free((uchar*)sets->set_buffer,MYF(0)); - my_free((uchar*)sets->bit_buffer,MYF(0)); + my_free(sets->set_buffer); + my_free(sets->bit_buffer); return; } @@ -950,8 +950,8 @@ static void reset_buffer() static void free_buffer() { - my_free(buffer,MYF(MY_WME)); - my_free(out_buff,MYF(MY_WME)); + my_free(buffer); + my_free(out_buff); } -- cgit v1.2.1 From f54a1182494db9bababccfa83692630bec51ca95 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 15 Jul 2010 08:13:30 -0300 Subject: WL#5486: Remove code for unsupported platforms Remove Netware specific code. --- extra/my_print_defaults.c | 5 --- extra/mysql_waitpid.c | 14 --------- extra/perror.c | 6 +--- extra/resolve_stack_dump.c | 4 --- extra/resolveip.c | 3 -- extra/yassl/include/yassl_int.hpp | 3 +- extra/yassl/src/socket_wrapper.cpp | 2 +- extra/yassl/taocrypt/src/random.cpp | 61 ------------------------------------- extra/yassl/testsuite/test.hpp | 9 ++---- 9 files changed, 5 insertions(+), 102 deletions(-) (limited to 'extra') diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c index 81416df2922..89fd4104c6f 100644 --- a/extra/my_print_defaults.c +++ b/extra/my_print_defaults.c @@ -89,9 +89,6 @@ static struct my_option my_long_options[] = }; - -#include - static void usage(my_bool version) { printf("%s Ver 1.6 for %s at %s\n",my_progname,SYSTEM_TYPE, @@ -107,8 +104,6 @@ static void usage(my_bool version) printf("\nExample usage:\n%s --defaults-file=example.cnf client mysql\n", my_progname); } -#include - static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), diff --git a/extra/mysql_waitpid.c b/extra/mysql_waitpid.c index e5c06ac9857..d5c9f2f42ae 100644 --- a/extra/mysql_waitpid.c +++ b/extra/mysql_waitpid.c @@ -15,8 +15,6 @@ /* Wait until a program dies */ -#ifndef __NETWARE__ - #include #include #include @@ -103,15 +101,3 @@ void usage(void) my_print_help(my_long_options); exit(-1); } - -#else - -#include - -main() -{ - fprintf(stderr,"This tool has not been ported to NetWare\n"); - return 0; -} - -#endif /* __NETWARE__ */ diff --git a/extra/perror.c b/extra/perror.c index be9a47d63a4..382805c5dfd 100644 --- a/extra/perror.c +++ b/extra/perror.c @@ -102,8 +102,6 @@ static HA_ERRORS ha_errlist[]= }; -#include - static void print_version(void) { printf("%s Ver %s, for %s (%s)\n",my_progname,PERROR_VERSION, @@ -122,8 +120,6 @@ static void usage(void) my_print_variables(my_long_options); } -#include - static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), @@ -281,7 +277,7 @@ int main(int argc,char *argv[]) #endif { /* - On some system, like NETWARE, strerror(unknown_error) returns a + On some system, like Linux, strerror(unknown_error) returns a string 'Unknown Error'. To avoid printing it we try to find the error string by asking for an impossible big error message. diff --git a/extra/resolve_stack_dump.c b/extra/resolve_stack_dump.c index 4faca1653b2..432a207f424 100644 --- a/extra/resolve_stack_dump.c +++ b/extra/resolve_stack_dump.c @@ -65,8 +65,6 @@ static struct my_option my_long_options[] = static void verify_sort(); -#include - static void print_version(void) { printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION, @@ -90,8 +88,6 @@ The numeric-dump-file should contain a numeric stack trace from mysqld.\n\ If the numeric-dump-file is not given, the stack trace is read from stdin.\n"); } -#include - static void die(const char* fmt, ...) { diff --git a/extra/resolveip.c b/extra/resolveip.c index 90fda977848..094dfecae59 100644 --- a/extra/resolveip.c +++ b/extra/resolveip.c @@ -155,11 +155,8 @@ int main(int argc, char **argv) else { printf ("Host name of %s is %s", ip,hpaddr->h_name); -#ifndef __NETWARE__ - /* this information is not available on NetWare */ for (q = hpaddr->h_aliases; *q != 0; q++) (void) printf(", %s", *q); -#endif /* __NETWARE__ */ puts(""); } } diff --git a/extra/yassl/include/yassl_int.hpp b/extra/yassl/include/yassl_int.hpp index 1e761f559e2..1cc4200d10c 100644 --- a/extra/yassl/include/yassl_int.hpp +++ b/extra/yassl/include/yassl_int.hpp @@ -34,9 +34,8 @@ #include "openssl/ssl.h" // ASN1_STRING and DH // Check if _POSIX_THREADS should be forced -#if !defined(_POSIX_THREADS) && (defined(__NETWARE__) || defined(__hpux)) +#if !defined(_POSIX_THREADS) && defined(__hpux) // HPUX does not define _POSIX_THREADS as it's not _fully_ implemented -// Netware supports pthreads but does not announce it #define _POSIX_THREADS #endif diff --git a/extra/yassl/src/socket_wrapper.cpp b/extra/yassl/src/socket_wrapper.cpp index eee5d47377f..cebbd9c5529 100644 --- a/extra/yassl/src/socket_wrapper.cpp +++ b/extra/yassl/src/socket_wrapper.cpp @@ -37,7 +37,7 @@ #include #endif // _WIN32 -#if defined(__sun) || defined(__SCO_VERSION__) || defined(__NETWARE__) +#if defined(__sun) || defined(__SCO_VERSION__) #include #endif diff --git a/extra/yassl/taocrypt/src/random.cpp b/extra/yassl/taocrypt/src/random.cpp index 2bbc0a85e8b..729421fc71d 100644 --- a/extra/yassl/taocrypt/src/random.cpp +++ b/extra/yassl/taocrypt/src/random.cpp @@ -92,67 +92,6 @@ void OS_Seed::GenerateSeed(byte* output, word32 sz) } -#elif defined(__NETWARE__) - -/* The OS_Seed implementation for Netware */ - -#include -#include - -// Loop on high resulution Read Time Stamp Counter -static void NetwareSeed(byte* output, word32 sz) -{ - word32 tscResult; - - for (word32 i = 0; i < sz; i += sizeof(tscResult)) { - #if defined(__GNUC__) - asm volatile("rdtsc" : "=A" (tscResult)); - #else - #ifdef __MWERKS__ - asm { - #else - __asm { - #endif - rdtsc - mov tscResult, eax - } - #endif - - memcpy(output, &tscResult, sizeof(tscResult)); - output += sizeof(tscResult); - - NXThreadYield(); // induce more variance - } -} - - -OS_Seed::OS_Seed() -{ -} - - -OS_Seed::~OS_Seed() -{ -} - - -void OS_Seed::GenerateSeed(byte* output, word32 sz) -{ - /* - Try to use NXSeedRandom as it will generate a strong - seed using the onboard 82802 chip - - As it's not always supported, fallback to default - implementation if an error is returned - */ - - if (NXSeedRandom(sz, output) != 0) - { - NetwareSeed(output, sz); - } -} - - #else /* The default OS_Seed implementation */ diff --git a/extra/yassl/testsuite/test.hpp b/extra/yassl/testsuite/test.hpp index c921f8f9c69..31fad36aaba 100644 --- a/extra/yassl/testsuite/test.hpp +++ b/extra/yassl/testsuite/test.hpp @@ -32,8 +32,7 @@ #endif /* _WIN32 */ -#if !defined(_SOCKLEN_T) && \ - (defined(_WIN32) || defined(__NETWARE__) || defined(__APPLE__)) +#if !defined(_SOCKLEN_T) && (defined(_WIN32) || defined(__APPLE__)) typedef int socklen_t; #endif @@ -42,18 +41,14 @@ #if defined(__hpux) // HPUX uses int* for third parameter to accept typedef int* ACCEPT_THIRD_T; -#elif defined(__NETWARE__) -// NetWare uses size_t* for third parameter to accept - typedef size_t* ACCEPT_THIRD_T; #else typedef socklen_t* ACCEPT_THIRD_T; #endif // Check if _POSIX_THREADS should be forced -#if !defined(_POSIX_THREADS) && (defined(__NETWARE__) || defined(__hpux)) +#if !defined(_POSIX_THREADS) && defined(__hpux) // HPUX does not define _POSIX_THREADS as it's not _fully_ implemented -// Netware supports pthreads but does not announce it #define _POSIX_THREADS #endif -- cgit v1.2.1 From 3c418c57097e307f1b6b3af58a35c72bd4771a55 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 15 Jul 2010 08:28:41 -0300 Subject: WL#5486: Remove code for unsupported platforms Remove QNX specific code. --- extra/yassl/taocrypt/include/misc.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extra') diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp index 96648a39aa1..431316b84d1 100644 --- a/extra/yassl/taocrypt/include/misc.hpp +++ b/extra/yassl/taocrypt/include/misc.hpp @@ -125,7 +125,7 @@ void CleanUp(); // no gas on these systems ?, disable for now -#if defined(__sun__) || defined (__QNX__) || defined (__APPLE__) +#if defined(__sun__) || defined (__APPLE__) #define TAOCRYPT_DISABLE_X86ASM #endif -- cgit v1.2.1