Commit 7198c6ab authored by Marko Mäkelä's avatar Marko Mäkelä

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 b6c5657e
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.
parent 18656797
......@@ -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,
......
......@@ -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 " \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment