Commit a535d4d1 authored by Daniel Black's avatar Daniel Black Committed by Sergey Vojtovich

my_largepage: fprintf -> my_{printf_,}error

parent 11aaf5c8
...@@ -70,7 +70,8 @@ extern const char *globerrs[]; /* my_error_messages is here */ ...@@ -70,7 +70,8 @@ extern const char *globerrs[]; /* my_error_messages is here */
#define EE_CANT_CHMOD 34 #define EE_CANT_CHMOD 34
#define EE_CANT_COPY_OWNERSHIP 35 #define EE_CANT_COPY_OWNERSHIP 35
#define EE_BADMEMORYRELEASE 36 #define EE_BADMEMORYRELEASE 36
#define EE_ERROR_LAST 36 /* Copy last error nr */ #define EE_PERM_LOCK_MEMORY 37
#define EE_ERROR_LAST 37 /* Copy last error nr */
/* Add error numbers before EE_ERROR_LAST and change it accordingly. */ /* Add error numbers before EE_ERROR_LAST and change it accordingly. */
......
...@@ -56,7 +56,8 @@ const char *globerrs[GLOBERRS]= ...@@ -56,7 +56,8 @@ const char *globerrs[GLOBERRS]=
"Can't seek in file '%s' (Errcode: %M)", "Can't seek in file '%s' (Errcode: %M)",
"Can't change mode for file '%s' to 0x%lx (Errcode: %M)", "Can't change mode for file '%s' to 0x%lx (Errcode: %M)",
"Warning: Can't copy ownership for file '%s' (Errcode: %M)", "Warning: Can't copy ownership for file '%s' (Errcode: %M)",
"Failed to release memory pointer %p, %zu bytes (Errcode: %M)" "Failed to release memory pointer %p, %zu bytes (Errcode: %M)",
"Lock Pages in memory access rights required"
}; };
void init_glob_errs(void) void init_glob_errs(void)
...@@ -103,6 +104,7 @@ void init_glob_errs() ...@@ -103,6 +104,7 @@ void init_glob_errs()
EE(EE_CANT_CHMOD) = "Can't change mode for file '%s' to 0x%lx (Errcode: %M)"; EE(EE_CANT_CHMOD) = "Can't change mode for file '%s' to 0x%lx (Errcode: %M)";
EE(EE_CANT_COPY_OWNERSHIP)= "Warning: Can't copy ownership for file '%s' (Errcode: %M)"; EE(EE_CANT_COPY_OWNERSHIP)= "Warning: Can't copy ownership for file '%s' (Errcode: %M)";
EE(EE_BADMEMORYRELEASE)= "Failed to release memory pointer %p, %zu bytes (Errcode: %M)"; EE(EE_BADMEMORYRELEASE)= "Failed to release memory pointer %p, %zu bytes (Errcode: %M)";
EE(EE_PERM_LOCK_MEMORY)= "Lock Pages in memory access rights required";
} }
#endif #endif
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
#include "mysys_priv.h" #include "mysys_priv.h"
#include <mysys_err.h>
#ifdef __linux__ #ifdef __linux__
#include <dirent.h> #include <dirent.h>
...@@ -85,7 +86,7 @@ static void my_get_large_page_sizes(size_t sizes[my_large_page_sizes_length]) ...@@ -85,7 +86,7 @@ static void my_get_large_page_sizes(size_t sizes[my_large_page_sizes_length])
dirp= opendir("/sys/kernel/mm/hugepages"); dirp= opendir("/sys/kernel/mm/hugepages");
if (dirp == NULL) if (dirp == NULL)
{ {
perror("Warning: failed to open /sys/kernel/mm/hugepages"); my_error(EE_DIR, MYF(ME_BELL), "/sys/kernel/mm/hugepages", errno);
} }
else else
{ {
...@@ -96,8 +97,10 @@ static void my_get_large_page_sizes(size_t sizes[my_large_page_sizes_length]) ...@@ -96,8 +97,10 @@ static void my_get_large_page_sizes(size_t sizes[my_large_page_sizes_length])
sizes[i]= strtoull(r->d_name + 10, NULL, 10) * 1024ULL; sizes[i]= strtoull(r->d_name + 10, NULL, 10) * 1024ULL;
if (!my_is_2pow(sizes[i])) if (!my_is_2pow(sizes[i]))
{ {
fprintf(stderr, "Warning: non-power of 2 large page size (%zu) found," my_printf_error(0,
" skipping\n", sizes[i]); "non-power of 2 large page size (%zu) found,"
" skipping", MYF(ME_NOTE | ME_ERROR_LOG_ONLY),
sizes[i]);
sizes[i]= 0; sizes[i]= 0;
continue; continue;
} }
...@@ -106,7 +109,7 @@ static void my_get_large_page_sizes(size_t sizes[my_large_page_sizes_length]) ...@@ -106,7 +109,7 @@ static void my_get_large_page_sizes(size_t sizes[my_large_page_sizes_length])
} }
if (closedir(dirp)) if (closedir(dirp))
{ {
perror("Warning: failed to close /sys/kernel/mm/hugepages"); my_error(EE_BADCLOSE, MYF(ME_BELL), "/sys/kernel/mm/hugepages", errno);
} }
qsort(sizes, i, sizeof(size_t), size_t_cmp); qsort(sizes, i, sizeof(size_t), size_t_cmp);
} }
...@@ -190,9 +193,10 @@ int my_init_large_pages(my_bool super_large_pages) ...@@ -190,9 +193,10 @@ int my_init_large_pages(my_bool super_large_pages)
#ifdef _WIN32 #ifdef _WIN32
if (!my_obtain_privilege(SE_LOCK_MEMORY_NAME)) if (!my_obtain_privilege(SE_LOCK_MEMORY_NAME))
{ {
fprintf(stderr, "mysqld: Lock Pages in memory access rights required for " my_printf_error(EE_PERM_LOCK_MEMORY,
"use with large-pages, see https://mariadb.com/kb/en/library/" "Lock Pages in memory access rights required for use with"
"mariadb-memory-allocation/#huge-pages\n"); " large-pages, see https://mariadb.com/kb/en/library/"
"mariadb-memory-allocation/#huge-pages", MYF(MY_WME));
return 1; return 1;
} }
my_large_page_size= GetLargePageMinimum(); my_large_page_size= GetLargePageMinimum();
...@@ -202,7 +206,8 @@ int my_init_large_pages(my_bool super_large_pages) ...@@ -202,7 +206,8 @@ int my_init_large_pages(my_bool super_large_pages)
my_get_large_page_sizes(my_large_page_sizes); my_get_large_page_sizes(my_large_page_sizes);
#ifndef HAVE_LARGE_PAGES #ifndef HAVE_LARGE_PAGES
fprintf(stderr, "Warning: no large page support on this platform\n"); my_printf_error(EE_OUTOFMEMORY, "No large page support on this platform",
MYF(MY_WME));
#endif #endif
#ifdef HAVE_SOLARIS_LARGE_PAGES #ifdef HAVE_SOLARIS_LARGE_PAGES
...@@ -280,19 +285,28 @@ uchar *my_large_malloc(size_t *size, myf my_flags) ...@@ -280,19 +285,28 @@ uchar *my_large_malloc(size_t *size, myf my_flags)
{ {
if (my_flags & MY_WME) if (my_flags & MY_WME)
{ {
fprintf(stderr, if (my_use_large_pages)
"Warning: VirtualAlloc(%zu bytes%s) failed; Windows error %lu\n", {
*size, my_printf_error(EE_OUTOFMEMORY,
my_use_large_pages ? ", MEM_LARGE_PAGES" : "", "Couldn't allocate %zu bytes (MEM_LARGE_PAGES page "
GetLastError()); "size %zu); Windows error %lu; fallback to "
"conventional pages failed",
MYF(ME_WARNING | ME_ERROR_LOG_ONLY), *size,
my_large_page_size, GetLastError());
}
else
{
my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_ERROR_LOG), *size);
} }
}
if (my_use_large_pages)
{
*size= orig_size; *size= orig_size;
ptr= VirtualAlloc(NULL, *size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); ptr= VirtualAlloc(NULL, *size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (!ptr && my_flags & MY_WME) if (!ptr && my_flags & MY_WME)
{ {
fprintf(stderr, my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_ERROR_LOG), *size);
"Warning: VirtualAlloc(%zu bytes) failed; Windows error %lu\n", }
*size, GetLastError());
} }
} }
#elif defined(HAVE_MMAP) #elif defined(HAVE_MMAP)
...@@ -308,12 +322,15 @@ uchar *my_large_malloc(size_t *size, myf my_flags) ...@@ -308,12 +322,15 @@ uchar *my_large_malloc(size_t *size, myf my_flags)
if (my_use_large_pages) if (my_use_large_pages)
{ {
large_page_size= my_next_large_page_size(*size, &page_i); large_page_size= my_next_large_page_size(*size, &page_i);
/* this might be 0, in which case we do a standard mmap */
if (large_page_size) if (large_page_size)
{ {
#ifdef __linux__ #ifdef __linux__
mapflag|= MAP_HUGETLB | my_bit_log2_size_t(large_page_size) << MAP_HUGE_SHIFT; mapflag|= MAP_HUGETLB |
my_bit_log2_size_t(large_page_size) << MAP_HUGE_SHIFT;
#elif defined(MAP_ALIGNED) #elif defined(MAP_ALIGNED)
mapflag|= MAP_ALIGNED_SUPER | MAP_ALIGNED(my_bit_log2_size_t(large_page_size)); mapflag|= MAP_ALIGNED_SUPER |
MAP_ALIGNED(my_bit_log2_size_t(large_page_size));
#endif #endif
aligned_size= MY_ALIGN(*size, (size_t) large_page_size); aligned_size= MY_ALIGN(*size, (size_t) large_page_size);
} }
...@@ -330,16 +347,15 @@ uchar *my_large_malloc(size_t *size, myf my_flags) ...@@ -330,16 +347,15 @@ uchar *my_large_malloc(size_t *size, myf my_flags)
{ {
if (large_page_size) if (large_page_size)
{ {
fprintf(stderr, my_printf_error(EE_OUTOFMEMORY,
"Warning: Failed to allocate %zu bytes from HugeTLB memory" "Couldn't allocate %zu bytes (Large/HugeTLB memory "
"(page size %zu). errno %d\n", aligned_size, large_page_size, "page size %zu); errno %u; continuing to smaller size",
errno); MYF(ME_WARNING | ME_ERROR_LOG_ONLY),
aligned_size, large_page_size, errno);
} }
else else
{ {
fprintf(stderr, my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_ERROR_LOG), aligned_size);
"Warning: Failed to allocate %zu bytes from memory."
" errno %d\n", aligned_size, errno);
} }
} }
/* try next smaller memory size */ /* try next smaller memory size */
...@@ -403,9 +419,7 @@ void my_large_free(void *ptr, size_t size) ...@@ -403,9 +419,7 @@ void my_large_free(void *ptr, size_t size)
#if defined(HAVE_MMAP) && !defined(_WIN32) #if defined(HAVE_MMAP) && !defined(_WIN32)
if (munmap(ptr, size)) if (munmap(ptr, size))
{ {
fprintf(stderr, my_error(EE_BADMEMORYRELEASE, MYF(ME_ERROR_LOG_ONLY), ptr, size, errno);
"Warning: Failed to unmap location %p, %zu bytes, errno %d\n",
ptr, size, errno);
} }
else else
{ {
...@@ -418,8 +432,8 @@ void my_large_free(void *ptr, size_t size) ...@@ -418,8 +432,8 @@ void my_large_free(void *ptr, size_t size)
*/ */
if (ptr && !VirtualFree(ptr, 0, MEM_RELEASE)) if (ptr && !VirtualFree(ptr, 0, MEM_RELEASE))
{ {
fprintf(stderr, my_error(EE_BADMEMORYRELEASE, MYF(ME_ERROR_LOG_ONLY), ptr, size,
"Error: VirtualFree(%p, %zu) failed; Windows error %lu\n", ptr, size, GetLastError()); GetLastError());
} }
else else
{ {
......
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