16 #include "mysys_priv.h"
18 #ifdef HAVE_LARGE_PAGES
28 static uint my_get_large_page_size_int(
void);
29 static uchar* my_large_malloc_int(
size_t size, myf my_flags);
30 static my_bool my_large_free_int(uchar* ptr);
34 uint my_get_large_page_size(
void)
37 DBUG_ENTER(
"my_get_large_page_size");
39 if (!(size = my_get_large_page_size_int()))
40 fprintf(stderr,
"Warning: Failed to determine large page size\n");
51 uchar* my_large_malloc(
size_t size, myf my_flags)
54 DBUG_ENTER(
"my_large_malloc");
56 if (my_use_large_pages && my_large_page_size)
58 if ((ptr = my_large_malloc_int(size, my_flags)) != NULL)
60 if (my_flags & MY_WME)
61 fprintf(stderr,
"Warning: Using conventional memory pool\n");
64 DBUG_RETURN(my_malloc_lock(size, my_flags));
73 void my_large_free(uchar* ptr)
75 DBUG_ENTER(
"my_large_free");
82 if (!my_use_large_pages || !my_large_page_size || !my_large_free_int(ptr))
88 #ifdef HUGETLB_USE_PROC_MEMINFO
91 uint my_get_large_page_size_int(
void)
96 DBUG_ENTER(
"my_get_large_page_size_int");
99 O_RDONLY, MYF(MY_WME))))
103 if (sscanf(buf,
"Hugepagesize: %u kB", &size))
109 DBUG_RETURN(size * 1024);
113 #if HAVE_DECL_SHM_HUGETLB
116 uchar* my_large_malloc_int(
size_t size, myf my_flags)
121 DBUG_ENTER(
"my_large_malloc_int");
124 size= MY_ALIGN(size, (
size_t) my_large_page_size);
126 shmid = shmget(IPC_PRIVATE, size, SHM_HUGETLB | SHM_R | SHM_W);
129 if (my_flags & MY_WME)
131 "Warning: Failed to allocate %lu bytes from HugeTLB memory."
132 " errno %d\n", (ulong) size, errno);
137 ptr = (uchar*) shmat(shmid, NULL, 0);
138 if (ptr == (uchar *) -1)
140 if (my_flags& MY_WME)
141 fprintf(stderr,
"Warning: Failed to attach shared memory segment,"
142 " errno %d\n", errno);
143 shmctl(shmid, IPC_RMID, &buf);
152 shmctl(shmid, IPC_RMID, &buf);
159 my_bool my_large_free_int(uchar *ptr)
161 DBUG_ENTER(
"my_large_free_int");
162 DBUG_RETURN(shmdt(ptr) == 0);