#include "univ.i"Include dependency graph for os0proc.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Defines | |
| #define | OS_AWE_X86_PAGE_SIZE 4096 |
Typedefs | |
| typedef void * | os_process_t |
| typedef unsigned long int | os_process_id_t |
| typedef ulint | os_awe_t |
Functions | |
| ibool | os_awe_enable_lock_pages_in_mem (void) |
| ibool | os_awe_allocate_physical_mem (os_awe_t **page_info, ulint n_megabytes) |
| byte * | os_awe_allocate_virtual_mem_window (ulint size) |
| ibool | os_awe_map_physical_mem_to_window (byte *ptr, ulint n_mem_pages, os_awe_t *page_info) |
| ulint | os_proc_get_number (void) |
| void * | os_mem_alloc_nocache (ulint n) |
| void * | os_mem_alloc_large (ulint n, ibool set_to_zero, ibool assert_on_error) |
| void | os_mem_free_large (void *ptr) |
| void | os_process_set_priority_boost (ibool do_boost) |
Variables | |
| ibool | os_use_large_pages |
| ulint | os_large_page_size |
| #define OS_AWE_X86_PAGE_SIZE 4096 |
Definition at line 33 of file os0proc.h.
Referenced by buf_awe_map_page_to_frame(), buf_pool_init(), and os_awe_allocate_physical_mem().
| typedef unsigned long int os_process_id_t |
| typedef void* os_process_t |
Definition at line 171 of file os0proc.c.
References FALSE, NULL, os_awe_enable_lock_pages_in_mem(), OS_AWE_X86_PAGE_SIZE, TRUE, ut_align(), ut_malloc(), UT_NOT_USED, and ut_total_allocated_memory.
Referenced by buf_pool_init().
00173 : TRUE if success */ 00174 os_awe_t** page_info, /* out, own: array of opaque data containing 00175 the info for allocated physical memory pages; 00176 each allocated 4 kB physical memory page has 00177 one slot of type os_awe_t in the array */ 00178 ulint n_megabytes) /* in: number of megabytes to allocate */ 00179 { 00180 #ifdef UNIV_SIMULATE_AWE 00181 os_awe_simulate_page_info = ut_malloc(sizeof(os_awe_t) * 00182 n_megabytes * ((1024 * 1024) / OS_AWE_X86_PAGE_SIZE)); 00183 00184 os_awe_simulate_mem = ut_align(ut_malloc( 00185 4096 + 1024 * 1024 * n_megabytes), 00186 4096); 00187 os_awe_simulate_mem_size = n_megabytes * 1024 * 1024; 00188 00189 *page_info = os_awe_simulate_page_info; 00190 00191 return(TRUE); 00192 00193 #elif defined(__WIN2000__) 00194 BOOL bResult; 00195 os_awe_t NumberOfPages; /* Question: why does Windows 00196 use the name ULONG_PTR for 00197 a scalar integer type? Maybe 00198 because we may also refer to 00199 &NumberOfPages? */ 00200 os_awe_t NumberOfPagesInitial; 00201 SYSTEM_INFO sSysInfo; 00202 int PFNArraySize; 00203 00204 if (n_megabytes > 64 * 1024) { 00205 00206 fprintf(stderr, 00207 "InnoDB: AWE: Error: tried to allocate %lu MB.\n" 00208 "InnoDB: AWE cannot allocate more than 64 GB in any computer.\n", n_megabytes); 00209 00210 return(FALSE); 00211 } 00212 00213 GetSystemInfo(&sSysInfo); /* fill the system information structure */ 00214 00215 if ((ulint)OS_AWE_X86_PAGE_SIZE != (ulint)sSysInfo.dwPageSize) { 00216 fprintf(stderr, 00217 "InnoDB: AWE: Error: this computer has a page size of %lu.\n" 00218 "InnoDB: Should be 4096 bytes for InnoDB AWE support to work.\n", 00219 (ulint)sSysInfo.dwPageSize); 00220 00221 return(FALSE); 00222 } 00223 00224 /* Calculate the number of pages of memory to request */ 00225 00226 NumberOfPages = n_megabytes * ((1024 * 1024) / OS_AWE_X86_PAGE_SIZE); 00227 00228 /* Calculate the size of page_info for allocated physical pages */ 00229 00230 PFNArraySize = NumberOfPages * sizeof(os_awe_t); 00231 00232 *page_info = (os_awe_t*)HeapAlloc(GetProcessHeap(), 0, PFNArraySize); 00233 00234 if (*page_info == NULL) { 00235 fprintf(stderr, 00236 "InnoDB: AWE: Failed to allocate page info array from process heap, error %lu\n", 00237 (ulint)GetLastError()); 00238 00239 return(FALSE); 00240 } 00241 00242 ut_total_allocated_memory += PFNArraySize; 00243 00244 /* Enable this process' privilege to lock pages to physical memory */ 00245 00246 if (!os_awe_enable_lock_pages_in_mem()) { 00247 00248 return(FALSE); 00249 } 00250 00251 /* Allocate the physical memory */ 00252 00253 NumberOfPagesInitial = NumberOfPages; 00254 00255 os_awe_page_info = *page_info; 00256 os_awe_n_pages = (ulint)NumberOfPages; 00257 00258 /* Compilation note: if the compiler complains the function is not 00259 defined, see the note at the start of this file */ 00260 00261 bResult = AllocateUserPhysicalPages(GetCurrentProcess(), 00262 &NumberOfPages, *page_info); 00263 if (bResult != TRUE) { 00264 fprintf(stderr, 00265 "InnoDB: AWE: Cannot allocate physical pages, error %lu.\n", 00266 (ulint)GetLastError()); 00267 00268 return(FALSE); 00269 } 00270 00271 if (NumberOfPagesInitial != NumberOfPages) { 00272 fprintf(stderr, 00273 "InnoDB: AWE: Error: allocated only %lu pages of %lu requested.\n" 00274 "InnoDB: Check that you have enough free RAM.\n" 00275 "InnoDB: In Windows XP Professional and 2000 Professional\n" 00276 "InnoDB: Windows PAE size is max 4 GB. In 2000 and .NET\n" 00277 "InnoDB: Advanced Servers and 2000 Datacenter Server it is 32 GB,\n" 00278 "InnoDB: and in .NET Datacenter Server it is 64 GB.\n" 00279 "InnoDB: A Microsoft web page said that the processor must be an Intel\n" 00280 "InnoDB: processor.\n", 00281 (ulint)NumberOfPages, 00282 (ulint)NumberOfPagesInitial); 00283 00284 return(FALSE); 00285 } 00286 00287 fprintf(stderr, 00288 "InnoDB: Using Address Windowing Extensions (AWE); allocated %lu MB\n", 00289 n_megabytes); 00290 00291 return(TRUE); 00292 #else 00293 UT_NOT_USED(n_megabytes); 00294 UT_NOT_USED(page_info); 00295 00296 return(FALSE); 00297 #endif 00298 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 305 of file os0proc.c.
References NULL, ut_align(), ut_malloc(), UT_NOT_USED, and ut_total_allocated_memory.
Referenced by buf_pool_init().
00307 : allocated memory, or NULL if did not 00308 succeed */ 00309 ulint size) /* in: virtual memory allocation size in bytes, must 00310 be < 2 GB */ 00311 { 00312 #ifdef UNIV_SIMULATE_AWE 00313 ulint i; 00314 00315 os_awe_simulate_window = ut_align(ut_malloc(4096 + size), 4096); 00316 os_awe_simulate_window_size = size; 00317 00318 os_awe_simulate_map = ut_malloc(sizeof(byte*) * (size / 4096)); 00319 00320 for (i = 0; i < (size / 4096); i++) { 00321 *(os_awe_simulate_map + i) = NULL; 00322 } 00323 00324 return(os_awe_simulate_window); 00325 00326 #elif defined(__WIN2000__) 00327 byte* ptr; 00328 00329 if (size > (ulint)0x7FFFFFFFUL) { 00330 fprintf(stderr, 00331 "InnoDB: AWE: Cannot allocate %lu bytes of virtual memory\n", size); 00332 00333 return(NULL); 00334 } 00335 00336 ptr = VirtualAlloc(NULL, (SIZE_T)size, MEM_RESERVE | MEM_PHYSICAL, 00337 PAGE_READWRITE); 00338 if (ptr == NULL) { 00339 fprintf(stderr, 00340 "InnoDB: AWE: Cannot allocate %lu bytes of virtual memory, error %lu\n", 00341 size, (ulint)GetLastError()); 00342 00343 return(NULL); 00344 } 00345 00346 os_awe_window = ptr; 00347 os_awe_window_size = size; 00348 00349 ut_total_allocated_memory += size; 00350 00351 return(ptr); 00352 #else 00353 UT_NOT_USED(size); 00354 00355 return(NULL); 00356 #endif 00357 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_awe_enable_lock_pages_in_mem | ( | void | ) |
Definition at line 82 of file os0proc.c.
References FALSE, HANDLE, NULL, and TRUE.
Referenced by os_awe_allocate_physical_mem().
00084 : TRUE if success, FALSE if error; 00085 prints error info to stderr if no success */ 00086 { 00087 #ifdef UNIV_SIMULATE_AWE 00088 00089 return(TRUE); 00090 00091 #elif defined(__WIN2000__) 00092 struct { 00093 DWORD Count; 00094 LUID_AND_ATTRIBUTES Privilege[1]; 00095 } Info; 00096 HANDLE hProcess; 00097 HANDLE Token; 00098 BOOL Result; 00099 00100 hProcess = GetCurrentProcess(); 00101 00102 /* Open the token of the current process */ 00103 00104 Result = OpenProcessToken(hProcess, 00105 TOKEN_ADJUST_PRIVILEGES, &Token); 00106 if (Result != TRUE) { 00107 fprintf(stderr, 00108 "InnoDB: AWE: Cannot open process token, error %lu\n", 00109 (ulint)GetLastError()); 00110 return(FALSE); 00111 } 00112 00113 Info.Count = 1; 00114 00115 Info.Privilege[0].Attributes = SE_PRIVILEGE_ENABLED; 00116 00117 /* Get the local unique identifier (LUID) of the SE_LOCK_MEMORY 00118 privilege */ 00119 00120 Result = LookupPrivilegeValue(NULL, SE_LOCK_MEMORY_NAME, 00121 &(Info.Privilege[0].Luid)); 00122 if (Result != TRUE) { 00123 fprintf(stderr, 00124 "InnoDB: AWE: Cannot get local privilege value for %s, error %lu.\n", 00125 SE_LOCK_MEMORY_NAME, (ulint)GetLastError()); 00126 00127 return(FALSE); 00128 } 00129 00130 /* Try to adjust the privilege */ 00131 00132 Result = AdjustTokenPrivileges(Token, FALSE, 00133 (PTOKEN_PRIVILEGES)&Info, 00134 0, NULL, NULL); 00135 /* Check the result */ 00136 00137 if (Result != TRUE) { 00138 fprintf(stderr, 00139 "InnoDB: AWE: Cannot adjust process token privileges, error %u.\n", 00140 GetLastError()); 00141 return(FALSE); 00142 } else if (GetLastError() != ERROR_SUCCESS) { 00143 fprintf(stderr, 00144 "InnoDB: AWE: Cannot enable SE_LOCK_MEMORY privilege, error %lu.\n" 00145 "InnoDB: In Windows XP Home you cannot use AWE. In Windows 2000 and XP\n" 00146 "InnoDB: Professional you must go to the Control Panel, to\n" 00147 "InnoDB: Security Settings, to Local Policies, and enable\n" 00148 "InnoDB: the 'lock pages in memory' privilege for the user who runs\n" 00149 "InnoDB: the MySQL server.\n", GetLastError()); 00150 00151 return(FALSE); 00152 } 00153 00154 CloseHandle(Token); 00155 00156 return(TRUE); 00157 #else 00158 #ifdef __WIN__ 00159 fprintf(stderr, 00160 "InnoDB: AWE: Error: to use AWE you must use a ...-nt MySQL executable.\n"); 00161 #endif 00162 return(FALSE); 00163 #endif 00164 }
Here is the caller graph for this function:

Definition at line 370 of file os0proc.c.
References exit, FALSE, map, NULL, page, TRUE, UNIV_PAGE_SIZE, ut_a, ut_memcpy(), UT_NOT_USED, and ut_print_timestamp().
Referenced by buf_awe_map_page_to_frame(), and buf_pool_init().
00372 : TRUE if success; the function 00373 calls exit(1) in case of an error */ 00374 byte* ptr, /* in: a page-aligned pointer to 00375 somewhere in the virtual address 00376 space window; we map the physical mem 00377 pages here */ 00378 ulint n_mem_pages, /* in: number of 4 kB mem pages to 00379 map */ 00380 os_awe_t* page_info) /* in: array of page infos for those 00381 pages; each page has one slot in the 00382 array */ 00383 { 00384 #ifdef UNIV_SIMULATE_AWE 00385 ulint i; 00386 byte** map; 00387 byte* page; 00388 byte* phys_page; 00389 00390 ut_a(ptr >= os_awe_simulate_window); 00391 ut_a(ptr < os_awe_simulate_window + os_awe_simulate_window_size); 00392 ut_a(page_info >= os_awe_simulate_page_info); 00393 ut_a(page_info < os_awe_simulate_page_info + 00394 (os_awe_simulate_mem_size / 4096)); 00395 00396 /* First look if some other 'physical pages' are mapped at ptr, 00397 and copy them back to where they were if yes */ 00398 00399 map = os_awe_simulate_map 00400 + ((ulint)(ptr - os_awe_simulate_window)) / 4096; 00401 page = ptr; 00402 00403 for (i = 0; i < n_mem_pages; i++) { 00404 if (*map != NULL) { 00405 ut_memcpy(*map, page, 4096); 00406 } 00407 map++; 00408 page += 4096; 00409 } 00410 00411 /* Then copy to ptr the 'physical pages' determined by page_info; we 00412 assume page_info is a segment of the array we created at the start */ 00413 00414 phys_page = os_awe_simulate_mem 00415 + (ulint)(page_info - os_awe_simulate_page_info) 00416 * 4096; 00417 00418 ut_memcpy(ptr, phys_page, n_mem_pages * 4096); 00419 00420 /* Update the map */ 00421 00422 map = os_awe_simulate_map 00423 + ((ulint)(ptr - os_awe_simulate_window)) / 4096; 00424 00425 for (i = 0; i < n_mem_pages; i++) { 00426 *map = phys_page; 00427 00428 map++; 00429 phys_page += 4096; 00430 } 00431 00432 return(TRUE); 00433 00434 #elif defined(__WIN2000__) 00435 BOOL bResult; 00436 os_awe_t n_pages; 00437 00438 n_pages = (os_awe_t)n_mem_pages; 00439 00440 if (!(ptr >= os_awe_window)) { 00441 fprintf(stderr, 00442 "InnoDB: AWE: Error: trying to map to address %lx but AWE window start %lx\n", 00443 (ulint)ptr, (ulint)os_awe_window); 00444 ut_a(0); 00445 } 00446 00447 if (!(ptr <= os_awe_window + os_awe_window_size - UNIV_PAGE_SIZE)) { 00448 fprintf(stderr, 00449 "InnoDB: AWE: Error: trying to map to address %lx but AWE window end %lx\n", 00450 (ulint)ptr, (ulint)os_awe_window + os_awe_window_size); 00451 ut_a(0); 00452 } 00453 00454 if (!(page_info >= os_awe_page_info)) { 00455 fprintf(stderr, 00456 "InnoDB: AWE: Error: trying to map page info at %lx but array start %lx\n", 00457 (ulint)page_info, (ulint)os_awe_page_info); 00458 ut_a(0); 00459 } 00460 00461 if (!(page_info <= os_awe_page_info + (os_awe_n_pages - 4))) { 00462 fprintf(stderr, 00463 "InnoDB: AWE: Error: trying to map page info at %lx but array end %lx\n", 00464 (ulint)page_info, (ulint)(os_awe_page_info + os_awe_n_pages)); 00465 ut_a(0); 00466 } 00467 00468 bResult = MapUserPhysicalPages((PVOID)ptr, n_pages, page_info); 00469 00470 if (bResult != TRUE) { 00471 ut_print_timestamp(stderr); 00472 fprintf(stderr, 00473 " InnoDB: AWE: Mapping of %lu physical pages to address %lx failed,\n" 00474 "InnoDB: error %lu.\n" 00475 "InnoDB: Cannot continue operation.\n", 00476 n_mem_pages, (ulint)ptr, (ulint)GetLastError()); 00477 exit(1); 00478 } 00479 00480 return(TRUE); 00481 #else 00482 UT_NOT_USED(ptr); 00483 UT_NOT_USED(n_mem_pages); 00484 UT_NOT_USED(page_info); 00485 00486 return(FALSE); 00487 #endif 00488 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void* os_mem_alloc_large | ( | ulint | n, | |
| ibool | set_to_zero, | |||
| ibool | assert_on_error | |||
| ) |
Definition at line 533 of file os0proc.c.
References errno, memset, NULL, os_large_page_size, os_use_large_pages, skip(), and ut_malloc_low().
Referenced by buf_pool_init().
00535 : allocated memory */ 00536 ulint n, /* in: number of bytes */ 00537 ibool set_to_zero, /* in: TRUE if allocated memory 00538 should be set to zero if 00539 UNIV_SET_MEM_TO_ZERO is defined */ 00540 ibool assert_on_error)/* in: if TRUE, we crash mysqld if 00541 the memory cannot be allocated */ 00542 { 00543 #ifdef HAVE_LARGE_PAGES 00544 ulint size; 00545 int shmid; 00546 void *ptr = NULL; 00547 struct shmid_ds buf; 00548 00549 if (!os_use_large_pages || !os_large_page_size) { 00550 goto skip; 00551 } 00552 00553 #ifdef UNIV_LINUX 00554 /* Align block size to os_large_page_size */ 00555 size = ((n - 1) & ~(os_large_page_size - 1)) + os_large_page_size; 00556 00557 shmid = shmget(IPC_PRIVATE, (size_t)size, SHM_HUGETLB | SHM_R | SHM_W); 00558 if (shmid < 0) { 00559 fprintf(stderr, "InnoDB: HugeTLB: Warning: Failed to allocate" 00560 " %lu bytes. errno %d\n", n, errno); 00561 } else { 00562 ptr = shmat(shmid, NULL, 0); 00563 if (ptr == (void *)-1) { 00564 fprintf(stderr, "InnoDB: HugeTLB: Warning: Failed to" 00565 " attach shared memory segment, errno %d\n", errno); 00566 } 00567 00568 /* Remove the shared memory segment so that it will be 00569 automatically freed after memory is detached or process exits */ 00570 shmctl(shmid, IPC_RMID, &buf); 00571 } 00572 #endif 00573 00574 if (ptr) { 00575 if (set_to_zero) { 00576 #ifdef UNIV_SET_MEM_TO_ZERO 00577 memset(ptr, '\0', size); 00578 #endif 00579 } 00580 00581 return(ptr); 00582 } 00583 00584 fprintf(stderr, "InnoDB HugeTLB: Warning: Using conventional memory pool\n"); 00585 skip: 00586 #endif /* HAVE_LARGE_PAGES */ 00587 00588 return(ut_malloc_low(n, set_to_zero, assert_on_error)); 00589 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void* os_mem_alloc_nocache | ( | ulint | n | ) |
Definition at line 511 of file os0proc.c.
References NULL, ut_a, and ut_malloc().
00513 : allocated memory */ 00514 ulint n) /* in: number of bytes */ 00515 { 00516 #ifdef __WIN__ 00517 void* ptr; 00518 00519 ptr = VirtualAlloc(NULL, n, MEM_COMMIT, 00520 PAGE_READWRITE | PAGE_NOCACHE); 00521 ut_a(ptr); 00522 00523 return(ptr); 00524 #else 00525 return(ut_malloc(n)); 00526 #endif 00527 }
Here is the call graph for this function:

| void os_mem_free_large | ( | void * | ptr | ) |
Definition at line 595 of file os0proc.c.
References os_large_page_size, os_use_large_pages, and ut_free().
00597 : number of bytes */ 00598 { 00599 #ifdef HAVE_LARGE_PAGES 00600 if (os_use_large_pages && os_large_page_size 00601 #ifdef UNIV_LINUX 00602 && !shmdt(ptr) 00603 #endif 00604 ) { 00605 return; 00606 } 00607 #endif 00608 00609 ut_free(ptr); 00610 }
Here is the call graph for this function:

| ulint os_proc_get_number | ( | void | ) |
Definition at line 497 of file os0proc.c.
Referenced by innobase_start_or_create_for_mysql(), srv_master_thread(), trx_allocate_for_mysql(), and trx_rollback_or_clean_all_without_sess().
00499 { 00500 #ifdef __WIN__ 00501 return((ulint)GetCurrentProcessId()); 00502 #else 00503 return((ulint)getpid()); 00504 #endif 00505 }
Here is the caller graph for this function:

| void os_process_set_priority_boost | ( | ibool | do_boost | ) |
Definition at line 617 of file os0proc.c.
References FALSE, TRUE, and UT_NOT_USED.
00619 : TRUE if priority boost should be done, 00620 FALSE if not */ 00621 { 00622 #ifdef __WIN__ 00623 ibool no_boost; 00624 00625 if (do_boost) { 00626 no_boost = FALSE; 00627 } else { 00628 no_boost = TRUE; 00629 } 00630 00631 #if TRUE != 1 00632 # error "TRUE != 1" 00633 #endif 00634 00635 /* Does not do anything currently! 00636 SetProcessPriorityBoost(GetCurrentProcess(), no_boost); 00637 */ 00638 fputs("Warning: process priority boost setting currently not functional!\n", 00639 stderr); 00640 #else 00641 UT_NOT_USED(do_boost); 00642 #endif 00643 }
Definition at line 74 of file os0proc.c.
Referenced by os_mem_alloc_large(), and os_mem_free_large().
| ibool os_use_large_pages |
Definition at line 72 of file os0proc.c.
Referenced by os_mem_alloc_large(), and os_mem_free_large().
1.4.7

