diff --git a/include/gen_utils.h b/include/gen_utils.h index b8cd5aadc..260836db7 100644 --- a/include/gen_utils.h +++ b/include/gen_utils.h @@ -27,15 +27,16 @@ class PtrArray { volatile unsigned int size; void expand(unsigned int); void shrink(); - bool use_l_alloc; +// bool use_l_alloc; public: - void * operator new(size_t); - void operator delete(void *); - void * operator new(size_t, bool); - void operator delete(void *, bool); +// void * operator new(size_t); +// void operator delete(void *); +// void * operator new(size_t, bool); +// void operator delete(void *, bool); void **pdata; unsigned int len; - PtrArray(unsigned int __size=0, bool _use_l_alloc=false); + //PtrArray(unsigned int __size=0, bool _use_l_alloc=false); + PtrArray(unsigned int __size=0); ~PtrArray(); void *index(unsigned int i) { return pdata[i];} ; diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index f93457f56..39fd81b1a 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -35,7 +35,7 @@ class ProxySQL_GlobalVariables { unsigned long long start_time; bool gdbg; bool nostart; - bool use_proxysql_mem; +// bool use_proxysql_mem; pthread_mutex_t start_mutex; bool foreground; #ifdef DEBUG diff --git a/include/proxysql_mem.h b/include/proxysql_mem.h index 77ffbba84..da1de70f0 100644 --- a/include/proxysql_mem.h +++ b/include/proxysql_mem.h @@ -31,7 +31,7 @@ struct _l_super_free_pool_t { }; #endif -extern __thread l_sfp *__thr_sfp; +//extern __thread l_sfp *__thr_sfp; l_sfp * l_mem_init(); void l_mem_destroy(l_sfp *); @@ -45,10 +45,10 @@ void __l_free(l_sfp *, size_t, void *); #ifndef L_STACK #define L_STACK -#define l_alloc(s) __l_alloc(__thr_sfp,s) -#define l_free(s,p) __l_free(__thr_sfp,s,p) -//#define l_alloc(s) malloc(s) -//#define l_free(s,p) free(p) +//#define l_alloc(s) __l_alloc(__thr_sfp,s) +//#define l_free(s,p) __l_free(__thr_sfp,s,p) +#define l_alloc(s) malloc(s) +#define l_free(s,p) free(p) static inline void l_stack_push (l_stack **s, void *p) { l_stack *d=(l_stack *)p; @@ -72,10 +72,12 @@ static inline char * l_strdup(const char *s) { return r; } +/* static inline void l_free_string(const char *s) { size_t len=strlen(s)+1; l_free(len,(char *)s); } +*/ diff --git a/lib/Makefile b/lib/Makefile index 65e870799..c213dce93 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -50,7 +50,7 @@ default: libproxysql.a _OBJ = c_tokenizer.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) -_OBJ_CPP = ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo SpookyV2.oo MySQL_Authentication.oo gen_utils.oo simple_kv.oo sqlite3db.oo global_variables.oo proxysql_mem.oo mysql_connection.oo MySQL_HostGroups_Manager.oo mysql_data_stream.oo MySQL_Thread.oo MySQL_Session.oo MySQL_Protocol.oo mysql_backend.oo Query_Processor.oo ProxySQL_Admin.oo MySQL_Monitor.oo MySQL_Logger.oo +_OBJ_CPP = ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo SpookyV2.oo MySQL_Authentication.oo gen_utils.oo simple_kv.oo sqlite3db.oo global_variables.oo mysql_connection.oo MySQL_HostGroups_Manager.oo mysql_data_stream.oo MySQL_Thread.oo MySQL_Session.oo MySQL_Protocol.oo mysql_backend.oo Query_Processor.oo ProxySQL_Admin.oo MySQL_Monitor.oo MySQL_Logger.oo OBJ_CPP = $(patsubst %,$(ODIR)/%,$(_OBJ_CPP)) %.ko: %.cpp diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index d23d3877a..6a5558b53 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -790,7 +790,8 @@ bool MySQL_Protocol::generate_pkt_auth_switch_request(bool send, void **ptr, uns + 20 // scramble + 1; // 00 unsigned int size=myhdr.pkt_length+sizeof(mysql_hdr); - unsigned char *_ptr=(unsigned char *)l_alloc0(size); + unsigned char *_ptr=(unsigned char *)malloc(size); + memset(_ptr,0,size); memcpy(_ptr, &myhdr, sizeof(mysql_hdr)); int l; l=sizeof(mysql_hdr); @@ -839,7 +840,8 @@ bool MySQL_Protocol::generate_pkt_initial_handshake(bool send, void **ptr, unsig unsigned int size=myhdr.pkt_length+sizeof(mysql_hdr); //mypkt->data=g_slice_alloc0(mypkt->length); //mypkt->data=l_alloc0(thrLD->sfp, mypkt->length); - unsigned char *_ptr=(unsigned char *)l_alloc0(size); + unsigned char *_ptr=(unsigned char *)malloc(size); + memset(_ptr,0,size); memcpy(_ptr, &myhdr, sizeof(mysql_hdr)); //Copy4B(_ptr, &myhdr); int l; @@ -1099,7 +1101,10 @@ bool MySQL_Protocol::process_pkt_COM_CHANGE_USER(unsigned char *pkt, unsigned in /*if (pass_len) */ userinfo->password=strdup((const char *)""); } //if (password) free(password); - if (password) l_free_string(password); + if (password) { + free(password); + password=NULL; + } return ret; } @@ -1214,7 +1219,10 @@ bool MySQL_Protocol::process_pkt_handshake_response(unsigned char *pkt, unsigned if (pass_len) userinfo->password=strdup((const char *)""); } //if (password) free(password); - if (password) l_free_string(password); + if (password) { + free(password); + password=NULL; + } //l_free(len,pkt); return ret; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 7ad4743b9..29c2d2b47 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -208,7 +208,7 @@ MySQL_Session::MySQL_Session() { //server_myds=NULL; to_process=0; mybe=NULL; - mybes= new (true) PtrArray(4,true); + mybes= new PtrArray(4); set_status(NONE); CurrentQuery.sess=this; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index c1160a79a..662afb02f 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -1615,7 +1615,7 @@ __run_query: void *child_mysql(void *arg) { int client = *(int *)arg; - __thr_sfp=l_mem_init(); +// __thr_sfp=l_mem_init(); GloMTH->wrlock(); mysql_thread___server_version=GloMTH->get_variable((char *)"server_version"); @@ -1696,7 +1696,7 @@ __exit_child_mysql: if (mysql_thread___default_schema) { free(mysql_thread___default_schema); mysql_thread___default_schema=NULL; } if (mysql_thread___server_version) { free(mysql_thread___server_version); mysql_thread___server_version=NULL; } delete mysql_thr; - l_mem_destroy(__thr_sfp); +// l_mem_destroy(__thr_sfp); return NULL; } diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index 048b273dc..1a4d689f4 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -55,7 +55,7 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() { global.gdbg=false; global.nostart=false; global.foreground=false; - global.use_proxysql_mem=false; +// global.use_proxysql_mem=false; pthread_mutex_init(&global.start_mutex,NULL); #ifdef DEBUG global.gdb=0; @@ -76,7 +76,7 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() { opt->add((const char *)"",0,0,0,(const char *)"Run in foreground",(const char *)"-f",(const char *)"--foreground"); opt->add((const char *)"",0,0,0,(const char *)"Do not restart ProxySQL if crashes",(const char *)"-e",(const char *)"--exit-on-error"); opt->add((const char *)"~/proxysql.cnf",0,1,0,(const char *)"Configuraton file",(const char *)"-c",(const char *)"--config"); - opt->add((const char *)"",0,0,0,(const char *)"Enable custom memory allocator",(const char *)"-m",(const char *)"--custom-memory"); + //opt->add((const char *)"",0,0,0,(const char *)"Enable custom memory allocator",(const char *)"-m",(const char *)"--custom-memory"); opt->add((const char *)"",0,1,0,(const char *)"Datadir",(const char *)"-D",(const char *)"--datadir"); opt->add((const char *)"",0,0,0,(const char *)"Rename/empty database file",(const char *)"--initial"); opt->add((const char *)"",0,0,0,(const char *)"Merge config file into database file",(const char *)"--reload"); @@ -136,9 +136,9 @@ void ProxySQL_GlobalVariables::process_opts_pre() { GloVars.__cmd_proxysql_datadir=strdup(datadir.c_str()); } - if (opt->isSet("-m")) { - global.use_proxysql_mem=true; - } +// if (opt->isSet("-m")) { +// global.use_proxysql_mem=true; +// } if (opt->isSet("--initial")) { __cmd_proxysql_initial=true; diff --git a/lib/gen_utils.cpp b/lib/gen_utils.cpp index f9a0bfb74..407787f47 100644 --- a/lib/gen_utils.cpp +++ b/lib/gen_utils.cpp @@ -42,6 +42,7 @@ static unsigned int l_near_pow_2 (unsigned int n) { // PtrArray is used also for shared struct, needs to fork the class in two) +/* void * PtrArray::operator new(size_t size) { return malloc(size); } @@ -57,11 +58,12 @@ void * PtrArray::operator new(size_t size, bool b) { void PtrArray::operator delete(void *ptr, bool b) { l_free(sizeof(PtrArray), ptr); } +*/ - -PtrArray::PtrArray(unsigned int __size, bool _use_l_alloc) { - use_l_alloc=false; - use_l_alloc=_use_l_alloc; +//PtrArray::PtrArray(unsigned int __size, bool _use_l_alloc) { +PtrArray::PtrArray(unsigned int __size) { +// use_l_alloc=false; +// use_l_alloc=_use_l_alloc; len=0; pdata=NULL; size=0; @@ -72,7 +74,8 @@ PtrArray::PtrArray(unsigned int __size, bool _use_l_alloc) { } PtrArray::~PtrArray() { - if (pdata) (use_l_alloc ? l_free(size*sizeof(void *),pdata) : free(pdata) ); + //if (pdata) (use_l_alloc ? l_free(size*sizeof(void *),pdata) : free(pdata) ); + if (pdata) ( free(pdata) ); //if (pdata) l_free(size*sizeof(void *),pdata); pdata=NULL; } @@ -80,7 +83,8 @@ PtrArray::~PtrArray() { void PtrArray::shrink() { unsigned int new_size=l_near_pow_2(len+1); - pdata=(use_l_alloc ? (void **)l_realloc(pdata,new_size*sizeof(void *),size*sizeof(void *)) : (void **)realloc(pdata,new_size*sizeof(void *)) ); + //pdata=(use_l_alloc ? (void **)l_realloc(pdata,new_size*sizeof(void *),size*sizeof(void *)) : (void **)realloc(pdata,new_size*sizeof(void *)) ); + pdata=(void **)realloc(pdata,new_size*sizeof(void *)); //pdata=(void **)realloc(pdata,new_size*sizeof(void *)); //pdata=(void **)l_realloc(pdata,new_size*sizeof(void *),size*sizeof(void *)); size=new_size; @@ -89,13 +93,15 @@ void PtrArray::shrink() { void PtrArray::expand(unsigned int more) { if ( (len+more) > size ) { unsigned int new_size=l_near_pow_2(len+more); - void *new_pdata=( use_l_alloc ? l_alloc(new_size*sizeof(void *)) : malloc(new_size*sizeof(void *)) ); + //void *new_pdata=( use_l_alloc ? l_alloc(new_size*sizeof(void *)) : malloc(new_size*sizeof(void *)) ); + void *new_pdata=malloc(new_size*sizeof(void *)); memset(new_pdata,0,new_size*sizeof(void *)); //void *new_pdata=malloc(new_size*sizeof(void *)); //void *new_pdata=l_alloc(new_size*sizeof(void *)); if (pdata) { memcpy(new_pdata,pdata,size*sizeof(void *)); - ( use_l_alloc ? l_free(size*sizeof(void *),pdata) : free(pdata) ); + //( use_l_alloc ? l_free(size*sizeof(void *),pdata) : free(pdata) ); + free(pdata); //free(pdata); //l_free(size*sizeof(void *),pdata); } @@ -194,7 +200,7 @@ PtrSizeArray::~PtrSizeArray() { void PtrSizeArray::shrink() { unsigned int new_size=l_near_pow_2(len+1); //pdata=(PtrSize_t *)realloc(pdata,new_size*sizeof(PtrSize_t)); - pdata=(PtrSize_t *)l_realloc(pdata,new_size*sizeof(PtrSize_t),size*sizeof(PtrSize_t)); + pdata=(PtrSize_t *)realloc(pdata,new_size*sizeof(PtrSize_t)); size=new_size; } diff --git a/lib/proxysql_mem.cpp b/lib/proxysql_mem.cpp index 7348e59f1..3d9f9882f 100644 --- a/lib/proxysql_mem.cpp +++ b/lib/proxysql_mem.cpp @@ -1,3 +1,12 @@ +/* + NOTE NOTE NOTE NOTE + + THIS FILE IS NOT USED ANYMORE + IT IS LEFT HERE ONLY FOR REFERENCE + + NOTE NOTE NOTE NOTE +*/ + #include "proxysql.h" diff --git a/src/main.cpp b/src/main.cpp index 139215e78..6ddcbb4e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,7 +101,7 @@ using namespace std; static volatile int load_; -__thread l_sfp *__thr_sfp=NULL; +//__thread l_sfp *__thr_sfp=NULL; const char *malloc_conf = "xmalloc:true,lg_tcache_max:16"; @@ -123,7 +123,7 @@ MySQL_Logger *GloMyLogger; void * mysql_worker_thread_func(void *arg) { - __thr_sfp=l_mem_init(); +// __thr_sfp=l_mem_init(); proxysql_mysql_thread_t *mysql_thread=(proxysql_mysql_thread_t *)arg; MySQL_Thread *worker = new MySQL_Thread(); mysql_thread->worker=worker; @@ -136,7 +136,7 @@ void * mysql_worker_thread_func(void *arg) { worker->run(); //delete worker; delete worker; - l_mem_destroy(__thr_sfp); +// l_mem_destroy(__thr_sfp); return NULL; } @@ -317,7 +317,7 @@ void ProxySQL_Main_init() { #else glovars.has_debug=false; #endif /* DEBUG */ - __thr_sfp=l_mem_init(); +// __thr_sfp=l_mem_init(); { /* moved here, so if needed by multiple modules it applies to all of them */ @@ -583,7 +583,7 @@ finish: daemon_signal_done(); daemon_pid_file_remove(); - l_mem_destroy(__thr_sfp); +// l_mem_destroy(__thr_sfp); return 0; }