diff --git a/handler/ha_innodb.cc b/handler/ha_innodb.cc index e1c5c6fc38e..384ee4407ed 100644 --- a/handler/ha_innodb.cc +++ b/handler/ha_innodb.cc @@ -9583,6 +9583,11 @@ static MYSQL_SYSVAR_STR(version, innodb_version_str, PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_READONLY, "InnoDB version", NULL, NULL, INNODB_VERSION_STR); +static MYSQL_SYSVAR_BOOL(use_sys_malloc, srv_use_sys_malloc, + PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY, + "Use OS memory allocator instead of InnoDB's internal memory allocator", + NULL, NULL, FALSE); + static struct st_mysql_sys_var* innobase_system_variables[]= { MYSQL_SYSVAR(additional_mem_pool_size), MYSQL_SYSVAR(autoextend_increment), @@ -9629,6 +9634,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= { MYSQL_SYSVAR(thread_sleep_delay), MYSQL_SYSVAR(autoinc_lock_mode), MYSQL_SYSVAR(version), + MYSQL_SYSVAR(use_sys_malloc), NULL }; diff --git a/include/srv0srv.h b/include/srv0srv.h index 878afa0feb3..4a0609be4dc 100644 --- a/include/srv0srv.h +++ b/include/srv0srv.h @@ -93,6 +93,7 @@ extern ulong srv_flush_log_at_trx_commit; /* The sort order table of the MySQL latin1_swedish_ci character set collation */ extern const byte* srv_latin1_ordering; +extern my_bool srv_use_sys_malloc; extern ulint srv_buf_pool_size; /* requested size in bytes */ extern ulint srv_buf_pool_old_size; /* previously requested size */ extern ulint srv_buf_pool_curr_size; /* current size in bytes */ diff --git a/mem/mem0pool.c b/mem/mem0pool.c index d3bf4d04853..4f26ec560bf 100644 --- a/mem/mem0pool.c +++ b/mem/mem0pool.c @@ -11,6 +11,7 @@ Created 5/12/1997 Heikki Tuuri #include "mem0pool.ic" #endif +#include "srv0srv.h" #include "sync0sync.h" #include "ut0mem.h" #include "ut0lst.h" @@ -336,6 +337,12 @@ mem_area_alloc( ulint n; ibool ret; + /* If we are using os allocator just make a simple call + to malloc */ + if (srv_use_sys_malloc) { + return(malloc(*psize)); + } + size = *psize; n = ut_2_log(ut_max(size + MEM_AREA_EXTRA_SIZE, MEM_AREA_MIN_SIZE)); @@ -470,6 +477,10 @@ mem_area_free( ulint size; ulint n; + if (srv_use_sys_malloc) { + return(free(ptr)); + } + /* It may be that the area was really allocated from the OS with regular malloc: check if ptr points within our memory pool */ diff --git a/mysql-test/innodb-use-sys-malloc-master.opt b/mysql-test/innodb-use-sys-malloc-master.opt new file mode 100644 index 00000000000..889834add01 --- /dev/null +++ b/mysql-test/innodb-use-sys-malloc-master.opt @@ -0,0 +1,2 @@ +--innodb-use-sys-malloc=true +--innodb-use-sys-malloc=true diff --git a/mysql-test/innodb-use-sys-malloc.result b/mysql-test/innodb-use-sys-malloc.result new file mode 100644 index 00000000000..2ec4c7c8130 --- /dev/null +++ b/mysql-test/innodb-use-sys-malloc.result @@ -0,0 +1,48 @@ +SELECT @@GLOBAL.innodb_use_sys_malloc; +@@GLOBAL.innodb_use_sys_malloc +1 +1 Expected +SET @@GLOBAL.innodb_use_sys_malloc=0; +ERROR HY000: Variable 'innodb_use_sys_malloc' is a read only variable +Expected error 'Read only variable' +SELECT @@GLOBAL.innodb_use_sys_malloc; +@@GLOBAL.innodb_use_sys_malloc +1 +1 Expected +drop table if exists t1; +create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1; +insert into t1 values (1),(2),(3),(4),(5),(6),(7); +select * from t1; +a +1 +2 +3 +4 +5 +6 +7 +drop table t1; +SELECT @@GLOBAL.innodb_use_sys_malloc; +@@GLOBAL.innodb_use_sys_malloc +1 +1 Expected +SET @@GLOBAL.innodb_use_sys_malloc=0; +ERROR HY000: Variable 'innodb_use_sys_malloc' is a read only variable +Expected error 'Read only variable' +SELECT @@GLOBAL.innodb_use_sys_malloc; +@@GLOBAL.innodb_use_sys_malloc +1 +1 Expected +drop table if exists t1; +create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1; +insert into t1 values (1),(2),(3),(4),(5),(6),(7); +select * from t1; +a +1 +2 +3 +4 +5 +6 +7 +drop table t1; diff --git a/mysql-test/innodb-use-sys-malloc.test b/mysql-test/innodb-use-sys-malloc.test new file mode 100644 index 00000000000..325dd19d086 --- /dev/null +++ b/mysql-test/innodb-use-sys-malloc.test @@ -0,0 +1,48 @@ +--source include/have_innodb.inc + +#display current value of innodb_use_sys_malloc +SELECT @@GLOBAL.innodb_use_sys_malloc; +--echo 1 Expected + +#try changing it. Should fail. +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +SET @@GLOBAL.innodb_use_sys_malloc=0; +--echo Expected error 'Read only variable' + +SELECT @@GLOBAL.innodb_use_sys_malloc; +--echo 1 Expected + + +#do some stuff to see if it works. +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1; +insert into t1 values (1),(2),(3),(4),(5),(6),(7); +select * from t1; +drop table t1; +--source include/have_innodb.inc + +#display current value of innodb_use_sys_malloc +SELECT @@GLOBAL.innodb_use_sys_malloc; +--echo 1 Expected + +#try changing it. Should fail. +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +SET @@GLOBAL.innodb_use_sys_malloc=0; +--echo Expected error 'Read only variable' + +SELECT @@GLOBAL.innodb_use_sys_malloc; +--echo 1 Expected + + +#do some stuff to see if it works. +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1; +insert into t1 values (1),(2),(3),(4),(5),(6),(7); +select * from t1; +drop table t1; diff --git a/srv/srv0srv.c b/srv/srv0srv.c index d75269e96d5..84a053dc7b6 100644 --- a/srv/srv0srv.c +++ b/srv/srv0srv.c @@ -136,6 +136,8 @@ UNIV_INTERN ulong srv_flush_log_at_trx_commit = 1; collation */ UNIV_INTERN const byte* srv_latin1_ordering; +/* use os/external memory allocator */ +UNIV_INTERN my_bool srv_use_sys_malloc = FALSE; /* requested size in kilobytes */ UNIV_INTERN ulint srv_buf_pool_size = ULINT_MAX; /* previously requested size */ diff --git a/srv/srv0start.c b/srv/srv0start.c index 1e8c10c13bb..d484e728cff 100644 --- a/srv/srv0start.c +++ b/srv/srv0start.c @@ -1047,6 +1047,11 @@ innobase_start_or_create_for_mysql(void) "InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n"); #endif + if (srv_use_sys_malloc) { + fprintf(stderr, + "InnoDB: The InnoDB memory heap is disabled\n"); + } + /* Since InnoDB does not currently clean up all its internal data structures in MySQL Embedded Server Library server_end(), we print an error message if someone tries to start up InnoDB a