Skip to content

Commit 2bf3e41

Browse files
author
Jan Lindström
committed
MDEV-6932: Enable Lazy Flushing
Merge Facebook commit 4f3e0343fd2ac3fc7311d0ec9739a8f668274f0d authored by Steaphan Greene from https://github.com/facebook/mysql-5.6 Adds innodb_idle_flush_pct to enable tuning of the page flushing rate when the system is relatively idle. We care about this, since doing extra unnecessary flash writes shortens the lifespan of the flash.
1 parent 58888e2 commit 2bf3e41

File tree

11 files changed

+189
-22
lines changed

11 files changed

+189
-22
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
SET @start_global_value = @@global.innodb_idle_flush_pct;
2+
SELECT @start_global_value;
3+
@start_global_value
4+
100
5+
Valid values are between 0 and 100
6+
select @@global.innodb_idle_flush_pct between 0 and 100;
7+
@@global.innodb_idle_flush_pct between 0 and 100
8+
1
9+
select @@global.innodb_idle_flush_pct;
10+
@@global.innodb_idle_flush_pct
11+
100
12+
select @@session.innodb_idle_flush_pct;
13+
ERROR HY000: Variable 'innodb_idle_flush_pct' is a GLOBAL variable
14+
show global variables like 'innodb_idle_flush_pct';
15+
Variable_name Value
16+
innodb_idle_flush_pct 100
17+
show session variables like 'innodb_idle_flush_pct';
18+
Variable_name Value
19+
innodb_idle_flush_pct 100
20+
select * from information_schema.global_variables where variable_name='innodb_idle_flush_pct';
21+
VARIABLE_NAME VARIABLE_VALUE
22+
INNODB_IDLE_FLUSH_PCT 100
23+
select * from information_schema.session_variables where variable_name='innodb_idle_flush_pct';
24+
VARIABLE_NAME VARIABLE_VALUE
25+
INNODB_IDLE_FLUSH_PCT 100
26+
set global innodb_idle_flush_pct=10;
27+
select @@global.innodb_idle_flush_pct;
28+
@@global.innodb_idle_flush_pct
29+
10
30+
select * from information_schema.global_variables where variable_name='innodb_idle_flush_pct';
31+
VARIABLE_NAME VARIABLE_VALUE
32+
INNODB_IDLE_FLUSH_PCT 10
33+
select * from information_schema.session_variables where variable_name='innodb_idle_flush_pct';
34+
VARIABLE_NAME VARIABLE_VALUE
35+
INNODB_IDLE_FLUSH_PCT 10
36+
set session innodb_idle_flush_pct=1;
37+
ERROR HY000: Variable 'innodb_idle_flush_pct' is a GLOBAL variable and should be set with SET GLOBAL
38+
set global innodb_idle_flush_pct=1.1;
39+
ERROR 42000: Incorrect argument type to variable 'innodb_idle_flush_pct'
40+
set global innodb_idle_flush_pct=1e1;
41+
ERROR 42000: Incorrect argument type to variable 'innodb_idle_flush_pct'
42+
set global innodb_idle_flush_pct="bar";
43+
ERROR 42000: Incorrect argument type to variable 'innodb_idle_flush_pct'
44+
set global innodb_idle_flush_pct=-7;
45+
Warnings:
46+
Warning 1292 Truncated incorrect innodb_idle_flush_pct value: '-7'
47+
select @@global.innodb_idle_flush_pct;
48+
@@global.innodb_idle_flush_pct
49+
0
50+
select * from information_schema.global_variables where variable_name='innodb_idle_flush_pct';
51+
VARIABLE_NAME VARIABLE_VALUE
52+
INNODB_IDLE_FLUSH_PCT 0
53+
set global innodb_idle_flush_pct=106;
54+
Warnings:
55+
Warning 1292 Truncated incorrect innodb_idle_flush_pct value: '106'
56+
select @@global.innodb_idle_flush_pct;
57+
@@global.innodb_idle_flush_pct
58+
100
59+
select * from information_schema.global_variables where variable_name='innodb_idle_flush_pct';
60+
VARIABLE_NAME VARIABLE_VALUE
61+
INNODB_IDLE_FLUSH_PCT 100
62+
set global innodb_idle_flush_pct=0;
63+
select @@global.innodb_idle_flush_pct;
64+
@@global.innodb_idle_flush_pct
65+
0
66+
set global innodb_idle_flush_pct=100;
67+
select @@global.innodb_idle_flush_pct;
68+
@@global.innodb_idle_flush_pct
69+
100
70+
set global innodb_idle_flush_pct=DEFAULT;
71+
select @@global.innodb_idle_flush_pct;
72+
@@global.innodb_idle_flush_pct
73+
100
74+
SET @@global.innodb_idle_flush_pct = @start_global_value;
75+
SELECT @@global.innodb_idle_flush_pct;
76+
@@global.innodb_idle_flush_pct
77+
100

mysql-test/suite/sys_vars/r/sysvars_innodb.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,20 @@ NUMERIC_BLOCK_SIZE NULL
10271027
ENUM_VALUE_LIST NULL
10281028
READ_ONLY NO
10291029
COMMAND_LINE_ARGUMENT OPTIONAL
1030+
VARIABLE_NAME INNODB_IDLE_FLUSH_PCT
1031+
SESSION_VALUE NULL
1032+
GLOBAL_VALUE 100
1033+
GLOBAL_VALUE_ORIGIN COMPILE-TIME
1034+
DEFAULT_VALUE 100
1035+
VARIABLE_SCOPE GLOBAL
1036+
VARIABLE_TYPE BIGINT UNSIGNED
1037+
VARIABLE_COMMENT Up to what percentage of dirty pages should be flushed when innodb finds it has spare resources to do so.
1038+
NUMERIC_MIN_VALUE 0
1039+
NUMERIC_MAX_VALUE 100
1040+
NUMERIC_BLOCK_SIZE 0
1041+
ENUM_VALUE_LIST NULL
1042+
READ_ONLY NO
1043+
COMMAND_LINE_ARGUMENT REQUIRED
10301044
VARIABLE_NAME INNODB_IO_CAPACITY
10311045
SESSION_VALUE NULL
10321046
GLOBAL_VALUE 200
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
#
3+
# 2013-04-01 - Added
4+
#
5+
6+
--source include/have_innodb.inc
7+
8+
SET @start_global_value = @@global.innodb_idle_flush_pct;
9+
SELECT @start_global_value;
10+
11+
#
12+
# exists as global only
13+
#
14+
--echo Valid values are between 0 and 100
15+
select @@global.innodb_idle_flush_pct between 0 and 100;
16+
select @@global.innodb_idle_flush_pct;
17+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
18+
select @@session.innodb_idle_flush_pct;
19+
show global variables like 'innodb_idle_flush_pct';
20+
show session variables like 'innodb_idle_flush_pct';
21+
select * from information_schema.global_variables where variable_name='innodb_idle_flush_pct';
22+
select * from information_schema.session_variables where variable_name='innodb_idle_flush_pct';
23+
24+
#
25+
# show that it's writable
26+
#
27+
set global innodb_idle_flush_pct=10;
28+
select @@global.innodb_idle_flush_pct;
29+
select * from information_schema.global_variables where variable_name='innodb_idle_flush_pct';
30+
select * from information_schema.session_variables where variable_name='innodb_idle_flush_pct';
31+
--error ER_GLOBAL_VARIABLE
32+
set session innodb_idle_flush_pct=1;
33+
34+
#
35+
# incorrect types
36+
#
37+
--error ER_WRONG_TYPE_FOR_VAR
38+
set global innodb_idle_flush_pct=1.1;
39+
--error ER_WRONG_TYPE_FOR_VAR
40+
set global innodb_idle_flush_pct=1e1;
41+
--error ER_WRONG_TYPE_FOR_VAR
42+
set global innodb_idle_flush_pct="bar";
43+
44+
set global innodb_idle_flush_pct=-7;
45+
select @@global.innodb_idle_flush_pct;
46+
select * from information_schema.global_variables where variable_name='innodb_idle_flush_pct';
47+
set global innodb_idle_flush_pct=106;
48+
select @@global.innodb_idle_flush_pct;
49+
select * from information_schema.global_variables where variable_name='innodb_idle_flush_pct';
50+
51+
#
52+
# min/max/DEFAULT values
53+
#
54+
set global innodb_idle_flush_pct=0;
55+
select @@global.innodb_idle_flush_pct;
56+
set global innodb_idle_flush_pct=100;
57+
select @@global.innodb_idle_flush_pct;
58+
set global innodb_idle_flush_pct=DEFAULT;
59+
select @@global.innodb_idle_flush_pct;
60+
61+
62+
SET @@global.innodb_idle_flush_pct = @start_global_value;
63+
SELECT @@global.innodb_idle_flush_pct;

storage/innobase/buf/buf0flu.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,27 +2444,17 @@ DECLARE_THREAD(buf_flush_page_cleaner_thread)(
24442444

24452445
while (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
24462446

2447-
/* The page_cleaner skips sleep if the server is
2448-
idle and there are no pending IOs in the buffer pool
2449-
and there is work to do. */
2450-
if (srv_check_activity(last_activity)
2451-
|| buf_get_n_pending_read_ios()
2452-
|| n_flushed == 0) {
2453-
page_cleaner_sleep_if_needed(next_loop_time);
2454-
}
2447+
page_cleaner_sleep_if_needed(next_loop_time);
24552448

24562449
next_loop_time = ut_time_ms() + 1000;
24572450

24582451
if (srv_check_activity(last_activity)) {
24592452
last_activity = srv_get_activity_count();
24602453

2461-
/* Flush pages from end of LRU if required */
2462-
n_flushed = buf_flush_LRU_tail();
2463-
24642454
/* Flush pages from flush_list if required */
24652455
n_flushed += page_cleaner_flush_pages_if_needed();
24662456

2467-
} else {
2457+
} else if (srv_idle_flush_pct) {
24682458
n_flushed = page_cleaner_do_flush_batch(
24692459
PCT_IO(100),
24702460
LSN_MAX);
@@ -2477,6 +2467,9 @@ DECLARE_THREAD(buf_flush_page_cleaner_thread)(
24772467
n_flushed);
24782468
}
24792469
}
2470+
2471+
/* Flush pages from end of LRU if required */
2472+
buf_flush_LRU_tail();
24802473
}
24812474

24822475
ut_ad(srv_shutdown_state > 0);

storage/innobase/handler/ha_innodb.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17891,6 +17891,13 @@ static MYSQL_SYSVAR_ULONG(io_capacity_max, srv_max_io_capacity,
1789117891
SRV_MAX_IO_CAPACITY_DUMMY_DEFAULT, 100,
1789217892
SRV_MAX_IO_CAPACITY_LIMIT, 0);
1789317893

17894+
static MYSQL_SYSVAR_ULONG(idle_flush_pct,
17895+
srv_idle_flush_pct,
17896+
PLUGIN_VAR_RQCMDARG,
17897+
"Up to what percentage of dirty pages should be flushed when innodb "
17898+
"finds it has spare resources to do so.",
17899+
NULL, NULL, 100, 0, 100, 0);
17900+
1789417901
#ifdef UNIV_DEBUG
1789517902
static MYSQL_SYSVAR_BOOL(purge_run_now, innodb_purge_run_now,
1789617903
PLUGIN_VAR_OPCMDARG,
@@ -18920,6 +18927,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
1892018927
MYSQL_SYSVAR(read_only),
1892118928
MYSQL_SYSVAR(io_capacity),
1892218929
MYSQL_SYSVAR(io_capacity_max),
18930+
MYSQL_SYSVAR(idle_flush_pct),
1892318931
MYSQL_SYSVAR(monitor_enable),
1892418932
MYSQL_SYSVAR(monitor_disable),
1892518933
MYSQL_SYSVAR(monitor_reset),

storage/innobase/include/srv0srv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ extern double srv_defragment_fill_factor;
359359
extern uint srv_defragment_frequency;
360360
extern ulonglong srv_defragment_interval;
361361

362+
extern ulint srv_idle_flush_pct;
363+
362364
/* Number of IO operations per second the server can do */
363365
extern ulong srv_io_capacity;
364366

storage/innobase/srv/srv0srv.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ UNIV_INTERN ulint srv_buf_pool_curr_size = 0;
257257
UNIV_INTERN ulint srv_mem_pool_size = ULINT_MAX;
258258
UNIV_INTERN ulint srv_lock_table_size = ULINT_MAX;
259259

260+
UNIV_INTERN ulint srv_idle_flush_pct = 100;
261+
260262
/* This parameter is deprecated. Use srv_n_io_[read|write]_threads
261263
instead. */
262264
UNIV_INTERN ulint srv_n_file_io_threads = ULINT_MAX;

storage/xtradb/buf/buf0flu.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,14 +2736,7 @@ DECLARE_THREAD(buf_flush_page_cleaner_thread)(
27362736

27372737
srv_current_thread_priority = srv_cleaner_thread_priority;
27382738

2739-
/* The page_cleaner skips sleep if the server is
2740-
idle and there are no pending IOs in the buffer pool
2741-
and there is work to do. */
2742-
if (srv_check_activity(last_activity)
2743-
|| buf_get_n_pending_read_ios()
2744-
|| n_flushed == 0) {
2745-
page_cleaner_sleep_if_needed(next_loop_time);
2746-
}
2739+
page_cleaner_sleep_if_needed(next_loop_time);
27472740

27482741
page_cleaner_sleep_time
27492742
= page_cleaner_adapt_flush_sleep_time();
@@ -2761,8 +2754,8 @@ DECLARE_THREAD(buf_flush_page_cleaner_thread)(
27612754
}
27622755

27632756
/* Flush pages from flush_list if required */
2764-
n_flushed += page_cleaner_flush_pages_if_needed();
2765-
} else {
2757+
page_cleaner_flush_pages_if_needed();
2758+
} else if (srv_idle_flush_pct) {
27662759
n_flushed = page_cleaner_do_flush_batch(
27672760
PCT_IO(100),
27682761
LSN_MAX);
@@ -2775,6 +2768,9 @@ DECLARE_THREAD(buf_flush_page_cleaner_thread)(
27752768
n_flushed);
27762769
}
27772770
}
2771+
2772+
/* Flush pages from end of LRU if required */
2773+
buf_flush_LRU_tail();
27782774
}
27792775

27802776
ut_ad(srv_shutdown_state > 0);

storage/xtradb/handler/ha_innodb.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18970,6 +18970,13 @@ static MYSQL_SYSVAR_ULONG(io_capacity_max, srv_max_io_capacity,
1897018970
SRV_MAX_IO_CAPACITY_DUMMY_DEFAULT, 100,
1897118971
SRV_MAX_IO_CAPACITY_LIMIT, 0);
1897218972

18973+
static MYSQL_SYSVAR_ULONG(idle_flush_pct,
18974+
srv_idle_flush_pct,
18975+
PLUGIN_VAR_RQCMDARG,
18976+
"Up to what percentage of dirty pages should be flushed when innodb "
18977+
"finds it has spare resources to do so.",
18978+
NULL, NULL, 100, 0, 100, 0);
18979+
1897318980
#ifdef UNIV_DEBUG
1897418981
static MYSQL_SYSVAR_BOOL(purge_run_now, innodb_purge_run_now,
1897518982
PLUGIN_VAR_OPCMDARG,
@@ -20224,6 +20231,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
2022420231
MYSQL_SYSVAR(read_only),
2022520232
MYSQL_SYSVAR(io_capacity),
2022620233
MYSQL_SYSVAR(io_capacity_max),
20234+
MYSQL_SYSVAR(idle_flush_pct),
2022720235
MYSQL_SYSVAR(monitor_enable),
2022820236
MYSQL_SYSVAR(monitor_disable),
2022920237
MYSQL_SYSVAR(monitor_reset),

storage/xtradb/include/srv0srv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ extern double srv_defragment_fill_factor;
424424
extern uint srv_defragment_frequency;
425425
extern ulonglong srv_defragment_interval;
426426

427+
extern ulint srv_idle_flush_pct;
428+
427429
/* Number of IO operations per second the server can do */
428430
extern ulong srv_io_capacity;
429431

0 commit comments

Comments
 (0)