/* We know that the writes have been flushed to disk now
and in recovery we will find them in the doublewrite buffer
-@@ -1378,7 +1378,7 @@
+@@ -1375,10 +1375,11 @@
+ ulint high;
+ ulint count = 0;
+ buf_pool_t* buf_pool = buf_pool_get(space, offset);
++ ibool is_forward_scan;
ut_ad(flush_type == BUF_FLUSH_LRU || flush_type == BUF_FLUSH_LIST);
/* If there is little space, it is better not to flush
any block except from the end of the LRU list */
+@@ -1405,7 +1406,32 @@
+ high = fil_space_get_size(space);
+ }
+
+- for (i = low; i < high; i++) {
++ if (srv_flush_neighbor_pages == 2) {
++
++ /* In the case of contiguous flush where the requested page
++ does not fall at the start of flush area, first scan backward
++ from the page and later forward from it. */
++ is_forward_scan = (offset == low);
++ }
++ else {
++ is_forward_scan = TRUE;
++ }
++
++scan:
++ if (srv_flush_neighbor_pages == 2) {
++ if (is_forward_scan) {
++ i = offset;
++ }
++ else {
++ i = offset - 1;
++ }
++ }
++ else {
++ i = low;
++ }
++
++ for (; is_forward_scan ? (i < high) : (i >= low);
++ is_forward_scan ? i++ : i--) {
+
+ buf_page_t* bpage;
+
+@@ -1434,6 +1460,12 @@
+ if (!bpage) {
+
+ buf_pool_mutex_exit(buf_pool);
++ if (srv_flush_neighbor_pages == 2) {
++
++ /* This is contiguous neighbor page flush and
++ the pages here are not contiguous. */
++ break;
++ }
+ continue;
+ }
+
+@@ -1470,6 +1502,22 @@
+ }
+ }
+ buf_pool_mutex_exit(buf_pool);
++
++ if (srv_flush_neighbor_pages == 2) {
++
++ /* We are trying to do the contiguous neighbor page
++ flush, but the last page we checked was unflushable,
++ making a "hole" in the flush, so stop this attempt. */
++ break;
++ }
++ }
++
++ if (!is_forward_scan) {
++
++ /* Backward scan done, now do the forward scan */
++ ut_a (srv_flush_neighbor_pages == 2);
++ is_forward_scan = TRUE;
++ goto scan;
+ }
+
+ return(count);
--- a/storage/innobase/buf/buf0rea.c
+++ b/storage/innobase/buf/buf0rea.c
@@ -427,6 +427,10 @@
return(0);
--- a/storage/innobase/fil/fil0fil.c
+++ b/storage/innobase/fil/fil0fil.c
-@@ -2601,7 +2601,7 @@
+@@ -2609,7 +2609,7 @@
os_thread_sleep(20000);
goto retry;
-@@ -2815,7 +2815,7 @@
+@@ -2823,7 +2823,7 @@
goto error_exit;
}
if (!ret) {
fputs("InnoDB: Error: file flush of tablespace ", stderr);
-@@ -3001,7 +3001,7 @@
+@@ -3009,7 +3009,7 @@
}
}
if (!success) {
goto func_exit;
-@@ -3023,7 +3023,7 @@
+@@ -3031,7 +3031,7 @@
goto func_exit;
}
func_exit:
os_file_close(file);
ut_free(buf2);
-@@ -4006,7 +4006,7 @@
+@@ -4014,7 +4014,7 @@
size_after_extend, *actual_size); */
mutex_exit(&fil_system->mutex);
return(success);
}
-@@ -4577,8 +4577,9 @@
+@@ -4585,8 +4585,9 @@
void
fil_flush(
/*======*/
{
fil_space_t* space;
fil_node_t* node;
-@@ -4649,7 +4650,7 @@
+@@ -4657,7 +4658,7 @@
/* fprintf(stderr, "Flushing to file %s\n",
node->name); */
mutex_enter(&fil_system->mutex);
-@@ -4732,7 +4733,7 @@
+@@ -4740,7 +4741,7 @@
a non-existing space id. */
for (i = 0; i < n_space_ids; i++) {
srv_force_recovery = (ulint) innobase_force_recovery;
srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
-@@ -11133,7 +11153,7 @@
+@@ -11141,7 +11161,7 @@
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
"Purge threads can be either 0 or 1.",
NULL, NULL,
0, /* Minimum value */
1, 0); /* Maximum value */
-@@ -11175,12 +11195,18 @@
+@@ -11183,12 +11203,18 @@
innodb_file_format_max_validate,
innodb_file_format_max_update, "Antelope");
static MYSQL_SYSVAR_STR(flush_method, innobase_file_flush_method,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
-@@ -11285,7 +11311,7 @@
+@@ -11293,7 +11319,7 @@
static MYSQL_SYSVAR_LONGLONG(buffer_pool_size, innobase_buffer_pool_size,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
static MYSQL_SYSVAR_LONG(buffer_pool_instances, innobase_buffer_pool_instances,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
-@@ -11442,6 +11468,95 @@
+@@ -11442,6 +11468,127 @@
"trigger a readahead.",
NULL, NULL, 56, 0, 64, 0);
+ "Control soft limit of checkpoint age. (0 : not control)",
+ NULL, NULL, 0, 0, ~0UL, 0);
+
-+static MYSQL_SYSVAR_ULONG(flush_neighbor_pages, srv_flush_neighbor_pages,
-+ PLUGIN_VAR_RQCMDARG,
-+ "Enable/Disable flushing also neighbor pages. 0:disable 1:enable",
-+ NULL, NULL, 1, 0, 1, 0);
++static
++void
++innodb_flush_neighbor_pages_update(
++ THD* thd,
++ struct st_mysql_sys_var* var,
++ void* var_ptr,
++ const void* save)
++{
++ *(long *)var_ptr = (*(long *)save) % 3;
++}
++
++const char *flush_neighbor_pages_names[]=
++{
++ "none", /* 0 */
++ "area",
++ "cont", /* 2 */
++ /* For compatibility with the older patch */
++ "0", /* "none" + 3 */
++ "1", /* "area" + 3 */
++ "2", /* "cont" + 3 */
++ NullS
++};
++
++TYPELIB flush_neighbor_pages_typelib=
++{
++ array_elements(flush_neighbor_pages_names) - 1,
++ "flush_neighbor_pages_typelib",
++ flush_neighbor_pages_names,
++ NULL
++};
++
++static MYSQL_SYSVAR_ENUM(flush_neighbor_pages, srv_flush_neighbor_pages,
++ PLUGIN_VAR_RQCMDARG, "Neighbor page flushing behaviour: none: do not flush, "
++ "[area]: flush selected pages one-by-one, "
++ "cont: flush a contiguous block of pages", NULL,
++ innodb_flush_neighbor_pages_update, 1, &flush_neighbor_pages_typelib);
+
+static
+void
static struct st_mysql_sys_var* innobase_system_variables[]= {
MYSQL_SYSVAR(additional_mem_pool_size),
MYSQL_SYSVAR(autoextend_increment),
-@@ -11462,6 +11577,7 @@
+@@ -11462,6 +11609,7 @@
MYSQL_SYSVAR(file_format_check),
MYSQL_SYSVAR(file_format_max),
MYSQL_SYSVAR(flush_log_at_trx_commit),
MYSQL_SYSVAR(flush_method),
MYSQL_SYSVAR(force_recovery),
MYSQL_SYSVAR(large_prefix),
-@@ -11501,6 +11617,13 @@
+@@ -11501,6 +11649,13 @@
MYSQL_SYSVAR(show_verbose_locks),
MYSQL_SYSVAR(show_locks_held),
MYSQL_SYSVAR(version),
MYSQL_SYSVAR(change_buffering),
--- a/storage/innobase/ibuf/ibuf0ibuf.c
+++ b/storage/innobase/ibuf/ibuf0ibuf.c
-@@ -514,8 +514,10 @@
+@@ -523,8 +523,10 @@
grow in size, as the references on the upper levels of the tree can
change */
mutex_create(ibuf_pessimistic_insert_mutex_key,
&ibuf_pessimistic_insert_mutex,
-@@ -2753,9 +2755,11 @@
+@@ -2763,9 +2765,11 @@
size = ibuf->size;
max_size = ibuf->max_size;
/** read only pages belonging to the insert buffer tree */
--- a/storage/innobase/include/fil0fil.h
+++ b/storage/innobase/include/fil0fil.h
-@@ -658,8 +658,9 @@
+@@ -663,8 +663,9 @@
void
fil_flush(
/*======*/
+#define PCT_IBUF_IO(pct) ((ulint) (srv_io_capacity * srv_ibuf_accel_rate * ((double) pct / 10000.0)))
+
+UNIV_INTERN ulint srv_checkpoint_age_target = 0;
-+UNIV_INTERN ulint srv_flush_neighbor_pages = 1; /* 0:disable 1:enable */
++UNIV_INTERN ulint srv_flush_neighbor_pages = 1; /* 0:disable 1:area 2:contiguous */
+
+UNIV_INTERN ulint srv_enable_unsafe_group_commit = 0; /* 0:disable 1:enable */
+UNIV_INTERN ulint srv_read_ahead = 3; /* 1: random 2: linear 3: Both */
mutex_enter(&kernel_mutex);
--- a/storage/innobase/srv/srv0start.c
+++ b/storage/innobase/srv/srv0start.c
-@@ -1217,6 +1217,9 @@
+@@ -1237,6 +1237,9 @@
} else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) {
srv_unix_file_flush_method = SRV_UNIX_O_DIRECT;
/* Write the log but do not flush it to disk */
+--- a/mysql-test/include/default_mysqld.cnf
++++ b/mysql-test/include/default_mysqld.cnf
+@@ -29,7 +29,7 @@
+ max_heap_table_size= 1M
+
+ loose-innodb_data_file_path= ibdata1:10M:autoextend
+-loose-innodb_buffer_pool_size= 8M
++loose-innodb_buffer_pool_size= 32M
+ loose-innodb_write_io_threads= 2
+ loose-innodb_read_io_threads= 2
+ loose-innodb_log_buffer_size= 1M
+--- a/mysql-test/suite/innodb/r/innodb.result
++++ b/mysql-test/suite/innodb/r/innodb.result
+@@ -1678,7 +1678,7 @@
+ drop table t1;
+ SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_buffer_pool_pages_total';
+ variable_value
+-511
++2047
+ SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_page_size';
+ variable_value
+ 16384
+--- /dev/null
++++ b/mysql-test/suite/innodb/r/percona_flush_contiguous_neighbors.result
+@@ -0,0 +1,21 @@
++DROP TABLE IF EXISTS t1;
++CREATE TABLE t1 (id INT AUTO_INCREMENT, foo CHAR(255), PRIMARY KEY (id)) ENGINE=InnoDB;
++INSERT INTO t1(foo) VALUES ('a'), ('b');
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++DROP TABLE t1;
+--- /dev/null
++++ b/mysql-test/suite/innodb/t/percona_flush_contiguous_neighbors-master.opt
+@@ -0,0 +1 @@
++--innodb_flush_neighbor_pages=cont
+--- /dev/null
++++ b/mysql-test/suite/innodb/t/percona_flush_contiguous_neighbors.test
+@@ -0,0 +1,36 @@
++# Test for innodb_flush_neighbor_pages=contiguous.
++# The test is very crude: we simply overflow the buffer pool with such a number of
++# new/modified pages that some flushing is bound to happen.
++
++--source include/have_innodb.inc
++
++--disable_warnings
++DROP TABLE IF EXISTS t1;
++--enable_warnings
++
++CREATE TABLE t1 (id INT AUTO_INCREMENT, foo CHAR(255), PRIMARY KEY (id)) ENGINE=InnoDB;
++
++INSERT INTO t1(foo) VALUES ('a'), ('b');
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++INSERT INTO t1(foo) SELECT foo FROM t1;
++
++# TODO: cannot record a stable value here. A check of > 0 should be enough,
++# but the variable is not accessible through INFORMATION_SCHEMA currently.
++# SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_pages_flushed';
++
++DROP TABLE t1;
+--- a/mysql-test/suite/innodb/t/innodb_cmp_drop_table-master.opt
++++ b/mysql-test/suite/innodb/t/innodb_cmp_drop_table-master.opt
+@@ -1 +1 @@
+---innodb-buffer-pool-size=8M
++--innodb-buffer-pool-size=32M
+--- a/mysql-test/suite/innodb/t/innodb_cmp_drop_table.test
++++ b/mysql-test/suite/innodb/t/innodb_cmp_drop_table.test
+@@ -36,13 +36,14 @@
+
+ -- disable_query_log
+
+--- let $i = 400
++-- let $i = 4000
++begin;
+ while ($i)
+ {
+ insert into t2 values(repeat('abcdefghijklmnopqrstuvwxyz',1000));
+ dec $i;
+ }
+-
++commit;
+ -- enable_query_log
+
+ # now there should be no 8K pages in the buffer pool