1 diff -ruN a/innobase/include/srv0srv.h b/innobase/include/srv0srv.h
2 --- a/innobase/include/srv0srv.h 2009-07-06 15:59:52.000000000 +0900
3 +++ b/innobase/include/srv0srv.h 2009-07-06 16:06:51.000000000 +0900
5 extern ulint srv_mem_pool_size;
6 extern ulint srv_lock_table_size;
8 +extern ibool srv_use_sys_malloc;
9 extern ibool srv_thread_concurrency_timer_based;
11 extern ulint srv_n_file_io_threads;
12 diff -ruN a/innobase/include/ut0mem.h b/innobase/include/ut0mem.h
13 --- a/innobase/include/ut0mem.h 2009-07-07 21:54:07.000000000 +0900
14 +++ b/innobase/include/ut0mem.h 2009-08-03 14:42:17.000000000 +0900
18 /**************************************************************************
19 +Initializes the mem block list at database startup. */
22 +ut_mem_block_list_init(void);
23 +/*========================*/
25 +/**************************************************************************
26 Allocates memory. Sets it also to zero if UNIV_SET_MEM_TO_ZERO is
27 defined and set_to_zero is TRUE. */
29 diff -ruN a/innobase/mem/mem0dbg.c b/innobase/mem/mem0dbg.c
30 --- a/innobase/mem/mem0dbg.c 2009-05-08 06:12:10.000000000 +0900
31 +++ b/innobase/mem/mem0dbg.c 2009-07-06 16:48:17.000000000 +0900
33 mem_hash_initialized = TRUE;
36 + if (UNIV_LIKELY(srv_use_sys_malloc)) {
37 + /* When innodb_use_sys_malloc is set, the
38 + mem_comm_pool won't be used for any allocations. We
39 + create a dummy mem_comm_pool, because some statistics
40 + and debugging code relies on it being initialized. */
44 mem_comm_pool = mem_pool_create(size);
47 diff -ruN a/innobase/mem/mem0pool.c b/innobase/mem/mem0pool.c
48 --- a/innobase/mem/mem0pool.c 2009-05-08 06:12:10.000000000 +0900
49 +++ b/innobase/mem/mem0pool.c 2009-07-06 17:22:09.000000000 +0900
51 #include "mem0pool.ic"
55 #include "sync0sync.h"
64 pool = ut_malloc(sizeof(mem_pool_t));
66 /* We do not set the memory to zero (FALSE) in the pool,
71 + if (UNIV_LIKELY(srv_use_sys_malloc)) {
72 + return(malloc(size));
75 n = ut_2_log(ut_max(size + MEM_AREA_EXTRA_SIZE, MEM_AREA_MIN_SIZE));
77 mutex_enter(&(pool->mutex));
82 + if (UNIV_LIKELY(srv_use_sys_malloc)) {
87 /* It may be that the area was really allocated from the OS with
88 regular malloc: check if ptr points within our memory pool */
90 diff -ruN a/innobase/srv/srv0srv.c b/innobase/srv/srv0srv.c
91 --- a/innobase/srv/srv0srv.c 2009-07-06 15:59:52.000000000 +0900
92 +++ b/innobase/srv/srv0srv.c 2009-07-06 16:08:06.000000000 +0900
94 computer. Bigger computers need bigger values. Value 0 will disable the
97 +ibool srv_use_sys_malloc = TRUE;
98 ibool srv_thread_concurrency_timer_based = TRUE;
99 ulong srv_thread_concurrency = 0;
100 ulong srv_commit_concurrency = 0;
101 @@ -1012,6 +1013,7 @@
102 srv_general_init(void)
103 /*==================*/
105 + ut_mem_block_list_init();
108 mem_init(srv_mem_pool_size);
109 diff -ruN a/innobase/srv/srv0start.c b/innobase/srv/srv0start.c
110 --- a/innobase/srv/srv0start.c 2009-07-06 15:59:52.000000000 +0900
111 +++ b/innobase/srv/srv0start.c 2009-07-06 16:23:38.000000000 +0900
112 @@ -1040,6 +1040,11 @@
116 + if (UNIV_LIKELY(srv_use_sys_malloc)) {
118 + "InnoDB: The InnoDB memory heap is disabled\n");
121 #ifdef HAVE_ATOMIC_BUILTINS
123 "InnoDB: use atomic builtins.\n");
124 diff -ruN a/innobase/ut/ut0mem.c b/innobase/ut/ut0mem.c
125 --- a/innobase/ut/ut0mem.c 2009-05-08 06:12:13.000000000 +0900
126 +++ b/innobase/ut/ut0mem.c 2009-07-06 16:42:26.000000000 +0900
130 #include "os0thread.h"
131 +#include "srv0srv.h"
133 /* This struct is placed first in every allocated memory block */
134 typedef struct ut_mem_block_struct ut_mem_block_t;
137 /**************************************************************************
138 Initializes the mem block list at database startup. */
142 ut_mem_block_list_init(void)
143 /*========================*/
145 ulint retry_count = 0;
148 - ut_ad((sizeof(ut_mem_block_t) % 8) == 0); /* check alignment ok */
149 + if (UNIV_LIKELY(srv_use_sys_malloc)) {
151 + ut_a(ret || !assert_on_error);
153 - if (!ut_mem_block_list_inited) {
154 - ut_mem_block_list_init();
155 +#ifdef UNIV_SET_MEM_TO_ZERO
157 + memset(ret, '\0', n);
163 + ut_ad((sizeof(ut_mem_block_t) % 8) == 0); /* check alignment ok */
165 + ut_a(ut_mem_block_list_inited);
167 os_fast_mutex_lock(&ut_list_mutex);
171 ut_mem_block_t* block;
173 + if (UNIV_LIKELY(srv_use_sys_malloc)) {
178 block = (ut_mem_block_t*)((byte*)ptr - sizeof(ut_mem_block_t));
180 os_fast_mutex_lock(&ut_list_mutex);
185 + if (UNIV_LIKELY(srv_use_sys_malloc)) {
186 + return(realloc(ptr, size));
191 return(ut_malloc(size));
192 diff -ruN a/patch_info/innodb_use_sys_malloc.info b/patch_info/innodb_use_sys_malloc.info
193 --- /dev/null 1970-01-01 09:00:00.000000000 +0900
194 +++ b/patch_info/innodb_use_sys_malloc.info 2009-07-06 16:04:24.000000000 +0900
196 +File=innodb_use_sys_malloc.patch
197 +Name=InnoDB uses malloc directly (backport from InnoDB-Plugin)
199 +Author=Percona <info@percona.com>
202 diff -ruN a/sql/ha_innodb.cc b/sql/ha_innodb.cc
203 --- a/sql/ha_innodb.cc 2009-07-06 15:59:52.000000000 +0900
204 +++ b/sql/ha_innodb.cc 2009-07-06 16:10:15.000000000 +0900
208 long innobase_read_io_threads, innobase_write_io_threads;
209 +my_bool innobase_use_sys_malloc;
210 my_bool innobase_thread_concurrency_timer_based;
211 long innobase_extra_rsegments;
212 longlong innobase_buffer_pool_size, innobase_log_file_size;
213 @@ -1492,6 +1493,8 @@
214 srv_n_log_files = (ulint) innobase_log_files_in_group;
215 srv_log_file_size = (ulint) innobase_log_file_size;
217 + srv_use_sys_malloc = (ibool) innobase_use_sys_malloc;
219 srv_thread_concurrency_timer_based =
220 (ibool) innobase_thread_concurrency_timer_based;
222 diff -ruN a/sql/ha_innodb.h b/sql/ha_innodb.h
223 --- a/sql/ha_innodb.h 2009-07-06 15:59:52.000000000 +0900
224 +++ b/sql/ha_innodb.h 2009-07-06 16:10:42.000000000 +0900
226 extern long innobase_buffer_pool_awe_mem_mb;
227 extern long innobase_file_io_threads, innobase_lock_wait_timeout;
228 extern long innobase_read_io_threads, innobase_write_io_threads;
229 +extern my_bool innobase_use_sys_malloc;
230 extern my_bool innobase_thread_concurrency_timer_based;
231 extern long innobase_extra_rsegments;
232 extern long innobase_force_recovery;
233 diff -ruN a/sql/mysqld.cc b/sql/mysqld.cc
234 --- a/sql/mysqld.cc 2009-07-06 15:59:52.000000000 +0900
235 +++ b/sql/mysqld.cc 2009-07-06 16:16:56.000000000 +0900
236 @@ -5102,6 +5102,7 @@
237 OPT_INNODB_ADAPTIVE_CHECKPOINT,
238 OPT_INNODB_READ_IO_THREADS,
239 OPT_INNODB_WRITE_IO_THREADS,
240 + OPT_INNODB_USE_SYS_MALLOC,
241 OPT_INNODB_THREAD_CONCURRENCY_TIMER_BASED,
242 OPT_INNODB_EXTRA_RSEGMENTS,
243 OPT_INNODB_DICT_SIZE_LIMIT,
244 @@ -5470,6 +5471,10 @@
245 "Number of background write I/O threads in InnoDB.",
246 (gptr*) &innobase_write_io_threads, (gptr*) &innobase_write_io_threads,
247 0, GET_LONG, REQUIRED_ARG, 8, 1, 64, 0, 0, 0},
248 + {"innodb_use_sys_malloc", OPT_INNODB_USE_SYS_MALLOC,
249 + "Use OS memory allocator instead of InnoDB's internal memory allocator",
250 + (gptr*) &innobase_use_sys_malloc, (gptr*) &innobase_use_sys_malloc,
251 + 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
252 {"innodb_thread_concurrency_timer_based", OPT_INNODB_THREAD_CONCURRENCY_TIMER_BASED,
253 "Use InnoDB timer based concurrency throttling. ",
254 (gptr*) &innobase_thread_concurrency_timer_based,
255 diff -ruN a/sql/set_var.cc b/sql/set_var.cc
256 --- a/sql/set_var.cc 2009-07-06 15:59:52.000000000 +0900
257 +++ b/sql/set_var.cc 2009-07-06 16:22:05.000000000 +0900
258 @@ -1093,6 +1093,7 @@
259 {sys_innodb_adaptive_checkpoint.name, (char*) &sys_innodb_adaptive_checkpoint, SHOW_SYS},
260 {"innodb_read_io_threads", (char*) &innobase_read_io_threads, SHOW_LONG},
261 {"innodb_write_io_threads", (char*) &innobase_write_io_threads, SHOW_LONG},
262 + {"innodb_use_sys_malloc", (char*) &innobase_use_sys_malloc, SHOW_MY_BOOL},
263 {"innodb_thread_concurrency_timer_based", (char*) &innobase_thread_concurrency_timer_based, SHOW_MY_BOOL},
264 {"innodb_extra_rsegments", (char*) &innobase_extra_rsegments, SHOW_LONG},
265 {sys_innodb_dict_size_limit.name, (char*) &sys_innodb_dict_size_limit, SHOW_SYS},