1
/******************************************************
2
The interface to the operating system
3
process control primitives
7
Created 9/30/1995 Heikki Tuuri
8
*******************************************************/
18
/* FreeBSD for example has only MAP_ANON, Linux has MAP_ANONYMOUS and
19
MAP_ANON but MAP_ANON is marked as deprecated */
20
#if defined(MAP_ANONYMOUS)
21
#define OS_MAP_ANON MAP_ANONYMOUS
22
#elif defined(MAP_ANON)
23
#define OS_MAP_ANON MAP_ANON
26
UNIV_INTERN ibool os_use_large_pages;
27
/* Large page size. This may be a boot-time option on some platforms */
28
UNIV_INTERN ulint os_large_page_size;
30
/********************************************************************
31
Converts the current process id to a number. It is not guaranteed that the
32
number is unique. In Linux returns the 'process number' of the current
33
thread. That number is the same as one sees in 'top', for example. In Linux
34
the thread id is not the same as one sees in 'top'. */
37
os_proc_get_number(void)
38
/*====================*/
41
return((ulint)GetCurrentProcessId());
43
return((ulint)getpid());
47
/********************************************************************
48
Allocates non-cacheable memory. */
53
/* out: allocated memory */
54
ulint n) /* in: number of bytes */
59
ptr = VirtualAlloc(NULL, n, MEM_COMMIT,
60
PAGE_READWRITE | PAGE_NOCACHE);
69
/********************************************************************
70
Allocates large pages memory. */
75
/* out: allocated memory */
76
ulint* n) /* in/out: number of bytes */
80
#if defined HAVE_LARGE_PAGES && defined UNIV_LINUX
84
if (!os_use_large_pages || !os_large_page_size) {
88
/* Align block size to os_large_page_size */
89
ut_ad(ut_is_2pow(os_large_page_size));
90
size = ut_2pow_round(*n + (os_large_page_size - 1),
93
shmid = shmget(IPC_PRIVATE, (size_t)size, SHM_HUGETLB | SHM_R | SHM_W);
95
fprintf(stderr, "InnoDB: HugeTLB: Warning: Failed to allocate"
96
" %lu bytes. errno %d\n", size, errno);
99
ptr = shmat(shmid, NULL, 0);
100
if (ptr == (void *)-1) {
101
fprintf(stderr, "InnoDB: HugeTLB: Warning: Failed to"
102
" attach shared memory segment, errno %d\n",
106
/* Remove the shared memory segment so that it will be
107
automatically freed after memory is detached or
109
shmctl(shmid, IPC_RMID, &buf);
114
ut_total_allocated_memory += size;
115
# ifdef UNIV_SET_MEM_TO_ZERO
116
memset(ptr, '\0', size);
121
fprintf(stderr, "InnoDB HugeTLB: Warning: Using conventional"
124
#endif /* HAVE_LARGE_PAGES && UNIV_LINUX */
127
SYSTEM_INFO system_info;
128
GetSystemInfo(&system_info);
130
/* Align block size to system page size */
131
ut_ad(ut_is_2pow(system_info.dwPageSize));
132
size = *n = ut_2pow_round(*n + (system_info.dwPageSize - 1),
133
system_info.dwPageSize);
134
ptr = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE,
137
fprintf(stderr, "InnoDB: VirtualAlloc(%lu bytes) failed;"
138
" Windows error %lu\n",
139
(ulong) size, (ulong) GetLastError());
141
ut_total_allocated_memory += size;
143
#elif defined __NETWARE__ || !defined OS_MAP_ANON
145
ptr = ut_malloc_low(size, TRUE, FALSE);
147
# ifdef HAVE_GETPAGESIZE
148
size = getpagesize();
150
size = UNIV_PAGE_SIZE;
152
/* Align block size to system page size */
153
ut_ad(ut_is_2pow(size));
154
size = *n = ut_2pow_round(*n + (size - 1), size);
155
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
156
MAP_PRIVATE | OS_MAP_ANON, -1, 0);
157
if (UNIV_UNLIKELY(ptr == (void*) -1)) {
158
fprintf(stderr, "InnoDB: mmap(%lu bytes) failed;"
160
(ulong) size, (ulong) errno);
163
ut_total_allocated_memory += size;
169
/********************************************************************
170
Frees large pages memory. */
175
void *ptr, /* in: pointer returned by
176
os_mem_alloc_large() */
177
ulint size) /* in: size returned by
178
os_mem_alloc_large() */
180
ut_a(ut_total_allocated_memory >= size);
182
#if defined HAVE_LARGE_PAGES && defined UNIV_LINUX
183
if (os_use_large_pages && os_large_page_size && !shmdt(ptr)) {
184
ut_total_allocated_memory -= size;
187
#endif /* HAVE_LARGE_PAGES && UNIV_LINUX */
189
if (!VirtualFree(ptr, size, MEM_DECOMMIT | MEM_RELEASE)) {
190
fprintf(stderr, "InnoDB: VirtualFree(%p, %lu) failed;"
191
" Windows error %lu\n",
192
ptr, (ulong) size, (ulong) GetLastError());
194
ut_total_allocated_memory -= size;
196
#elif defined __NETWARE__ || !defined OS_MAP_ANON
199
if (munmap(ptr, size)) {
200
fprintf(stderr, "InnoDB: munmap(%p, %lu) failed;"
202
ptr, (ulong) size, (ulong) errno);
204
ut_total_allocated_memory -= size;
209
/********************************************************************
210
Sets the priority boost for threads released from waiting within the current
214
os_process_set_priority_boost(
215
/*==========================*/
216
ibool do_boost) /* in: TRUE if priority boost should be done,
232
/* Does not do anything currently!
233
SetProcessPriorityBoost(GetCurrentProcess(), no_boost);
235
fputs("Warning: process priority boost setting"
236
" currently not functional!\n",
239
UT_NOT_USED(do_boost);