Skip to content

Commit

Permalink
Bug #32965326 OUT OF THREAD STACK IN CREATEITERATORFROMACCESSPATH (AG…
Browse files Browse the repository at this point in the history
…AIN)

The patch for
Bug #32934187: HYPERGRAPH: CRASHING IN ITEM_IN_SUBSELECT::EXEC
increased stack usage for CreateIteratorFromAccessPath()
and we have queries which run out of stack space when building with
clang debug and no optimization.

The fix is to increase the value of DEFAULT_THREAD_STACK, and pick a
value which works for all mtr tests and for all known/supported
compilers.  This also simplifies handling of the system variable
"thread_stack", and several -master.opt files of mtr can be removed.

For two test cases, we add a -master.opt file, keeping the old value
for thread_stack, since the test cases are flaky (different behaviour
for different values provided, and actual stack space used).

Previous default value for thread_stack was 280K for most platforms.
New default value is 1M for all platforms.

Change-Id: I101c3959e831bd85ef11dd8ac82ed4c00da1cdb0
  • Loading branch information
Tor Didriksen committed Jun 9, 2021
1 parent fcf00ae commit 907e8ab
Show file tree
Hide file tree
Showing 39 changed files with 27 additions and 63 deletions.
20 changes: 5 additions & 15 deletions include/my_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,11 @@
#define ETIMEDOUT 145 /* Win32 doesn't have this */
#endif

#if defined(__sparc) && (defined(__SUNPRO_CC) || defined(__SUNPRO_C))
#define STACK_MULTIPLIER 2UL
#elif defined HAVE_UBSAN
#define STACK_MULTIPLIER 3UL
#elif defined(HAVE_LSAN) || defined(HAVE_ASAN)
#define STACK_MULTIPLIER 4UL
#else
#define STACK_MULTIPLIER 1UL
#endif

#if SIZEOF_CHARP > 4
#define DEFAULT_THREAD_STACK (STACK_MULTIPLIER * 280UL * 1024UL)
#else
#define DEFAULT_THREAD_STACK (STACK_MULTIPLIER * 216UL * 1024UL)
#endif
// Pick a value which is enough for all mtr tests,
// on all known/supported platforms.
// Currently the largest stack requirement is with
// clang with DEBUG and UBSAN -O0 -fno-inline
#define DEFAULT_THREAD_STACK (1024UL * 1024UL)

static inline int is_timeout(int e) {
#if ETIMEDOUT == ETIME
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/mysqld--help-notwin.result
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,7 @@ temptable-use-mmap TRUE
terminology-use-previous NONE
thread-cache-size 9
thread-handling one-thread-per-connection
thread-stack 262144
thread-stack 1048576
tls-ciphersuites (No default value)
tmp-table-size 16777216
transaction-alloc-block-size 8192
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/mysqld--help-win.result
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ temptable-use-mmap TRUE
terminology-use-previous NONE
thread-cache-size 9
thread-handling one-thread-per-connection
thread-stack 262144
thread-stack 1048576
tls-ciphersuites (No default value)
tmp-table-size 16777216
transaction-alloc-block-size 8192
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion mysql-test/suite/binlog_nogtid/t/binlog_unsafe-master.opt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
$UDF_EXAMPLE_LIB_OPT --log-output=file,table --thread-stack=512K
$UDF_EXAMPLE_LIB_OPT --log-output=file,table
Original file line number Diff line number Diff line change
@@ -1 +1 @@
$UDF_EXAMPLE_LIB_OPT --thread-stack=512K
$UDF_EXAMPLE_LIB_OPT
1 change: 0 additions & 1 deletion mysql-test/suite/perfschema/t/max_program_zero-master.opt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--loose-performance_schema_max_program_instances=0
--loose-performance_schema_max_statement_stack=1
--thread_stack=655360
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--thread_stack=655360
--max_digest_length=10
--loose-performance_schema_max_sql_text_length=10
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--thread_stack=655360
--max_digest_length=0
--loose-performance_schema_max_sql_text_length=0

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
--innodb_lock_wait_timeout=1 --thread_stack=655360
--innodb_lock_wait_timeout=1
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--loose-performance_schema_max_program_instances=7
--loose-performance_schema_max_statement_stack=2
--thread_stack=655360
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# These additional stored programs which will be added might cause
# result content mismatch failure.

# clang/UBSAN needs to override the small thread stack in our -master.opt
--disable_query_log
call mtr.add_suppression("option 'thread_stack':");
--enable_query_log

let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect;
--exec echo "wait" > $restart_file
--shutdown_server
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion mysql-test/suite/rpl/t/rpl_parallel_multi_db-master.opt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--thread_stack=512K --log-error-verbosity=1
--log-error-verbosity=1
1 change: 0 additions & 1 deletion mysql-test/suite/rpl/t/rpl_row_sp011-master.opt

This file was deleted.

10 changes: 5 additions & 5 deletions mysql-test/suite/sys_vars/r/thread_stack_basic.result
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
select @@global.thread_stack;
@@global.thread_stack
262144
1048576
select @@session.thread_stack;
ERROR HY000: Variable 'thread_stack' is a GLOBAL variable
show global variables like 'thread_stack';
Variable_name Value
thread_stack 262144
thread_stack 1048576
show session variables like 'thread_stack';
Variable_name Value
thread_stack 262144
thread_stack 1048576
select * from performance_schema.global_variables where variable_name='thread_stack';
VARIABLE_NAME VARIABLE_VALUE
thread_stack 262144
thread_stack 1048576
select * from performance_schema.session_variables where variable_name='thread_stack';
VARIABLE_NAME VARIABLE_VALUE
thread_stack 262144
thread_stack 1048576
set global thread_stack=1;
ERROR HY000: Variable 'thread_stack' is a read only variable
set session thread_stack=1;
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions mysql-test/suite/sys_vars/t/thread_stack_basic.test
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#
# only global
#
--replace_result 196608 262144 393216 262144 524288 262144 286720 262144 573440 262144 221184 262144 860160 262144 1146880 262144
select @@global.thread_stack;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
select @@session.thread_stack;
--replace_result 196608 262144 393216 262144 524288 262144 286720 262144 573440 262144 221184 262144 860160 262144 1146880 262144
show global variables like 'thread_stack';
--replace_result 196608 262144 393216 262144 524288 262144 286720 262144 573440 262144 221184 262144 860160 262144 1146880 262144
show session variables like 'thread_stack';
--disable_warnings
--replace_result 196608 262144 393216 262144 524288 262144 286720 262144 573440 262144 221184 262144 860160 262144 1146880 262144
select * from performance_schema.global_variables where variable_name='thread_stack';
--replace_result 196608 262144 393216 262144 524288 262144 286720 262144 573440 262144 221184 262144 860160 262144 1146880 262144
select * from performance_schema.session_variables where variable_name='thread_stack';
--enable_warnings

Expand Down
1 change: 0 additions & 1 deletion mysql-test/suite/sysschema/t/pr_diagnostics-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/suite/x/t/notices_disable-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/suite/x/t/notices_enable-master.opt

This file was deleted.

3 changes: 1 addition & 2 deletions mysql-test/t/partition-master.opt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--thread-stack=524288
--innodb-directories=$MYSQL_TMP_DIR
--innodb-directories=$MYSQL_TMP_DIR
1 change: 0 additions & 1 deletion mysql-test/t/ps_ddl-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/ps_ddl_myisam-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/signal_demo3-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/sp-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/subquery_sj_all-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/subquery_sj_all_bka-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/subquery_sj_all_bka_nobnl-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/subquery_sj_dupsweed-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/subquery_sj_dupsweed_bka-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/subquery_sj_dupsweed_bka_nobnl-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/subquery_sj_firstmatch-master.opt

This file was deleted.

1 change: 0 additions & 1 deletion mysql-test/t/subquery_sj_firstmatch_bka-master.opt

This file was deleted.

4 changes: 3 additions & 1 deletion sql/sp_head.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2021,12 +2021,14 @@ bool sp_head::execute(THD *thd, bool merge_da_on_success) {
Stack size depends on the platform:
- for most platforms (8 * STACK_MIN_SIZE) is enough;
- for Solaris SPARC 64 (10 * STACK_MIN_SIZE) is required.
- for clang and UBSAN we need even more stack space.
- for clang and ASAN/UBSAN we need even more stack space.
*/

{
#if defined(__sparc) && defined(__SUNPRO_CC)
const int sp_stack_size = 10 * STACK_MIN_SIZE;
#elif defined(__clang__) && defined(HAVE_ASAN)
const int sp_stack_size = 12 * STACK_MIN_SIZE;
#elif defined(__clang__) && defined(HAVE_UBSAN)
const int sp_stack_size = 16 * STACK_MIN_SIZE;
#else
Expand Down
5 changes: 2 additions & 3 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3699,9 +3699,8 @@ static Sys_var_ulong Sys_thread_stack(
"thread_stack", "The stack size for each thread",
READ_ONLY GLOBAL_VAR(my_thread_stack_size), CMD_LINE(REQUIRED_ARG),
#if defined(__clang__) && defined(HAVE_UBSAN)
// DEFAULT_THREAD_STACK is multiplied by 3 for clang/UBSAN
// We need to increase the minimum value as well.
VALID_RANGE(DEFAULT_THREAD_STACK / 2, ULONG_MAX),
// Clang with DEBUG needs more stack, esp. with UBSAN.
VALID_RANGE(DEFAULT_THREAD_STACK, ULONG_MAX),
#else
VALID_RANGE(128 * 1024, ULONG_MAX),
#endif
Expand Down

0 comments on commit 907e8ab

Please sign in to comment.