📄 os0proc.c
字号:
*(os_awe_simulate_map + i) = NULL; } return(os_awe_simulate_window); #elif defined(__WIN2000__) byte* ptr; if (size > (ulint)0x7FFFFFFFUL) { fprintf(stderr,"InnoDB: AWE: Cannot allocate %lu bytes of virtual memory\n", size); return(NULL); } ptr = VirtualAlloc(NULL, (SIZE_T)size, MEM_RESERVE | MEM_PHYSICAL, PAGE_READWRITE); if (ptr == NULL) { fprintf(stderr,"InnoDB: AWE: Cannot allocate %lu bytes of virtual memory, error %lu\n", size, (ulint)GetLastError()); return(NULL); } os_awe_window = ptr; os_awe_window_size = size; ut_total_allocated_memory += size; return(ptr);#else UT_NOT_USED(size); return(NULL);#endif}/********************************************************************With this function you can map parts of physical memory allocated withthe ..._allocate_physical_mem to the virtual address space allocated withthe previous function. Intel implements this so that the process pagetables are updated accordingly. A test on a 1.5 GHz AMD processor and XPshowed that this takes < 1 microsecond, much better than the estimated 80 usfor copying a 16 kB page memory to memory. But, the operation will at leastpartially invalidate the translation lookaside buffer (TLB) of allprocessors. Under a real-world load the performance hit may be bigger. */iboolos_awe_map_physical_mem_to_window(/*==============================*/ /* out: TRUE if success; the function calls exit(1) in case of an error */ byte* ptr, /* in: a page-aligned pointer to somewhere in the virtual address space window; we map the physical mem pages here */ ulint n_mem_pages, /* in: number of 4 kB mem pages to map */ os_awe_t* page_info) /* in: array of page infos for those pages; each page has one slot in the array */{#ifdef UNIV_SIMULATE_AWE ulint i; byte** map; byte* page; byte* phys_page; ut_a(ptr >= os_awe_simulate_window); ut_a(ptr < os_awe_simulate_window + os_awe_simulate_window_size); ut_a(page_info >= os_awe_simulate_page_info); ut_a(page_info < os_awe_simulate_page_info + (os_awe_simulate_mem_size / 4096)); /* First look if some other 'physical pages' are mapped at ptr, and copy them back to where they were if yes */ map = os_awe_simulate_map + ((ulint)(ptr - os_awe_simulate_window)) / 4096; page = ptr; for (i = 0; i < n_mem_pages; i++) { if (*map != NULL) { ut_memcpy(*map, page, 4096); } map++; page += 4096; } /* Then copy to ptr the 'physical pages' determined by page_info; we assume page_info is a segment of the array we created at the start */ phys_page = os_awe_simulate_mem + (ulint)(page_info - os_awe_simulate_page_info) * 4096; ut_memcpy(ptr, phys_page, n_mem_pages * 4096); /* Update the map */ map = os_awe_simulate_map + ((ulint)(ptr - os_awe_simulate_window)) / 4096; for (i = 0; i < n_mem_pages; i++) { *map = phys_page; map++; phys_page += 4096; } return(TRUE); #elif defined(__WIN2000__) BOOL bResult; os_awe_t n_pages; n_pages = (os_awe_t)n_mem_pages; if (!(ptr >= os_awe_window)) { fprintf(stderr,"InnoDB: AWE: Error: trying to map to address %lx but AWE window start %lx\n", (ulint)ptr, (ulint)os_awe_window); ut_a(0); } if (!(ptr <= os_awe_window + os_awe_window_size - UNIV_PAGE_SIZE)) { fprintf(stderr,"InnoDB: AWE: Error: trying to map to address %lx but AWE window end %lx\n", (ulint)ptr, (ulint)os_awe_window + os_awe_window_size); ut_a(0); } if (!(page_info >= os_awe_page_info)) { fprintf(stderr,"InnoDB: AWE: Error: trying to map page info at %lx but array start %lx\n", (ulint)page_info, (ulint)os_awe_page_info); ut_a(0); } if (!(page_info <= os_awe_page_info + (os_awe_n_pages - 4))) { fprintf(stderr,"InnoDB: AWE: Error: trying to map page info at %lx but array end %lx\n", (ulint)page_info, (ulint)(os_awe_page_info + os_awe_n_pages)); ut_a(0); } bResult = MapUserPhysicalPages((PVOID)ptr, n_pages, page_info); if (bResult != TRUE) { ut_print_timestamp(stderr); fprintf(stderr," InnoDB: AWE: Mapping of %lu physical pages to address %lx failed,\n""InnoDB: error %lu.\n""InnoDB: Cannot continue operation.\n", n_mem_pages, (ulint)ptr, (ulint)GetLastError()); exit(1); } return(TRUE);#else UT_NOT_USED(ptr); UT_NOT_USED(n_mem_pages); UT_NOT_USED(page_info); return(FALSE);#endif} /********************************************************************Converts the current process id to a number. It is not guaranteed that thenumber is unique. In Linux returns the 'process number' of the currentthread. That number is the same as one sees in 'top', for example. In Linuxthe thread id is not the same as one sees in 'top'. */ulintos_proc_get_number(void)/*====================*/{#ifdef __WIN__ return((ulint)GetCurrentProcessId());#else return((ulint)getpid());#endif}/********************************************************************Allocates non-cacheable memory. */void*os_mem_alloc_nocache(/*=================*/ /* out: allocated memory */ ulint n) /* in: number of bytes */{#ifdef __WIN__ void* ptr; ptr = VirtualAlloc(NULL, n, MEM_COMMIT, PAGE_READWRITE | PAGE_NOCACHE); ut_a(ptr); return(ptr);#else return(ut_malloc(n));#endif}/********************************************************************Allocates large pages memory. */void*os_mem_alloc_large(/*=================*/ /* out: allocated memory */ ulint n, /* in: number of bytes */ ibool set_to_zero, /* in: TRUE if allocated memory should be set to zero if UNIV_SET_MEM_TO_ZERO is defined */ ibool assert_on_error) /* in: if TRUE, we crash mysqld if the memory cannot be allocated */{#ifdef HAVE_LARGE_PAGES ulint size; int shmid; void *ptr = NULL; struct shmid_ds buf; if (!os_use_large_pages || !os_large_page_size) { goto skip; }#ifdef UNIV_LINUX /* Align block size to os_large_page_size */ size = ((n - 1) & ~(os_large_page_size - 1)) + os_large_page_size; shmid = shmget(IPC_PRIVATE, (size_t)size, SHM_HUGETLB | SHM_R | SHM_W); if (shmid < 0) { fprintf(stderr, "InnoDB: HugeTLB: Warning: Failed to allocate %lu bytes. " "errno %d\n", n, errno); } else { ptr = shmat(shmid, NULL, 0); if (ptr == (void *)-1) { fprintf(stderr, "InnoDB: HugeTLB: Warning: Failed to attach shared memory " "segment, errno %d\n", errno); } /* Remove the shared memory segment so that it will be automatically freed after memory is detached or process exits */ shmctl(shmid, IPC_RMID, &buf); }#endif if (ptr) { if (set_to_zero) {#ifdef UNIV_SET_MEM_TO_ZERO memset(ptr, '\0', size);#endif } return(ptr); } fprintf(stderr, "InnoDB HugeTLB: Warning: Using conventional memory pool\n");skip:#endif /* HAVE_LARGE_PAGES */ return(ut_malloc_low(n, set_to_zero, assert_on_error));}/********************************************************************Frees large pages memory. */voidos_mem_free_large(/*=================*/ void *ptr) /* in: number of bytes */{#ifdef HAVE_LARGE_PAGES if (os_use_large_pages && os_large_page_size#ifdef UNIV_LINUX && !shmdt(ptr)#endif ) { return; }#endif ut_free(ptr);}/********************************************************************Sets the priority boost for threads released from waiting within the currentprocess. */voidos_process_set_priority_boost(/*==========================*/ ibool do_boost) /* in: TRUE if priority boost should be done, FALSE if not */{#ifdef __WIN__ ibool no_boost; if (do_boost) { no_boost = FALSE; } else { no_boost = TRUE; } ut_a(TRUE == 1);/* Does not do anything currently! SetProcessPriorityBoost(GetCurrentProcess(), no_boost);*/ fputs("Warning: process priority boost setting currently not functional!\n", stderr);#else UT_NOT_USED(do_boost);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -