diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-04-17 10:49:07 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-04-17 10:54:56 +0300 |
commit | 7198c6ab2dc8f8286f6732824ab985a76ebaaddc (patch) | |
tree | e8e363c5bd24322498f2c8c8c15aa620a5128a37 /sql/wsrep_mysqld.h | |
parent | 18656797de2c10f7539f99b257cdf093056d9ad9 (diff) | |
download | mariadb-git-7198c6ab2dc8f8286f6732824ab985a76ebaaddc.tar.gz |
MDEV-22271 Excessive stack memory usage due to WSREP_LOG
Several tests that involve stored procedures fail on 10.4 kvm-asan
(clang 10) due to stack overrun. The main contributor to this stack
overrun is mysql_execute_command(), which is invoked recursively
during stored procedure execution.
Rebuilding with cmake -DWITH_WSREP=OFF shrunk the stack frame size
of mysql_execute_command() by more than 10 kilobytes in a
WITH_ASAN=ON, CMAKE_BUILD_TYPE=Debug build. The culprit
turned out to be the macro WSREP_LOG, which is allocating a
separate 1KiB buffer for every occurrence.
We replace the macro with a function, so that the stack will be
allocated only when the function is actually invoked. In this way,
no stack space will be wasted by default (when WSREP and Galera
are disabled).
This backports commit b6c5657ef27de034439b1505a8b4815c263d6455
from MariaDB 10.3.1.
Without ASAN, compilers can be smarter and optimize the stack usage.
The original commit message mentions that 1KiB was saved on GCC 5.4,
and 4KiB on Mac OS X Lion, which presumably uses a clang-based compiler.
Diffstat (limited to 'sql/wsrep_mysqld.h')
-rw-r--r-- | sql/wsrep_mysqld.h | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index 0f0a65f97b6..a5ec69268d4 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -201,13 +201,8 @@ extern wsrep_seqno_t wsrep_locked_seqno; ? wsrep_forced_binlog_format : (ulong)(my_format)) // prefix all messages with "WSREP" -#define WSREP_LOG(fun, ...) \ - do { \ - char msg[1024] = {'\0'}; \ - snprintf(msg, sizeof(msg) - 1, ## __VA_ARGS__); \ - fun("WSREP: %s", msg); \ - } while(0) - +void wsrep_log(void (*fun)(const char *, ...), const char *format, ...); +#define WSREP_LOG(fun, ...) wsrep_log(fun, ## __VA_ARGS__) #define WSREP_LOG_CONFLICT_THD(thd, role) \ WSREP_LOG(sql_print_information, \ "%s: \n " \ |