1 # name : innodb_io_patches.patch
2 # introduced : 11 or before
3 # maintainer : Yasufumi
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 diff -ruN a/storage/innobase/buf/buf0buf.c b/storage/innobase/buf/buf0buf.c
9 --- a/storage/innobase/buf/buf0buf.c 2010-12-03 15:09:51.273986410 +0900
10 +++ b/storage/innobase/buf/buf0buf.c 2010-12-03 15:10:08.934990091 +0900
13 /* When we traverse all the flush lists we don't want another
14 thread to add a dirty page to any flush list. */
15 + if (srv_buf_pool_instances > 1)
16 log_flush_order_mutex_enter();
18 for (i = 0; i < srv_buf_pool_instances; i++) {
23 + if (srv_buf_pool_instances > 1)
24 log_flush_order_mutex_exit();
26 /* The returned answer may be out of date: the flush_list can
27 diff -ruN a/storage/innobase/buf/buf0flu.c b/storage/innobase/buf/buf0flu.c
28 --- a/storage/innobase/buf/buf0flu.c 2010-11-03 07:01:13.000000000 +0900
29 +++ b/storage/innobase/buf/buf0flu.c 2010-12-03 15:10:08.934990091 +0900
32 ut_ad(flush_type == BUF_FLUSH_LRU || flush_type == BUF_FLUSH_LIST);
34 - if (UT_LIST_GET_LEN(buf_pool->LRU) < BUF_LRU_OLD_MIN_LEN) {
35 + if (UT_LIST_GET_LEN(buf_pool->LRU) < BUF_LRU_OLD_MIN_LEN || !srv_flush_neighbor_pages) {
36 /* If there is little space, it is better not to flush
37 any block except from the end of the LRU list */
39 diff -ruN a/storage/innobase/buf/buf0rea.c b/storage/innobase/buf/buf0rea.c
40 --- a/storage/innobase/buf/buf0rea.c 2010-11-03 07:01:13.000000000 +0900
41 +++ b/storage/innobase/buf/buf0rea.c 2010-12-03 15:10:08.937050537 +0900
43 = BUF_READ_AHEAD_LINEAR_AREA(buf_pool);
46 + if (!(srv_read_ahead & 2)) {
50 if (UNIV_UNLIKELY(srv_startup_is_before_trx_rollback_phase)) {
51 /* No read-ahead to avoid thread deadlocks */
53 diff -ruN a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
54 --- a/storage/innobase/handler/ha_innodb.cc 2010-12-03 15:09:51.283956391 +0900
55 +++ b/storage/innobase/handler/ha_innodb.cc 2010-12-03 15:10:08.963980444 +0900
57 "Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout.",
58 NULL, NULL, 50, 1, 1024 * 1024 * 1024, 0);
60 +static MYSQL_THDVAR_ULONG(flush_log_at_trx_commit, PLUGIN_VAR_OPCMDARG,
61 + "Set to 0 (write and flush once per second),"
62 + " 1 (write and flush at each commit)"
63 + " or 2 (write at commit, flush once per second).",
64 + NULL, NULL, 1, 0, 2, 0);
67 static handler *innobase_create_handler(handlerton *hton,
73 +/******************************************************************//**
75 +extern "C" UNIV_INTERN
77 +thd_flush_log_at_trx_commit(
78 +/*================================*/
81 + return(THDVAR((THD*) thd, flush_log_at_trx_commit));
84 /********************************************************************//**
85 Obtain the InnoDB transaction of a MySQL thread.
86 @return reference to transaction pointer */
88 srv_n_read_io_threads = (ulint) innobase_read_io_threads;
89 srv_n_write_io_threads = (ulint) innobase_write_io_threads;
91 + srv_read_ahead &= 3;
92 + srv_adaptive_flushing_method %= 3;
94 srv_force_recovery = (ulint) innobase_force_recovery;
96 srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
97 @@ -11025,7 +11045,7 @@
98 PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
99 "Purge threads can be either 0 or 1.",
101 - 0, /* Default setting */
102 + 1, /* Default setting */
103 0, /* Minimum value */
104 1, 0); /* Maximum value */
106 @@ -11067,12 +11087,18 @@
107 innodb_file_format_max_validate,
108 innodb_file_format_max_update, "Antelope");
110 -static MYSQL_SYSVAR_ULONG(flush_log_at_trx_commit, srv_flush_log_at_trx_commit,
111 - PLUGIN_VAR_OPCMDARG,
112 - "Set to 0 (write and flush once per second),"
113 - " 1 (write and flush at each commit)"
114 - " or 2 (write at commit, flush once per second).",
115 - NULL, NULL, 1, 0, 2, 0);
116 +/* Changed to the THDVAR */
117 +//static MYSQL_SYSVAR_ULONG(flush_log_at_trx_commit, srv_flush_log_at_trx_commit,
118 +// PLUGIN_VAR_OPCMDARG,
119 +// "Set to 0 (write and flush once per second),"
120 +// " 1 (write and flush at each commit)"
121 +// " or 2 (write at commit, flush once per second).",
122 +// NULL, NULL, 1, 0, 2, 0);
124 +static MYSQL_SYSVAR_BOOL(use_global_flush_log_at_trx_commit, srv_use_global_flush_log_at_trx_commit,
125 + PLUGIN_VAR_NOCMDARG,
126 + "Use global innodb_flush_log_at_trx_commit value. (default: ON).",
129 static MYSQL_SYSVAR_STR(flush_method, innobase_file_flush_method,
130 PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
131 @@ -11167,7 +11193,7 @@
132 static MYSQL_SYSVAR_LONGLONG(buffer_pool_size, innobase_buffer_pool_size,
133 PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
134 "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
135 - NULL, NULL, 128*1024*1024L, 5*1024*1024L, LONGLONG_MAX, 1024*1024L);
136 + NULL, NULL, 128*1024*1024L, 32*1024*1024L, LONGLONG_MAX, 1024*1024L);
138 static MYSQL_SYSVAR_LONG(buffer_pool_instances, innobase_buffer_pool_instances,
139 PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
140 @@ -11319,6 +11345,95 @@
141 "trigger a readahead.",
142 NULL, NULL, 56, 0, 64, 0);
144 +static MYSQL_SYSVAR_LONGLONG(ibuf_max_size, srv_ibuf_max_size,
145 + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
146 + "The maximum size of the insert buffer. (in bytes)",
147 + NULL, NULL, LONGLONG_MAX, 0, LONGLONG_MAX, 0);
149 +static MYSQL_SYSVAR_ULONG(ibuf_active_contract, srv_ibuf_active_contract,
150 + PLUGIN_VAR_RQCMDARG,
151 + "Enable/Disable active_contract of insert buffer. 0:disable 1:enable",
152 + NULL, NULL, 1, 0, 1, 0);
154 +static MYSQL_SYSVAR_ULONG(ibuf_accel_rate, srv_ibuf_accel_rate,
155 + PLUGIN_VAR_RQCMDARG,
156 + "Tunes amount of insert buffer processing of background, in addition to innodb_io_capacity. (in percentage)",
157 + NULL, NULL, 100, 100, 999999999, 0);
159 +static MYSQL_SYSVAR_ULONG(checkpoint_age_target, srv_checkpoint_age_target,
160 + PLUGIN_VAR_RQCMDARG,
161 + "Control soft limit of checkpoint age. (0 : not control)",
162 + NULL, NULL, 0, 0, ~0UL, 0);
164 +static MYSQL_SYSVAR_ULONG(flush_neighbor_pages, srv_flush_neighbor_pages,
165 + PLUGIN_VAR_RQCMDARG,
166 + "Enable/Disable flushing also neighbor pages. 0:disable 1:enable",
167 + NULL, NULL, 1, 0, 1, 0);
171 +innodb_read_ahead_update(
173 + struct st_mysql_sys_var* var,
177 + *(long *)var_ptr= (*(long *)save) & 3;
179 +const char *read_ahead_names[]=
185 + /* For compatibility of the older patch */
186 + "0", /* 4 ("none" + 4) */
189 + "3", /* 7 ("both" + 4) */
192 +TYPELIB read_ahead_typelib=
194 + array_elements(read_ahead_names) - 1, "read_ahead_typelib",
195 + read_ahead_names, NULL
197 +static MYSQL_SYSVAR_ENUM(read_ahead, srv_read_ahead,
198 + PLUGIN_VAR_RQCMDARG,
199 + "Control read ahead activity (none, random, [linear], both). [from 1.0.5: random read ahead is ignored]",
200 + NULL, innodb_read_ahead_update, 2, &read_ahead_typelib);
204 +innodb_adaptive_flushing_method_update(
206 + struct st_mysql_sys_var* var,
210 + *(long *)var_ptr= (*(long *)save) % 4;
212 +const char *adaptive_flushing_method_names[]=
215 + "estimate", /* 1 */
216 + "keep_average", /* 2 */
217 + /* For compatibility of the older patch */
218 + "0", /* 3 ("none" + 3) */
219 + "1", /* 4 ("estimate" + 3) */
220 + "2", /* 5 ("keep_average" + 3) */
223 +TYPELIB adaptive_flushing_method_typelib=
225 + array_elements(adaptive_flushing_method_names) - 1, "adaptive_flushing_method_typelib",
226 + adaptive_flushing_method_names, NULL
228 +static MYSQL_SYSVAR_ENUM(adaptive_flushing_method, srv_adaptive_flushing_method,
229 + PLUGIN_VAR_RQCMDARG,
230 + "Choose method of innodb_adaptive_flushing. (native, [estimate], keep_average)",
231 + NULL, innodb_adaptive_flushing_method_update, 1, &adaptive_flushing_method_typelib);
233 static struct st_mysql_sys_var* innobase_system_variables[]= {
234 MYSQL_SYSVAR(additional_mem_pool_size),
235 MYSQL_SYSVAR(autoextend_increment),
236 @@ -11339,6 +11454,7 @@
237 MYSQL_SYSVAR(file_format_check),
238 MYSQL_SYSVAR(file_format_max),
239 MYSQL_SYSVAR(flush_log_at_trx_commit),
240 + MYSQL_SYSVAR(use_global_flush_log_at_trx_commit),
241 MYSQL_SYSVAR(flush_method),
242 MYSQL_SYSVAR(force_recovery),
243 MYSQL_SYSVAR(locks_unsafe_for_binlog),
244 @@ -11376,6 +11492,13 @@
245 MYSQL_SYSVAR(show_verbose_locks),
246 MYSQL_SYSVAR(show_locks_held),
247 MYSQL_SYSVAR(version),
248 + MYSQL_SYSVAR(ibuf_max_size),
249 + MYSQL_SYSVAR(ibuf_active_contract),
250 + MYSQL_SYSVAR(ibuf_accel_rate),
251 + MYSQL_SYSVAR(checkpoint_age_target),
252 + MYSQL_SYSVAR(flush_neighbor_pages),
253 + MYSQL_SYSVAR(read_ahead),
254 + MYSQL_SYSVAR(adaptive_flushing_method),
255 MYSQL_SYSVAR(use_sys_malloc),
256 MYSQL_SYSVAR(use_native_aio),
257 MYSQL_SYSVAR(change_buffering),
258 diff -ruN a/storage/innobase/ibuf/ibuf0ibuf.c b/storage/innobase/ibuf/ibuf0ibuf.c
259 --- a/storage/innobase/ibuf/ibuf0ibuf.c 2010-11-03 07:01:13.000000000 +0900
260 +++ b/storage/innobase/ibuf/ibuf0ibuf.c 2010-12-03 15:10:09.073984282 +0900
262 grow in size, as the references on the upper levels of the tree can
265 - ibuf->max_size = buf_pool_get_curr_size() / UNIV_PAGE_SIZE
266 - / IBUF_POOL_SIZE_PER_MAX_SIZE;
267 + ibuf->max_size = ut_min( buf_pool_get_curr_size() / UNIV_PAGE_SIZE
268 + / IBUF_POOL_SIZE_PER_MAX_SIZE, (ulint) srv_ibuf_max_size / UNIV_PAGE_SIZE);
270 + srv_ibuf_max_size = (long long) ibuf->max_size * UNIV_PAGE_SIZE;
272 mutex_create(ibuf_pessimistic_insert_mutex_key,
273 &ibuf_pessimistic_insert_mutex,
274 @@ -2753,9 +2755,11 @@
276 max_size = ibuf->max_size;
278 + if (!srv_ibuf_active_contract) {
279 if (size < max_size + IBUF_CONTRACT_ON_INSERT_NON_SYNC) {
284 sync = (size >= max_size + IBUF_CONTRACT_ON_INSERT_SYNC);
286 diff -ruN a/storage/innobase/include/buf0rea.h b/storage/innobase/include/buf0rea.h
287 --- a/storage/innobase/include/buf0rea.h 2010-11-03 07:01:13.000000000 +0900
288 +++ b/storage/innobase/include/buf0rea.h 2010-12-03 15:10:09.076066335 +0900
291 /** The size in pages of the area which the read-ahead algorithms read if
293 -#define BUF_READ_AHEAD_AREA(b) \
294 - ut_min(64, ut_2_power_up((b)->curr_size / 32))
295 +#define BUF_READ_AHEAD_AREA(b) 64
297 /** @name Modes used in read-ahead @{ */
298 /** read only pages belonging to the insert buffer tree */
299 diff -ruN a/storage/innobase/include/ha_prototypes.h b/storage/innobase/include/ha_prototypes.h
300 --- a/storage/innobase/include/ha_prototypes.h 2010-11-03 07:01:13.000000000 +0900
301 +++ b/storage/innobase/include/ha_prototypes.h 2010-12-03 15:10:09.078026360 +0900
303 /*===================*/
304 void* thd, /*!< in: thread handle (THD*) */
305 ulint value); /*!< in: time waited for the lock */
306 +/******************************************************************//**
310 +thd_flush_log_at_trx_commit(
311 +/*================================*/
314 /**********************************************************************//**
315 Get the current setting of the lower_case_table_names global parameter from
316 diff -ruN a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h
317 --- a/storage/innobase/include/srv0srv.h 2010-12-03 15:09:51.291955835 +0900
318 +++ b/storage/innobase/include/srv0srv.h 2010-12-03 15:10:09.079029047 +0900
320 extern ulint srv_n_log_files;
321 extern ulint srv_log_file_size;
322 extern ulint srv_log_buffer_size;
323 -extern ulong srv_flush_log_at_trx_commit;
324 +//extern ulong srv_flush_log_at_trx_commit;
325 +extern char srv_use_global_flush_log_at_trx_commit;
326 extern char srv_adaptive_flushing;
330 extern ulong srv_max_purge_lag;
332 extern ulong srv_replication_delay;
334 +extern long long srv_ibuf_max_size;
335 +extern ulint srv_ibuf_active_contract;
336 +extern ulint srv_ibuf_accel_rate;
337 +extern ulint srv_checkpoint_age_target;
338 +extern ulint srv_flush_neighbor_pages;
339 +extern ulint srv_enable_unsafe_group_commit;
340 +extern ulint srv_read_ahead;
341 +extern ulint srv_adaptive_flushing_method;
343 /*-------------------------------------------*/
345 extern ulint srv_n_rows_inserted;
347 when writing data files, but do flush
348 after writing to log files */
349 SRV_UNIX_NOSYNC, /*!< do not flush after writing */
350 - SRV_UNIX_O_DIRECT /*!< invoke os_file_set_nocache() on
351 + SRV_UNIX_O_DIRECT, /*!< invoke os_file_set_nocache() on
353 + SRV_UNIX_ALL_O_DIRECT /* new method for examination: logfile also open O_DIRECT */
356 /** Alternatives for file i/o in Windows */
357 diff -ruN a/storage/innobase/log/log0log.c b/storage/innobase/log/log0log.c
358 --- a/storage/innobase/log/log0log.c 2010-11-03 07:01:13.000000000 +0900
359 +++ b/storage/innobase/log/log0log.c 2010-12-03 15:10:09.084023562 +0900
361 #include "srv0start.h"
364 +#include "ha_prototypes.h"
367 General philosophy of InnoDB redo-logs:
371 /************************************************************//**
375 +log_max_modified_age_async()
377 + if (srv_checkpoint_age_target) {
378 + return(ut_min(log_sys->max_modified_age_async,
379 + srv_checkpoint_age_target
380 + - srv_checkpoint_age_target / 8));
382 + return(log_sys->max_modified_age_async);
388 +log_max_checkpoint_age_async()
390 + if (srv_checkpoint_age_target) {
391 + return(ut_min(log_sys->max_checkpoint_age_async,
392 + srv_checkpoint_age_target));
394 + return(log_sys->max_checkpoint_age_async);
398 +/************************************************************//**
406 - if (checkpoint_age <= log->max_modified_age_async) {
407 + if (checkpoint_age <= log_max_modified_age_async()) {
412 oldest_lsn = buf_pool_get_oldest_modification();
415 - || lsn - oldest_lsn > log->max_modified_age_async
416 - || checkpoint_age > log->max_checkpoint_age_async) {
417 + || lsn - oldest_lsn > log_max_modified_age_async()
418 + || checkpoint_age > log_max_checkpoint_age_async()) {
420 log->check_flush_or_checkpoint = TRUE;
422 @@ -1100,6 +1128,7 @@
423 group = (log_group_t*)((ulint)group - 1);
425 if (srv_unix_file_flush_method != SRV_UNIX_O_DSYNC
426 + && srv_unix_file_flush_method != SRV_UNIX_ALL_O_DIRECT
427 && srv_unix_file_flush_method != SRV_UNIX_NOSYNC) {
429 fil_flush(group->space_id);
430 @@ -1121,8 +1150,9 @@
431 logs and cannot end up here! */
433 if (srv_unix_file_flush_method != SRV_UNIX_O_DSYNC
434 + && srv_unix_file_flush_method != SRV_UNIX_ALL_O_DIRECT
435 && srv_unix_file_flush_method != SRV_UNIX_NOSYNC
436 - && srv_flush_log_at_trx_commit != 2) {
437 + && thd_flush_log_at_trx_commit(NULL) != 2) {
439 fil_flush(group->space_id);
441 @@ -1501,7 +1531,8 @@
443 mutex_exit(&(log_sys->mutex));
445 - if (srv_unix_file_flush_method == SRV_UNIX_O_DSYNC) {
446 + if (srv_unix_file_flush_method == SRV_UNIX_O_DSYNC
447 + || srv_unix_file_flush_method == SRV_UNIX_ALL_O_DIRECT) {
448 /* O_DSYNC means the OS did not buffer the log file at all:
449 so we have also flushed to disk what we have written */
451 @@ -2120,10 +2151,10 @@
454 advance = 2 * (age - log->max_modified_age_sync);
455 - } else if (age > log->max_modified_age_async) {
456 + } else if (age > log_max_modified_age_async()) {
458 /* A flush is not urgent: we do an asynchronous preflush */
459 - advance = age - log->max_modified_age_async;
460 + advance = age - log_max_modified_age_async();
464 @@ -2137,7 +2168,7 @@
466 do_checkpoint = TRUE;
468 - } else if (checkpoint_age > log->max_checkpoint_age_async) {
469 + } else if (checkpoint_age > log_max_checkpoint_age_async()) {
470 /* A checkpoint is not urgent: do it asynchronously */
472 do_checkpoint = TRUE;
473 @@ -3349,6 +3380,17 @@
474 log_sys->flushed_to_disk_lsn,
475 log_sys->last_checkpoint_lsn);
478 + "Max checkpoint age %lu\n"
479 + "Checkpoint age target %lu\n"
480 + "Modified age %lu\n"
481 + "Checkpoint age %lu\n",
482 + (ulong) log_sys->max_checkpoint_age,
483 + (ulong) log_max_checkpoint_age_async(),
484 + (ulong) (log_sys->lsn -
485 + log_buf_pool_get_oldest_modification()),
486 + (ulong) (log_sys->lsn - log_sys->last_checkpoint_lsn));
488 current_time = time(NULL);
490 time_elapsed = 0.001 + difftime(current_time,
491 diff -ruN a/storage/innobase/log/log0recv.c b/storage/innobase/log/log0recv.c
492 --- a/storage/innobase/log/log0recv.c 2010-11-03 07:01:13.000000000 +0900
493 +++ b/storage/innobase/log/log0recv.c 2010-12-03 15:10:09.089024191 +0900
494 @@ -2906,9 +2906,12 @@
495 ib_uint64_t archived_lsn;
496 #endif /* UNIV_LOG_ARCHIVE */
498 - byte log_hdr_buf[LOG_FILE_HDR_SIZE];
500 + byte log_hdr_buf_base[LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE];
503 + log_hdr_buf = ut_align(log_hdr_buf_base, OS_FILE_LOG_BLOCK_SIZE);
505 #ifdef UNIV_LOG_ARCHIVE
506 ut_ad(type != LOG_CHECKPOINT || limit_lsn == IB_ULONGLONG_MAX);
507 /** TRUE when recovering from a checkpoint */
508 diff -ruN a/storage/innobase/os/os0file.c b/storage/innobase/os/os0file.c
509 --- a/storage/innobase/os/os0file.c 2010-11-03 07:01:13.000000000 +0900
510 +++ b/storage/innobase/os/os0file.c 2010-12-03 15:10:09.093023540 +0900
511 @@ -1424,7 +1424,7 @@
513 #ifdef UNIV_NON_BUFFERED_IO
514 # ifndef UNIV_HOTBACKUP
515 - if (type == OS_LOG_FILE && srv_flush_log_at_trx_commit == 2) {
516 + if (type == OS_LOG_FILE && thd_flush_log_at_trx_commit(NULL) == 2) {
517 /* Do not use unbuffered i/o to log files because
518 value 2 denotes that we do not flush the log at every
519 commit, but only once per second */
520 @@ -1440,7 +1440,7 @@
522 #ifdef UNIV_NON_BUFFERED_IO
523 # ifndef UNIV_HOTBACKUP
524 - if (type == OS_LOG_FILE && srv_flush_log_at_trx_commit == 2) {
525 + if (type == OS_LOG_FILE && thd_flush_log_at_trx_commit(NULL) == 2) {
526 /* Do not use unbuffered i/o to log files because
527 value 2 denotes that we do not flush the log at every
528 commit, but only once per second */
529 @@ -1585,6 +1585,11 @@
530 os_file_set_nocache(file, name, mode_str);
533 + /* ALL_O_DIRECT: O_DIRECT also for transaction log file */
534 + if (srv_unix_file_flush_method == SRV_UNIX_ALL_O_DIRECT) {
535 + os_file_set_nocache(file, name, mode_str);
539 if (create_mode != OS_FILE_OPEN_RAW && os_file_lock(file, name)) {
541 diff -ruN a/storage/innobase/srv/srv0srv.c b/storage/innobase/srv/srv0srv.c
542 --- a/storage/innobase/srv/srv0srv.c 2010-12-03 15:09:51.301987792 +0900
543 +++ b/storage/innobase/srv/srv0srv.c 2010-12-03 15:13:29.369986988 +0900
545 UNIV_INTERN ulint srv_log_file_size = ULINT_MAX;
546 /* size in database pages */
547 UNIV_INTERN ulint srv_log_buffer_size = ULINT_MAX;
548 -UNIV_INTERN ulong srv_flush_log_at_trx_commit = 1;
549 +//UNIV_INTERN ulong srv_flush_log_at_trx_commit = 1;
550 +UNIV_INTERN char srv_use_global_flush_log_at_trx_commit = TRUE;
552 /* Try to flush dirty pages so as to avoid IO bursts at
556 UNIV_INTERN ulong srv_replication_delay = 0;
558 +UNIV_INTERN long long srv_ibuf_max_size = 0;
559 +UNIV_INTERN ulint srv_ibuf_active_contract = 0; /* 0:disable 1:enable */
560 +UNIV_INTERN ulint srv_ibuf_accel_rate = 100;
561 +#define PCT_IBUF_IO(pct) ((ulint) (srv_io_capacity * srv_ibuf_accel_rate * ((double) pct / 10000.0)))
563 +UNIV_INTERN ulint srv_checkpoint_age_target = 0;
564 +UNIV_INTERN ulint srv_flush_neighbor_pages = 1; /* 0:disable 1:enable */
566 +UNIV_INTERN ulint srv_enable_unsafe_group_commit = 0; /* 0:disable 1:enable */
567 +UNIV_INTERN ulint srv_read_ahead = 3; /* 1: random 2: linear 3: Both */
568 +UNIV_INTERN ulint srv_adaptive_flushing_method = 0; /* 0: native 1: estimate 2: keep_average */
569 /*-------------------------------------------*/
570 UNIV_INTERN ulong srv_n_spin_wait_rounds = 30;
571 UNIV_INTERN ulong srv_n_free_tickets_to_enter = 500;
572 @@ -2742,6 +2754,7 @@
573 ulint n_pages_purged = 0;
574 ulint n_bytes_merged;
575 ulint n_pages_flushed;
576 + ulint n_pages_flushed_prev = 0;
577 ulint n_bytes_archived;
578 ulint n_tables_to_drop;
580 @@ -2749,7 +2762,20 @@
581 ulint n_ios_very_old;
584 + ulint prev_adaptive_flushing_method = ULINT_UNDEFINED;
585 + ulint inner_loop = 0;
586 + ibool skip_sleep = FALSE;
588 + struct t_prev_flush_info_struct {
591 + unsigned offset:32;
592 + ib_uint64_t oldest_modification;
593 + } prev_flush_info[MAX_BUFFER_POOLS];
595 + ib_uint64_t lsn_old;
597 + ib_uint64_t oldest_lsn;
599 #ifdef UNIV_DEBUG_THREAD_CREATION
600 fprintf(stderr, "Master thread starts, id %lu\n",
601 @@ -2771,6 +2797,9 @@
603 mutex_exit(&kernel_mutex);
605 + mutex_enter(&(log_sys->mutex));
606 + lsn_old = log_sys->lsn;
607 + mutex_exit(&(log_sys->mutex));
609 /*****************************************************************/
610 /* ---- When there is database activity by users, we cycle in this
611 @@ -2801,9 +2830,13 @@
612 /* Sleep for 1 second on entrying the for loop below the first time. */
613 next_itr_time = ut_time_ms() + 1000;
615 + skip_sleep = FALSE;
617 for (i = 0; i < 10; i++) {
618 ulint cur_time = ut_time_ms();
620 + n_pages_flushed = 0; /* initialize */
622 /* ALTER TABLE in MySQL requires on Unix that the table handler
623 can drop tables lazily after there no longer are SELECT
625 @@ -2827,6 +2860,7 @@
626 srv_main_thread_op_info = "sleeping";
627 srv_main_1_second_loops++;
630 if (next_itr_time > cur_time
631 && srv_shutdown_state == SRV_SHUTDOWN_NONE) {
633 @@ -2837,10 +2871,26 @@
634 (next_itr_time - cur_time)
639 + mutex_enter(&(log_sys->mutex));
640 + oldest_lsn = buf_pool_get_oldest_modification();
641 + ib_uint64_t lsn = log_sys->lsn;
642 + mutex_exit(&(log_sys->mutex));
646 + "InnoDB flush: age pct: %lu, lsn progress: %lu\n",
647 + (lsn - oldest_lsn) * 100 / log_sys->max_checkpoint_age,
652 /* Each iteration should happen at 1 second interval. */
653 next_itr_time = ut_time_ms() + 1000;
654 + } /* if (!skip_sleep) */
656 + skip_sleep = FALSE;
658 /* Flush logs if needed */
659 srv_sync_log_buffer_in_background();
660 @@ -2860,7 +2910,7 @@
661 if (n_pend_ios < SRV_PEND_IO_THRESHOLD
662 && (n_ios - n_ios_old < SRV_RECENT_IO_ACTIVITY)) {
663 srv_main_thread_op_info = "doing insert buffer merge";
664 - ibuf_contract_for_n_pages(FALSE, PCT_IO(5));
665 + ibuf_contract_for_n_pages(FALSE, PCT_IBUF_IO(5));
667 /* Flush logs if needed */
668 srv_sync_log_buffer_in_background();
669 @@ -2877,7 +2927,11 @@
670 n_pages_flushed = buf_flush_list(
671 PCT_IO(100), IB_ULONGLONG_MAX);
673 - } else if (srv_adaptive_flushing) {
674 + mutex_enter(&(log_sys->mutex));
675 + lsn_old = log_sys->lsn;
676 + mutex_exit(&(log_sys->mutex));
677 + prev_adaptive_flushing_method = ULINT_UNDEFINED;
678 + } else if (srv_adaptive_flushing && srv_adaptive_flushing_method == 0) {
680 /* Try to keep the rate of flushing of dirty
681 pages such that redo log generation does not
682 @@ -2893,6 +2947,224 @@
687 + mutex_enter(&(log_sys->mutex));
688 + lsn_old = log_sys->lsn;
689 + mutex_exit(&(log_sys->mutex));
690 + prev_adaptive_flushing_method = ULINT_UNDEFINED;
691 + } else if (srv_adaptive_flushing && srv_adaptive_flushing_method == 1) {
693 + /* Try to keep modified age not to exceed
694 + max_checkpoint_age * 7/8 line */
696 + mutex_enter(&(log_sys->mutex));
698 + oldest_lsn = buf_pool_get_oldest_modification();
699 + if (oldest_lsn == 0) {
700 + lsn_old = log_sys->lsn;
701 + mutex_exit(&(log_sys->mutex));
704 + if ((log_sys->lsn - oldest_lsn)
705 + > (log_sys->max_checkpoint_age) - ((log_sys->max_checkpoint_age) / 8)) {
706 + /* LOG_POOL_PREFLUSH_RATIO_ASYNC is exceeded. */
707 + /* We should not flush from here. */
708 + lsn_old = log_sys->lsn;
709 + mutex_exit(&(log_sys->mutex));
710 + } else if ((log_sys->lsn - oldest_lsn)
711 + > (log_sys->max_checkpoint_age)/4 ) {
713 + /* defence line (max_checkpoint_age * 1/2) */
714 + ib_uint64_t lsn = log_sys->lsn;
716 + ib_uint64_t level, bpl;
720 + mutex_exit(&(log_sys->mutex));
724 + for (j = 0; j < srv_buf_pool_instances; j++) {
725 + buf_pool_t* buf_pool;
728 + buf_pool = buf_pool_from_array(j);
730 + /* The scanning flush_list is optimistic here */
734 + bpage = UT_LIST_GET_FIRST(buf_pool->flush_list);
736 + while (bpage != NULL) {
737 + ib_uint64_t oldest_modification = bpage->oldest_modification;
738 + if (oldest_modification != 0) {
739 + level += log_sys->max_checkpoint_age
740 + - (lsn - oldest_modification);
742 + bpage = UT_LIST_GET_NEXT(list, bpage);
747 + bpl += ((ib_uint64_t) n_blocks * n_blocks
748 + * (lsn - lsn_old)) / level;
753 + if (!srv_use_doublewrite_buf) {
754 + /* flush is faster than when doublewrite */
755 + bpl = (bpl * 7) / 8;
760 + n_pages_flushed = buf_flush_list(bpl,
761 + oldest_lsn + (lsn - lsn_old));
762 + if (n_pages_flushed == ULINT_UNDEFINED) {
763 + os_thread_sleep(5000);
764 + goto retry_flush_batch;
771 + "InnoDB flush: age pct: %lu, lsn progress: %lu, blocks to flush:%llu\n",
772 + (lsn - oldest_lsn) * 100 / log_sys->max_checkpoint_age,
773 + lsn - lsn_old, bpl);
776 + lsn_old = log_sys->lsn;
777 + mutex_exit(&(log_sys->mutex));
780 + prev_adaptive_flushing_method = 1;
781 + } else if (srv_adaptive_flushing && srv_adaptive_flushing_method == 2) {
782 + buf_pool_t* buf_pool;
787 + mutex_enter(&(log_sys->mutex));
788 + oldest_lsn = buf_pool_get_oldest_modification();
789 + lsn = log_sys->lsn;
790 + mutex_exit(&(log_sys->mutex));
792 + /* upper loop/sec. (x10) */
793 + next_itr_time -= 900; /* 1000 - 900 == 100 */
795 + if (inner_loop < 10) {
801 + if (prev_adaptive_flushing_method == 2) {
804 + ulint new_blocks_sum, flushed_blocks_sum;
806 + blocks_sum = new_blocks_sum = flushed_blocks_sum = 0;
808 + /* prev_flush_info[j] should be the previous loop's */
809 + for (j = 0; j < srv_buf_pool_instances; j++) {
810 + lint blocks_num, new_blocks_num, flushed_blocks_num;
813 + buf_pool = buf_pool_from_array(j);
815 + blocks_num = UT_LIST_GET_LEN(buf_pool->flush_list);
816 + bpage = UT_LIST_GET_FIRST(buf_pool->flush_list);
817 + new_blocks_num = 0;
820 + while (bpage != NULL) {
821 + if (prev_flush_info[j].space == bpage->space
822 + && prev_flush_info[j].offset == bpage->offset
823 + && prev_flush_info[j].oldest_modification
824 + == bpage->oldest_modification) {
828 + bpage = UT_LIST_GET_NEXT(list, bpage);
832 + new_blocks_num = blocks_num;
835 + flushed_blocks_num = new_blocks_num + prev_flush_info[j].count
837 + if (flushed_blocks_num < 0) {
838 + flushed_blocks_num = 0;
841 + bpage = UT_LIST_GET_FIRST(buf_pool->flush_list);
843 + prev_flush_info[j].count = UT_LIST_GET_LEN(buf_pool->flush_list);
845 + prev_flush_info[j].space = bpage->space;
846 + prev_flush_info[j].offset = bpage->offset;
847 + prev_flush_info[j].oldest_modification = bpage->oldest_modification;
849 + prev_flush_info[j].space = 0;
850 + prev_flush_info[j].offset = 0;
851 + prev_flush_info[j].oldest_modification = 0;
854 + new_blocks_sum += new_blocks_num;
855 + flushed_blocks_sum += flushed_blocks_num;
856 + blocks_sum += blocks_num;
859 + n_flush = blocks_sum * (lsn - lsn_old) / log_sys->max_modified_age_async;
860 + if (flushed_blocks_sum > n_pages_flushed_prev) {
861 + n_flush -= (flushed_blocks_sum - n_pages_flushed_prev);
866 + n_pages_flushed = buf_flush_list(n_flush, oldest_lsn + (lsn - lsn_old));
868 + n_pages_flushed = 0;
871 + /* store previous first pages of the flush_list */
872 + for (j = 0; j < srv_buf_pool_instances; j++) {
873 + buf_pool = buf_pool_from_array(j);
875 + bpage = UT_LIST_GET_FIRST(buf_pool->flush_list);
877 + prev_flush_info[j].count = UT_LIST_GET_LEN(buf_pool->flush_list);
879 + prev_flush_info[j].space = bpage->space;
880 + prev_flush_info[j].offset = bpage->offset;
881 + prev_flush_info[j].oldest_modification = bpage->oldest_modification;
883 + prev_flush_info[j].space = 0;
884 + prev_flush_info[j].offset = 0;
885 + prev_flush_info[j].oldest_modification = 0;
888 + n_pages_flushed = 0;
892 + prev_adaptive_flushing_method = 2;
894 + mutex_enter(&(log_sys->mutex));
895 + lsn_old = log_sys->lsn;
896 + mutex_exit(&(log_sys->mutex));
897 + prev_adaptive_flushing_method = ULINT_UNDEFINED;
900 + if (n_pages_flushed == ULINT_UNDEFINED) {
901 + n_pages_flushed_prev = 0;
903 + n_pages_flushed_prev = n_pages_flushed;
906 if (srv_activity_count == old_activity_count) {
907 @@ -2941,7 +3213,7 @@
908 even if the server were active */
910 srv_main_thread_op_info = "doing insert buffer merge";
911 - ibuf_contract_for_n_pages(FALSE, PCT_IO(5));
912 + ibuf_contract_for_n_pages(FALSE, PCT_IBUF_IO(5));
914 /* Flush logs if needed */
915 srv_sync_log_buffer_in_background();
916 @@ -3049,7 +3321,7 @@
917 buf_flush_list below. Otherwise, the system favors
918 clean pages over cleanup throughput. */
919 n_bytes_merged = ibuf_contract_for_n_pages(FALSE,
924 srv_main_thread_op_info = "reserving kernel mutex";
925 @@ -3189,6 +3461,7 @@
928 ulint n_total_purged = ULINT_UNDEFINED;
929 + ulint next_itr_time;
931 ut_a(srv_n_purge_threads == 1);
933 @@ -3209,9 +3482,12 @@
935 mutex_exit(&kernel_mutex);
937 + next_itr_time = ut_time_ms();
939 while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS) {
941 ulint n_pages_purged = 0;
944 /* If there are very few records to purge or the last
945 purge didn't purge any records then wait for activity.
946 @@ -3258,6 +3534,16 @@
947 } while (n_pages_purged > 0 && !srv_fast_shutdown);
949 srv_sync_log_buffer_in_background();
951 + cur_time = ut_time_ms();
952 + if (next_itr_time > cur_time) {
953 + os_thread_sleep(ut_min(1000000,
954 + (next_itr_time - cur_time)
956 + next_itr_time = ut_time_ms() + 1000;
958 + next_itr_time = cur_time + 1000;
962 mutex_enter(&kernel_mutex);
963 diff -ruN a/storage/innobase/srv/srv0start.c b/storage/innobase/srv/srv0start.c
964 --- a/storage/innobase/srv/srv0start.c 2010-11-03 07:01:13.000000000 +0900
965 +++ b/storage/innobase/srv/srv0start.c 2010-12-03 15:10:09.103023543 +0900
966 @@ -1217,6 +1217,9 @@
967 } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) {
968 srv_unix_file_flush_method = SRV_UNIX_O_DIRECT;
970 + } else if (0 == ut_strcmp(srv_file_flush_method_str, "ALL_O_DIRECT")) {
971 + srv_unix_file_flush_method = SRV_UNIX_ALL_O_DIRECT;
973 } else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) {
974 srv_unix_file_flush_method = SRV_UNIX_LITTLESYNC;
976 diff -ruN a/storage/innobase/trx/trx0purge.c b/storage/innobase/trx/trx0purge.c
977 --- a/storage/innobase/trx/trx0purge.c 2011-04-12 14:14:14.000000000 +0900
978 +++ b/storage/innobase/trx/trx0purge.c 2011-04-12 14:15:44.000000000 +0900
979 @@ -392,10 +392,10 @@
980 trx_sys->rseg_history_len++;
981 mutex_exit(&kernel_mutex);
983 - if (!(trx_sys->rseg_history_len % srv_purge_batch_size)) {
984 +// if (!(trx_sys->rseg_history_len % srv_purge_batch_size)) { /*should wake up always*/
985 /* Inform the purge thread that there is work to do. */
986 srv_wake_purge_thread_if_not_active();
991 /**********************************************************************//**
992 diff -ruN a/storage/innobase/trx/trx0trx.c b/storage/innobase/trx/trx0trx.c
993 --- a/storage/innobase/trx/trx0trx.c 2010-11-03 07:01:13.000000000 +0900
994 +++ b/storage/innobase/trx/trx0trx.c 2010-12-03 15:10:09.106023937 +0900
996 trx->read_view = NULL;
999 + ulint flush_log_at_trx_commit;
1001 mutex_exit(&kernel_mutex);
1003 @@ -992,6 +993,12 @@
1004 trx_undo_insert_cleanup(trx);
1007 + if (srv_use_global_flush_log_at_trx_commit) {
1008 + flush_log_at_trx_commit = thd_flush_log_at_trx_commit(NULL);
1010 + flush_log_at_trx_commit = thd_flush_log_at_trx_commit(trx->mysql_thd);
1013 /* NOTE that we could possibly make a group commit more
1014 efficient here: call os_thread_yield here to allow also other
1015 trxs to come to commit! */
1016 @@ -1023,9 +1030,9 @@
1017 if (trx->flush_log_later) {
1018 /* Do nothing yet */
1019 trx->must_flush_log_later = TRUE;
1020 - } else if (srv_flush_log_at_trx_commit == 0) {
1021 + } else if (flush_log_at_trx_commit == 0) {
1023 - } else if (srv_flush_log_at_trx_commit == 1) {
1024 + } else if (flush_log_at_trx_commit == 1) {
1025 if (srv_unix_file_flush_method == SRV_UNIX_NOSYNC) {
1026 /* Write the log but do not flush it to disk */
1028 @@ -1037,7 +1044,7 @@
1030 log_write_up_to(lsn, LOG_WAIT_ONE_GROUP, TRUE);
1032 - } else if (srv_flush_log_at_trx_commit == 2) {
1033 + } else if (flush_log_at_trx_commit == 2) {
1035 /* Write the log but do not flush it to disk */
1037 @@ -1701,16 +1708,23 @@
1038 trx_t* trx) /*!< in: trx handle */
1040 ib_uint64_t lsn = trx->commit_lsn;
1041 + ulint flush_log_at_trx_commit;
1045 trx->op_info = "flushing log";
1047 + if (srv_use_global_flush_log_at_trx_commit) {
1048 + flush_log_at_trx_commit = thd_flush_log_at_trx_commit(NULL);
1050 + flush_log_at_trx_commit = thd_flush_log_at_trx_commit(trx->mysql_thd);
1053 if (!trx->must_flush_log_later) {
1055 - } else if (srv_flush_log_at_trx_commit == 0) {
1056 + } else if (flush_log_at_trx_commit == 0) {
1058 - } else if (srv_flush_log_at_trx_commit == 1) {
1059 + } else if (flush_log_at_trx_commit == 1) {
1060 if (srv_unix_file_flush_method == SRV_UNIX_NOSYNC) {
1061 /* Write the log but do not flush it to disk */
1063 @@ -1721,7 +1735,7 @@
1065 log_write_up_to(lsn, LOG_WAIT_ONE_GROUP, TRUE);
1067 - } else if (srv_flush_log_at_trx_commit == 2) {
1068 + } else if (flush_log_at_trx_commit == 2) {
1070 /* Write the log but do not flush it to disk */
1072 @@ -1969,6 +1983,8 @@
1073 /*--------------------------------------*/
1076 + ulint flush_log_at_trx_commit;
1078 /* Depending on the my.cnf options, we may now write the log
1079 buffer to the log files, making the prepared state of the
1080 transaction durable if the OS does not crash. We may also
1081 @@ -1988,9 +2004,15 @@
1083 mutex_exit(&kernel_mutex);
1085 - if (srv_flush_log_at_trx_commit == 0) {
1086 + if (srv_use_global_flush_log_at_trx_commit) {
1087 + flush_log_at_trx_commit = thd_flush_log_at_trx_commit(NULL);
1089 + flush_log_at_trx_commit = thd_flush_log_at_trx_commit(trx->mysql_thd);
1092 + if (flush_log_at_trx_commit == 0) {
1094 - } else if (srv_flush_log_at_trx_commit == 1) {
1095 + } else if (flush_log_at_trx_commit == 1) {
1096 if (srv_unix_file_flush_method == SRV_UNIX_NOSYNC) {
1097 /* Write the log but do not flush it to disk */
1099 @@ -2002,7 +2024,7 @@
1101 log_write_up_to(lsn, LOG_WAIT_ONE_GROUP, TRUE);
1103 - } else if (srv_flush_log_at_trx_commit == 2) {
1104 + } else if (flush_log_at_trx_commit == 2) {
1106 /* Write the log but do not flush it to disk */