MCPcopy Create free account
hub / github.com/F-Stack/f-stack / eal_mem_commit

Function eal_mem_commit

dpdk/lib/eal/windows/eal_memory.c:329–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327}
328
329void *
330eal_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(&param, 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, &param, 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)",

Callers 1

alloc_segFunction · 0.85

Calls 3

memsetFunction · 0.85
eal_socket_numa_nodeFunction · 0.85

Tested by

no test coverage detected