ut0mem.c:
If InnoDB cannot allocate memory, keep retrying for 60 seconds before we crash mysqld; maybe the memory shortage is just temporary innobase/ut/ut0mem.c: If InnoDB cannot allocate memory, keep retrying for 60 seconds before we crash mysqld; maybe the memory shortage is just temporary
This commit is contained in:
parent
6736ce56fb
commit
58002dddc1
@ -14,6 +14,7 @@ Created 5/11/1994 Heikki Tuuri
|
|||||||
|
|
||||||
#include "mem0mem.h"
|
#include "mem0mem.h"
|
||||||
#include "os0sync.h"
|
#include "os0sync.h"
|
||||||
|
#include "os0thread.h"
|
||||||
|
|
||||||
/* This struct is placed first in every allocated memory block */
|
/* This struct is placed first in every allocated memory block */
|
||||||
typedef struct ut_mem_block_struct ut_mem_block_t;
|
typedef struct ut_mem_block_struct ut_mem_block_t;
|
||||||
@ -66,6 +67,7 @@ ut_malloc_low(
|
|||||||
ibool assert_on_error) /* in: if TRUE, we crash mysqld if the memory
|
ibool assert_on_error) /* in: if TRUE, we crash mysqld if the memory
|
||||||
cannot be allocated */
|
cannot be allocated */
|
||||||
{
|
{
|
||||||
|
ulint retry_count = 0;
|
||||||
void* ret;
|
void* ret;
|
||||||
|
|
||||||
ut_ad((sizeof(ut_mem_block_t) % 8) == 0); /* check alignment ok */
|
ut_ad((sizeof(ut_mem_block_t) % 8) == 0); /* check alignment ok */
|
||||||
@ -73,22 +75,24 @@ ut_malloc_low(
|
|||||||
if (!ut_mem_block_list_inited) {
|
if (!ut_mem_block_list_inited) {
|
||||||
ut_mem_block_list_init();
|
ut_mem_block_list_init();
|
||||||
}
|
}
|
||||||
|
retry:
|
||||||
os_fast_mutex_lock(&ut_list_mutex);
|
os_fast_mutex_lock(&ut_list_mutex);
|
||||||
|
|
||||||
ret = malloc(n + sizeof(ut_mem_block_t));
|
ret = malloc(n + sizeof(ut_mem_block_t));
|
||||||
|
|
||||||
if (ret == NULL) {
|
if (ret == NULL && retry_count < 60) {
|
||||||
ut_print_timestamp(stderr);
|
if (retry_count == 0) {
|
||||||
fprintf(stderr,
|
ut_print_timestamp(stderr);
|
||||||
" InnoDB: Fatal error: cannot allocate %lu bytes of\n"
|
|
||||||
|
fprintf(stderr,
|
||||||
|
" InnoDB: Error: cannot allocate %lu bytes of\n"
|
||||||
"InnoDB: memory with malloc! Total allocated memory\n"
|
"InnoDB: memory with malloc! Total allocated memory\n"
|
||||||
"InnoDB: by InnoDB %lu bytes. Operating system errno: %lu\n"
|
"InnoDB: by InnoDB %lu bytes. Operating system errno: %lu\n"
|
||||||
"InnoDB: Cannot continue operation!\n"
|
|
||||||
"InnoDB: Check if you should increase the swap file or\n"
|
"InnoDB: Check if you should increase the swap file or\n"
|
||||||
"InnoDB: ulimits of your operating system.\n"
|
"InnoDB: ulimits of your operating system.\n"
|
||||||
"InnoDB: On FreeBSD check you have compiled the OS with\n"
|
"InnoDB: On FreeBSD check you have compiled the OS with\n"
|
||||||
"InnoDB: a big enough maximum process size.\n",
|
"InnoDB: a big enough maximum process size.\n"
|
||||||
|
"InnoDB: We keep retrying the allocation for 60 seconds...\n",
|
||||||
(ulong) n, (ulong) ut_total_allocated_memory,
|
(ulong) n, (ulong) ut_total_allocated_memory,
|
||||||
#ifdef __WIN__
|
#ifdef __WIN__
|
||||||
(ulong) GetLastError()
|
(ulong) GetLastError()
|
||||||
@ -96,7 +100,21 @@ ut_malloc_low(
|
|||||||
(ulong) errno
|
(ulong) errno
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
os_fast_mutex_unlock(&ut_list_mutex);
|
||||||
|
|
||||||
|
/* Sleep for a second and retry the allocation; maybe this is
|
||||||
|
just a temporary shortage of memory */
|
||||||
|
|
||||||
|
os_thread_sleep(1000000);
|
||||||
|
|
||||||
|
retry_count++;
|
||||||
|
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == NULL) {
|
||||||
/* Flush stderr to make more probable that the error
|
/* Flush stderr to make more probable that the error
|
||||||
message gets in the error file before we generate a seg
|
message gets in the error file before we generate a seg
|
||||||
fault */
|
fault */
|
||||||
@ -111,8 +129,10 @@ ut_malloc_low(
|
|||||||
by graceful exit handling in ut_a(). */
|
by graceful exit handling in ut_a(). */
|
||||||
#if (!defined __NETWARE__)
|
#if (!defined __NETWARE__)
|
||||||
if (assert_on_error) {
|
if (assert_on_error) {
|
||||||
|
ut_print_timestamp(stderr);
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"InnoDB: We now intentionally generate a seg fault so that\n"
|
" InnoDB: We now intentionally generate a seg fault so that\n"
|
||||||
"InnoDB: on Linux we get a stack trace.\n");
|
"InnoDB: on Linux we get a stack trace.\n");
|
||||||
|
|
||||||
if (*ut_mem_null_ptr) ut_mem_null_ptr = 0;
|
if (*ut_mem_null_ptr) ut_mem_null_ptr = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user