summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-04-17 10:49:07 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2020-04-17 10:54:56 +0300
commit7198c6ab2dc8f8286f6732824ab985a76ebaaddc (patch)
treee8e363c5bd24322498f2c8c8c15aa620a5128a37
parent18656797de2c10f7539f99b257cdf093056d9ad9 (diff)
downloadmariadb-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.
-rw-r--r--sql/wsrep_mysqld.cc11
-rw-r--r--sql/wsrep_mysqld.h9
2 files changed, 13 insertions, 7 deletions
diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc
index c256467706b..f38bf85cd1a 100644
--- a/sql/wsrep_mysqld.cc
+++ b/sql/wsrep_mysqld.cc
@@ -233,6 +233,17 @@ static void wsrep_log_cb(wsrep_log_level_t level, const char *msg) {
}
}
+void wsrep_log(void (*fun)(const char *, ...), const char *format, ...)
+{
+ va_list args;
+ char msg[1024];
+ va_start(args, format);
+ vsnprintf(msg, sizeof(msg) - 1, format, args);
+ va_end(args);
+ (fun)("WSREP: %s", msg);
+}
+
+
static void wsrep_log_states (wsrep_log_level_t const level,
const wsrep_uuid_t* const group_uuid,
wsrep_seqno_t const group_seqno,
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 " \