~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/os/os0proc.c

  • Committer: Monty Taylor
  • Date: 2008-08-01 22:33:44 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080801223344-vzhlflfmtijp1imv
First pass at gettexizing the error messages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
 
 
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.
8
 
 
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.
12
 
 
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., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file os/os0proc.c
21
 
The interface to the operating system
22
 
process control primitives
23
 
 
24
 
Created 9/30/1995 Heikki Tuuri
25
 
*******************************************************/
26
 
 
27
 
#include "os0proc.h"
28
 
#ifdef UNIV_NONINL
29
 
#include "os0proc.ic"
30
 
#endif
31
 
 
32
 
#include "ut0mem.h"
33
 
#include "ut0byte.h"
34
 
#include <errno.h>
35
 
 
36
 
/* FreeBSD for example has only MAP_ANON, Linux has MAP_ANONYMOUS and
37
 
MAP_ANON but MAP_ANON is marked as deprecated */
38
 
#if defined(MAP_ANONYMOUS)
39
 
#define OS_MAP_ANON     MAP_ANONYMOUS
40
 
#elif defined(MAP_ANON)
41
 
#define OS_MAP_ANON     MAP_ANON
42
 
#endif
43
 
 
44
 
UNIV_INTERN ibool os_use_large_pages;
45
 
/* Large page size. This may be a boot-time option on some platforms */
46
 
UNIV_INTERN ulint os_large_page_size;
47
 
 
48
 
/****************************************************************//**
49
 
Converts the current process id to a number. It is not guaranteed that the
50
 
number is unique. In Linux returns the 'process number' of the current
51
 
thread. That number is the same as one sees in 'top', for example. In Linux
52
 
the thread id is not the same as one sees in 'top'.
53
 
@return process id as a number */
54
 
UNIV_INTERN
55
 
ulint
56
 
os_proc_get_number(void)
57
 
/*====================*/
58
 
{
59
 
#ifdef __WIN__
60
 
        return((ulint)GetCurrentProcessId());
61
 
#else
62
 
        return((ulint)getpid());
63
 
#endif
64
 
}
65
 
 
66
 
/****************************************************************//**
67
 
Allocates large pages memory.
68
 
@return allocated memory */
69
 
UNIV_INTERN
70
 
void*
71
 
os_mem_alloc_large(
72
 
/*===============*/
73
 
        ulint*  n)                      /*!< in/out: number of bytes */
74
 
{
75
 
        void*   ptr;
76
 
        ulint   size;
77
 
#if defined HAVE_LARGE_PAGES && defined UNIV_LINUX
78
 
        int shmid;
79
 
        struct shmid_ds buf;
80
 
 
81
 
        if (!os_use_large_pages || !os_large_page_size) {
82
 
                goto skip;
83
 
        }
84
 
 
85
 
        /* Align block size to os_large_page_size */
86
 
        ut_ad(ut_is_2pow(os_large_page_size));
87
 
        size = ut_2pow_round(*n + (os_large_page_size - 1),
88
 
                             os_large_page_size);
89
 
 
90
 
        shmid = shmget(IPC_PRIVATE, (size_t)size, SHM_HUGETLB | SHM_R | SHM_W);
91
 
        if (shmid < 0) {
92
 
                fprintf(stderr, "InnoDB: HugeTLB: Warning: Failed to allocate"
93
 
                        " %lu bytes. errno %d\n", size, errno);
94
 
                ptr = NULL;
95
 
        } else {
96
 
                ptr = shmat(shmid, NULL, 0);
97
 
                if (ptr == (void *)-1) {
98
 
                        fprintf(stderr, "InnoDB: HugeTLB: Warning: Failed to"
99
 
                                " attach shared memory segment, errno %d\n",
100
 
                                errno);
101
 
                }
102
 
 
103
 
                /* Remove the shared memory segment so that it will be
104
 
                automatically freed after memory is detached or
105
 
                process exits */
106
 
                shmctl(shmid, IPC_RMID, &buf);
107
 
        }
108
 
 
109
 
        if (ptr) {
110
 
                *n = size;
111
 
                os_fast_mutex_lock(&ut_list_mutex);
112
 
                ut_total_allocated_memory += size;
113
 
                os_fast_mutex_unlock(&ut_list_mutex);
114
 
# ifdef UNIV_SET_MEM_TO_ZERO
115
 
                memset(ptr, '\0', size);
116
 
# endif
117
 
                UNIV_MEM_ALLOC(ptr, size);
118
 
                return(ptr);
119
 
        }
120
 
 
121
 
        fprintf(stderr, "InnoDB HugeTLB: Warning: Using conventional"
122
 
                " memory pool\n");
123
 
skip:
124
 
#endif /* HAVE_LARGE_PAGES && UNIV_LINUX */
125
 
 
126
 
#ifdef __WIN__
127
 
        SYSTEM_INFO     system_info;
128
 
        GetSystemInfo(&system_info);
129
 
 
130
 
        /* Align block size to system page size */
131
 
        ut_ad(ut_is_2pow(system_info.dwPageSize));
132
 
        /* system_info.dwPageSize is only 32-bit. Casting to ulint is required
133
 
        on 64-bit Windows. */
134
 
        size = *n = ut_2pow_round(*n + (system_info.dwPageSize - 1),
135
 
                                  (ulint) system_info.dwPageSize);
136
 
        ptr = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE,
137
 
                           PAGE_READWRITE);
138
 
        if (!ptr) {
139
 
                fprintf(stderr, "InnoDB: VirtualAlloc(%lu bytes) failed;"
140
 
                        " Windows error %lu\n",
141
 
                        (ulong) size, (ulong) GetLastError());
142
 
        } else {
143
 
                os_fast_mutex_lock(&ut_list_mutex);
144
 
                ut_total_allocated_memory += size;
145
 
                os_fast_mutex_unlock(&ut_list_mutex);
146
 
                UNIV_MEM_ALLOC(ptr, size);
147
 
        }
148
 
#elif defined __NETWARE__ || !defined OS_MAP_ANON
149
 
        size = *n;
150
 
        ptr = ut_malloc_low(size, TRUE, FALSE);
151
 
#else
152
 
# ifdef HAVE_GETPAGESIZE
153
 
        size = getpagesize();
154
 
# else
155
 
        size = UNIV_PAGE_SIZE;
156
 
# endif
157
 
        /* Align block size to system page size */
158
 
        ut_ad(ut_is_2pow(size));
159
 
        size = *n = ut_2pow_round(*n + (size - 1), size);
160
 
        ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
161
 
                   MAP_PRIVATE | OS_MAP_ANON, -1, 0);
162
 
        if (UNIV_UNLIKELY(ptr == (void*) -1)) {
163
 
                fprintf(stderr, "InnoDB: mmap(%lu bytes) failed;"
164
 
                        " errno %lu\n",
165
 
                        (ulong) size, (ulong) errno);
166
 
                ptr = NULL;
167
 
        } else {
168
 
                os_fast_mutex_lock(&ut_list_mutex);
169
 
                ut_total_allocated_memory += size;
170
 
                os_fast_mutex_unlock(&ut_list_mutex);
171
 
                UNIV_MEM_ALLOC(ptr, size);
172
 
        }
173
 
#endif
174
 
        return(ptr);
175
 
}
176
 
 
177
 
/****************************************************************//**
178
 
Frees large pages memory. */
179
 
UNIV_INTERN
180
 
void
181
 
os_mem_free_large(
182
 
/*==============*/
183
 
        void    *ptr,                   /*!< in: pointer returned by
184
 
                                        os_mem_alloc_large() */
185
 
        ulint   size)                   /*!< in: size returned by
186
 
                                        os_mem_alloc_large() */
187
 
{
188
 
        os_fast_mutex_lock(&ut_list_mutex);
189
 
        ut_a(ut_total_allocated_memory >= size);
190
 
        os_fast_mutex_unlock(&ut_list_mutex);
191
 
 
192
 
#if defined HAVE_LARGE_PAGES && defined UNIV_LINUX
193
 
        if (os_use_large_pages && os_large_page_size && !shmdt(ptr)) {
194
 
                os_fast_mutex_lock(&ut_list_mutex);
195
 
                ut_a(ut_total_allocated_memory >= size);
196
 
                ut_total_allocated_memory -= size;
197
 
                os_fast_mutex_unlock(&ut_list_mutex);
198
 
                UNIV_MEM_FREE(ptr, size);
199
 
                return;
200
 
        }
201
 
#endif /* HAVE_LARGE_PAGES && UNIV_LINUX */
202
 
#ifdef __WIN__
203
 
        /* When RELEASE memory, the size parameter must be 0.
204
 
        Do not use MEM_RELEASE with MEM_DECOMMIT. */
205
 
        if (!VirtualFree(ptr, 0, MEM_RELEASE)) {
206
 
                fprintf(stderr, "InnoDB: VirtualFree(%p, %lu) failed;"
207
 
                        " Windows error %lu\n",
208
 
                        ptr, (ulong) size, (ulong) GetLastError());
209
 
        } else {
210
 
                os_fast_mutex_lock(&ut_list_mutex);
211
 
                ut_a(ut_total_allocated_memory >= size);
212
 
                ut_total_allocated_memory -= size;
213
 
                os_fast_mutex_unlock(&ut_list_mutex);
214
 
                UNIV_MEM_FREE(ptr, size);
215
 
        }
216
 
#elif defined __NETWARE__ || !defined OS_MAP_ANON
217
 
        ut_free(ptr);
218
 
#else
219
 
        if (munmap(ptr, size)) {
220
 
                fprintf(stderr, "InnoDB: munmap(%p, %lu) failed;"
221
 
                        " errno %lu\n",
222
 
                        ptr, (ulong) size, (ulong) errno);
223
 
        } else {
224
 
                os_fast_mutex_lock(&ut_list_mutex);
225
 
                ut_a(ut_total_allocated_memory >= size);
226
 
                ut_total_allocated_memory -= size;
227
 
                os_fast_mutex_unlock(&ut_list_mutex);
228
 
                UNIV_MEM_FREE(ptr, size);
229
 
        }
230
 
#endif
231
 
}