37 #if defined(MAP_ANONYMOUS)
38 #define OS_MAP_ANON MAP_ANONYMOUS
39 #elif defined(MAP_ANON)
40 #define OS_MAP_ANON MAP_ANON
43 UNIV_INTERN ibool os_use_large_pages;
45 UNIV_INTERN ulint os_large_page_size;
59 return((ulint)GetCurrentProcessId());
61 return((ulint) getpid());
76 #if defined HAVE_LARGE_PAGES && defined UNIV_LINUX
80 if (!os_use_large_pages || !os_large_page_size) {
89 shmid = shmget(IPC_PRIVATE, (
size_t) size, SHM_HUGETLB | SHM_R | SHM_W);
91 fprintf(stderr,
"InnoDB: HugeTLB: Warning: Failed to allocate"
92 " %lu bytes. errno %d\n", size, errno);
95 ptr = shmat(shmid, NULL, 0);
96 if (ptr == (
void*)-1) {
97 fprintf(stderr,
"InnoDB: HugeTLB: Warning: Failed to"
98 " attach shared memory segment, errno %d\n",
106 shmctl(shmid, IPC_RMID, &buf);
114 UNIV_MEM_ALLOC(ptr, size);
118 fprintf(stderr,
"InnoDB HugeTLB: Warning: Using conventional"
124 SYSTEM_INFO system_info;
125 GetSystemInfo(&system_info);
132 (ulint) system_info.dwPageSize);
133 ptr = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE,
136 fprintf(stderr,
"InnoDB: VirtualAlloc(%lu bytes) failed;"
137 " Windows error %lu\n",
138 (ulong) size, (ulong) GetLastError());
143 UNIV_MEM_ALLOC(ptr, size);
145 #elif !defined OS_MAP_ANON
149 # ifdef HAVE_GETPAGESIZE
150 size = getpagesize();
152 size = UNIV_PAGE_SIZE;
157 ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
158 MAP_PRIVATE | OS_MAP_ANON, -1, 0);
159 if (UNIV_UNLIKELY(ptr == (
void*) -1)) {
160 fprintf(stderr,
"InnoDB: mmap(%lu bytes) failed;"
162 (ulong) size, (ulong) errno);
168 UNIV_MEM_ALLOC(ptr, size);
189 #if defined HAVE_LARGE_PAGES && defined UNIV_LINUX
190 if (os_use_large_pages && os_large_page_size && !shmdt(ptr)) {
195 UNIV_MEM_FREE(ptr, size);
202 if (!VirtualFree(ptr, 0, MEM_RELEASE)) {
203 fprintf(stderr,
"InnoDB: VirtualFree(%p, %lu) failed;"
204 " Windows error %lu\n",
205 ptr, (ulong) size, (ulong) GetLastError());
211 UNIV_MEM_FREE(ptr, size);
213 #elif !defined OS_MAP_ANON
216 # if defined(UNIV_SOLARIS)
217 if (munmap(static_cast<caddr_t>(ptr), size)) {
219 if (munmap(ptr, size)) {
221 fprintf(stderr,
"InnoDB: munmap(%p, %lu) failed;"
223 ptr, (ulong) size, (ulong) errno);
229 UNIV_MEM_FREE(ptr, size);