1
/*****************************************************************************
3
Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
1
/******************************************************
21
2
The interface to the operating system
22
3
process control primitives
24
7
Created 9/30/1995 Heikki Tuuri
25
8
*******************************************************/
46
27
/* Large page size. This may be a boot-time option on some platforms */
47
28
UNIV_INTERN ulint os_large_page_size;
49
/****************************************************************//**
30
/********************************************************************
50
31
Converts the current process id to a number. It is not guaranteed that the
51
32
number is unique. In Linux returns the 'process number' of the current
52
33
thread. That number is the same as one sees in 'top', for example. In Linux
53
the thread id is not the same as one sees in 'top'.
54
@return process id as a number */
34
the thread id is not the same as one sees in 'top'. */
57
37
os_proc_get_number(void)
67
/****************************************************************//**
68
Allocates large pages memory.
69
@return allocated memory */
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. */
72
73
os_mem_alloc_large(
73
74
/*===============*/
74
ulint* n) /*!< in/out: number of bytes */
75
/* out: allocated memory */
76
ulint* n) /* in/out: number of bytes */
99
101
fprintf(stderr, "InnoDB: HugeTLB: Warning: Failed to"
100
102
" attach shared memory segment, errno %d\n",
105
106
/* Remove the shared memory segment so that it will be
113
os_fast_mutex_lock(&ut_list_mutex);
114
114
ut_total_allocated_memory += size;
115
os_fast_mutex_unlock(&ut_list_mutex);
116
115
# ifdef UNIV_SET_MEM_TO_ZERO
117
116
memset(ptr, '\0', size);
119
UNIV_MEM_ALLOC(ptr, size);
132
130
/* Align block size to system page size */
133
131
ut_ad(ut_is_2pow(system_info.dwPageSize));
134
/* system_info.dwPageSize is only 32-bit. Casting to ulint is required
135
on 64-bit Windows. */
136
132
size = *n = ut_2pow_round(*n + (system_info.dwPageSize - 1),
137
(ulint) system_info.dwPageSize);
133
system_info.dwPageSize);
138
134
ptr = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE,
142
138
" Windows error %lu\n",
143
139
(ulong) size, (ulong) GetLastError());
145
os_fast_mutex_lock(&ut_list_mutex);
146
141
ut_total_allocated_memory += size;
147
os_fast_mutex_unlock(&ut_list_mutex);
148
UNIV_MEM_ALLOC(ptr, size);
150
#elif !defined OS_MAP_ANON
143
#elif defined __NETWARE__ || !defined OS_MAP_ANON
152
145
ptr = ut_malloc_low(size, TRUE, FALSE);
167
160
(ulong) size, (ulong) errno);
170
os_fast_mutex_lock(&ut_list_mutex);
171
163
ut_total_allocated_memory += size;
172
os_fast_mutex_unlock(&ut_list_mutex);
173
UNIV_MEM_ALLOC(ptr, size);
179
/****************************************************************//**
169
/********************************************************************
180
170
Frees large pages memory. */
183
173
os_mem_free_large(
184
174
/*==============*/
185
void *ptr, /*!< in: pointer returned by
175
void *ptr, /* in: pointer returned by
186
176
os_mem_alloc_large() */
187
ulint size) /*!< in: size returned by
177
ulint size) /* in: size returned by
188
178
os_mem_alloc_large() */
190
os_fast_mutex_lock(&ut_list_mutex);
191
180
ut_a(ut_total_allocated_memory >= size);
192
os_fast_mutex_unlock(&ut_list_mutex);
194
182
#if defined HAVE_LARGE_PAGES && defined UNIV_LINUX
195
183
if (os_use_large_pages && os_large_page_size && !shmdt(ptr)) {
196
os_fast_mutex_lock(&ut_list_mutex);
197
ut_a(ut_total_allocated_memory >= size);
198
184
ut_total_allocated_memory -= size;
199
os_fast_mutex_unlock(&ut_list_mutex);
200
UNIV_MEM_FREE(ptr, size);
203
187
#endif /* HAVE_LARGE_PAGES && UNIV_LINUX */
209
193
" Windows error %lu\n",
210
194
ptr, (ulong) size, (ulong) GetLastError());
212
os_fast_mutex_lock(&ut_list_mutex);
213
ut_a(ut_total_allocated_memory >= size);
214
196
ut_total_allocated_memory -= size;
215
os_fast_mutex_unlock(&ut_list_mutex);
216
UNIV_MEM_FREE(ptr, size);
218
#elif !defined OS_MAP_ANON
198
#elif defined __NETWARE__ || !defined OS_MAP_ANON
221
if (munmap(static_cast<char *>(ptr), size)) {
201
if (munmap(ptr, size)) {
222
202
fprintf(stderr, "InnoDB: munmap(%p, %lu) failed;"
224
204
ptr, (ulong) size, (ulong) errno);
226
os_fast_mutex_lock(&ut_list_mutex);
227
ut_a(ut_total_allocated_memory >= size);
228
206
ut_total_allocated_memory -= size;
229
os_fast_mutex_unlock(&ut_list_mutex);
230
UNIV_MEM_FREE(ptr, size);
211
/********************************************************************
212
Sets the priority boost for threads released from waiting within the current
216
os_process_set_priority_boost(
217
/*==========================*/
218
ibool do_boost) /* in: TRUE if priority boost should be done,
234
/* Does not do anything currently!
235
SetProcessPriorityBoost(GetCurrentProcess(), no_boost);
237
fputs("Warning: process priority boost setting"
238
" currently not functional!\n",
241
UT_NOT_USED(do_boost);