| 327 | } |
| 328 | |
| 329 | void * |
| 330 | eal_mem_commit(void *requested_addr, size_t size, int socket_id) |
| 331 | { |
| 332 | HANDLE process; |
| 333 | MEM_EXTENDED_PARAMETER param; |
| 334 | DWORD param_count = 0; |
| 335 | DWORD flags; |
| 336 | void *addr; |
| 337 | |
| 338 | process = GetCurrentProcess(); |
| 339 | |
| 340 | if (requested_addr != NULL) { |
| 341 | MEMORY_BASIC_INFORMATION info; |
| 342 | |
| 343 | if (VirtualQueryEx(process, requested_addr, &info, |
| 344 | sizeof(info)) != sizeof(info)) { |
| 345 | RTE_LOG_WIN32_ERR("VirtualQuery(%p)", requested_addr); |
| 346 | return NULL; |
| 347 | } |
| 348 | |
| 349 | /* Split reserved region if only a part is committed. */ |
| 350 | flags = MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER; |
| 351 | if ((info.RegionSize > size) && !VirtualFreeEx( |
| 352 | process, requested_addr, size, flags)) { |
| 353 | RTE_LOG_WIN32_ERR( |
| 354 | "VirtualFreeEx(%p, %zu, preserve placeholder)", |
| 355 | requested_addr, size); |
| 356 | return NULL; |
| 357 | } |
| 358 | |
| 359 | /* Temporarily release the region to be committed. |
| 360 | * |
| 361 | * There is an inherent race for this memory range |
| 362 | * if another thread allocates memory via OS API. |
| 363 | * However, VirtualAlloc2(MEM_REPLACE_PLACEHOLDER) |
| 364 | * doesn't work with MEM_LARGE_PAGES on Windows Server. |
| 365 | */ |
| 366 | if (!VirtualFreeEx(process, requested_addr, 0, MEM_RELEASE)) { |
| 367 | RTE_LOG_WIN32_ERR("VirtualFreeEx(%p, 0, release)", |
| 368 | requested_addr); |
| 369 | return NULL; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | if (socket_id != SOCKET_ID_ANY) { |
| 374 | param_count = 1; |
| 375 | memset(¶m, 0, sizeof(param)); |
| 376 | param.Type = MemExtendedParameterNumaNode; |
| 377 | param.ULong = eal_socket_numa_node(socket_id); |
| 378 | } |
| 379 | |
| 380 | flags = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; |
| 381 | addr = VirtualAlloc2_ptr(process, requested_addr, size, |
| 382 | flags, PAGE_READWRITE, ¶m, param_count); |
| 383 | if (addr == NULL) { |
| 384 | /* Logging may overwrite GetLastError() result. */ |
| 385 | DWORD err = GetLastError(); |
| 386 | RTE_LOG_WIN32_ERR("VirtualAlloc2(%p, %zu, commit large pages)", |
no test coverage detected