From 8f8288adfdee6577d35a44e17d80f09e258fc9fc Mon Sep 17 00:00:00 2001 From: Bryan Bernhart Date: Wed, 13 Jul 2022 12:10:41 -0700 Subject: [PATCH] Supress TrySubAllocateMemory events when never allocate is enabled. --- src/gpgmm/common/BuddyMemoryAllocator.cpp | 1 + src/gpgmm/common/MemoryAllocator.h | 12 ++++++++---- src/gpgmm/common/SlabMemoryAllocator.cpp | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/gpgmm/common/BuddyMemoryAllocator.cpp b/src/gpgmm/common/BuddyMemoryAllocator.cpp index 5f846f844..f77ce1bf8 100644 --- a/src/gpgmm/common/BuddyMemoryAllocator.cpp +++ b/src/gpgmm/common/BuddyMemoryAllocator.cpp @@ -59,6 +59,7 @@ namespace gpgmm { std::unique_ptr subAllocation; GPGMM_TRY_ASSIGN(TrySubAllocateMemory( &mBuddyBlockAllocator, allocationSize, request.Alignment, + request.NeverAllocate, [&](const auto& block) -> MemoryBase* { const uint64_t memoryIndex = GetMemoryIndex(block->Offset); std::unique_ptr memoryAllocation = diff --git a/src/gpgmm/common/MemoryAllocator.h b/src/gpgmm/common/MemoryAllocator.h index 6b23661cc..ed5551227 100644 --- a/src/gpgmm/common/MemoryAllocator.h +++ b/src/gpgmm/common/MemoryAllocator.h @@ -281,16 +281,20 @@ namespace gpgmm { BlockAllocator* allocator, uint64_t requestSize, uint64_t alignment, + bool neverAllocate, GetOrCreateMemoryFn&& GetOrCreateMemory) { MemoryBlock* block = nullptr; GPGMM_TRY_ASSIGN(allocator->TryAllocateBlock(requestSize, alignment), block); MemoryBase* memory = GetOrCreateMemory(block); if (memory == nullptr) { - DebugLog() << std::string(allocator->GetTypename()) + - " failed to sub-allocate memory range = [" - << std::to_string(block->Offset) << ", " - << std::to_string(block->Offset + block->Size) << ")."; + // NeverAllocate always fails, so suppress it. + if (!neverAllocate) { + DebugLog() << std::string(allocator->GetTypename()) + + " failed to sub-allocate memory range = [" + << std::to_string(block->Offset) << ", " + << std::to_string(block->Offset + block->Size) << ")."; + } allocator->DeallocateBlock(block); return nullptr; } diff --git a/src/gpgmm/common/SlabMemoryAllocator.cpp b/src/gpgmm/common/SlabMemoryAllocator.cpp index c8ceed872..9d09fe2fd 100644 --- a/src/gpgmm/common/SlabMemoryAllocator.cpp +++ b/src/gpgmm/common/SlabMemoryAllocator.cpp @@ -238,7 +238,7 @@ namespace gpgmm { std::unique_ptr subAllocation; GPGMM_TRY_ASSIGN( TrySubAllocateMemory( - &pFreeSlab->Allocator, mBlockSize, request.Alignment, + &pFreeSlab->Allocator, mBlockSize, request.Alignment, request.NeverAllocate, [&](const auto& block) -> MemoryBase* { // Re-use memory from the free slab. if (pFreeSlab->Allocation != nullptr) {