39 #if defined(MAP_ANONYMOUS)
40 #define OS_MAP_ANON MAP_ANONYMOUS
41 #elif defined(MAP_ANON)
42 #define OS_MAP_ANON MAP_ANON
45 UNIV_INTERN ibool os_use_large_pages;
47 UNIV_INTERN ulint os_large_page_size;
61 return((ulint)GetCurrentProcessId());
63 return((ulint)getpid());
78 #if defined HAVE_LARGE_PAGES && defined UNIV_LINUX
82 if (!os_use_large_pages || !os_large_page_size) {
91 shmid = shmget(IPC_PRIVATE, (
size_t)size, SHM_HUGETLB | SHM_R | SHM_W);
93 fprintf(stderr,
"InnoDB: HugeTLB: Warning: Failed to allocate"
94 " %lu bytes. errno %d\n", size, errno);
97 ptr = shmat(shmid, NULL, 0);
98 if (ptr == (
void *)-1) {
99 fprintf(stderr,
"InnoDB: HugeTLB: Warning: Failed to"
100 " attach shared memory segment, errno %d\n",
108 shmctl(shmid, IPC_RMID, &buf);
116 # ifdef UNIV_SET_MEM_TO_ZERO
117 memset(ptr,
'\0', size);
119 UNIV_MEM_ALLOC(ptr, size);
123 fprintf(stderr,
"InnoDB HugeTLB: Warning: Using conventional"
129 SYSTEM_INFO system_info;
130 GetSystemInfo(&system_info);
137 (ulint) system_info.dwPageSize);
138 ptr = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE,
141 fprintf(stderr,
"InnoDB: VirtualAlloc(%lu bytes) failed;"
142 " Windows error %lu\n",
143 (ulong) size, (ulong) GetLastError());
148 UNIV_MEM_ALLOC(ptr, size);
150 #elif !defined OS_MAP_ANON
154 # ifdef HAVE_GETPAGESIZE
155 size = getpagesize();
157 size = UNIV_PAGE_SIZE;
162 ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
163 MAP_PRIVATE | OS_MAP_ANON, -1, 0);
164 if (UNIV_UNLIKELY(ptr == (
void*) -1)) {
165 fprintf(stderr,
"InnoDB: mmap(%lu bytes) failed;"
167 (ulong) size, (ulong) errno);
173 UNIV_MEM_ALLOC(ptr, size);
194 #if defined HAVE_LARGE_PAGES && defined UNIV_LINUX
195 if (os_use_large_pages && os_large_page_size && !shmdt(ptr)) {
200 UNIV_MEM_FREE(ptr, size);
207 if (!VirtualFree(ptr, 0, MEM_RELEASE)) {
208 fprintf(stderr,
"InnoDB: VirtualFree(%p, %lu) failed;"
209 " Windows error %lu\n",
210 ptr, (ulong) size, (ulong) GetLastError());
216 UNIV_MEM_FREE(ptr, size);
218 #elif !defined OS_MAP_ANON
221 if (munmap(static_cast<char *>(ptr), size)) {
222 fprintf(stderr,
"InnoDB: munmap(%p, %lu) failed;"
224 ptr, (ulong) size, (ulong) errno);
230 UNIV_MEM_FREE(ptr, size);