From 5a6a90aa0e76f0e0bab35d07ee9cbb28e6338ed6 Mon Sep 17 00:00:00 2001 From: Kamil Diedrich Date: Tue, 26 Jul 2022 16:14:20 +0000 Subject: [PATCH] Destroy resource handle when created When allocation is created and createResource is set we need to remove resourceHandle instead of allocation handle list otherwise in long running application (a lot of allocations) we will observe memory leak. Signed-off-by: Kamil Diedrich --- .../windows/wddm_memory_manager_tests.cpp | 18 ++++++++++++++++++ .../windows/wddm_memory_manager.cpp | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 8ca629664d..af4073067e 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -811,6 +811,24 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHandl EXPECT_EQ(lastDestroyed, expectedDestroyHandle); } +TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromHostPtrIsCalledThenDestroyResourceHandle) { + auto size = 13u; + auto hostPtr = reinterpret_cast(0x10001); + + AllocationData allocationData; + allocationData.size = size; + allocationData.hostPtr = hostPtr; + auto allocation = static_cast(memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(allocationData)); + + auto expectedDestroyHandle = allocation->resourceHandle; + EXPECT_NE(0u, expectedDestroyHandle); + auto lastDestroyed = getMockLastDestroyedResHandleFcn(); + EXPECT_EQ(0u, lastDestroyed); + memoryManager->freeGraphicsMemory(allocation); + lastDestroyed = getMockLastDestroyedResHandleFcn(); + EXPECT_EQ(lastDestroyed, expectedDestroyHandle); +} + TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromSharedHandleIsCalledThenUpdateSize) { auto osHandle = 1u; auto size = 4096u; diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index f46dfc1d8e..28e2e3e7f9 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -565,7 +565,7 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation input->fragmentsStorage.fragmentCount > 0) { cleanGraphicsMemoryCreatedFromHostPtr(gfxAllocation); } else { - if (input->peekSharedHandle() || input->peekInternalHandle(nullptr) != 0) { + if (input->resourceHandle != 0) { [[maybe_unused]] auto status = tryDeferDeletions(nullptr, 0, input->resourceHandle, gfxAllocation->getRootDeviceIndex()); DEBUG_BREAK_IF(!status); } else {