From 170fd00d24bcd0fffdc3de575ebf37142e15f913 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Wed, 19 Jan 2022 18:51:35 +0000 Subject: [PATCH] Improve mmap logic in createAllocWithAlignment Unmap trailing extra memory right away. Related-To: NEO-6417 Signed-off-by: Filip Hazubski --- .../linux/drm_memory_manager_localmem_tests.cpp | 6 +++--- shared/source/os_interface/linux/drm_allocation.h | 2 +- .../os_interface/linux/drm_memory_manager_local_memory.cpp | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_tests.cpp index a09f062c92..bb7408bd4b 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_tests.cpp @@ -964,7 +964,7 @@ HWTEST2_F(DrmMemoryManagerLocalMemoryTest, givenAlignmentAndSizeWhenMmapReturnsU auto allocation = memoryManager->createAllocWithAlignment(allocationData, MemoryConstants::pageSize, MemoryConstants::pageSize64k, MemoryConstants::pageSize64k, 0u); EXPECT_EQ(alignUp(reinterpret_cast(0x12345678), MemoryConstants::pageSize64k), allocation->getMmapPtr()); - EXPECT_EQ(0u, munmapCalledCount); + EXPECT_EQ(1u, munmapCalledCount); memoryManager->freeGraphicsMemory(allocation); EXPECT_EQ(3u, munmapCalledCount); munmapCalledCount = 0u; @@ -999,10 +999,10 @@ HWTEST2_F(DrmMemoryManagerLocalMemoryTest, givenAlignmentAndSizeWhenMmapReturnsA }; munmapCalledCount = 0u; - auto allocation = memoryManager->createAllocWithAlignment(allocationData, MemoryConstants::pageSize, 1u, MemoryConstants::pageSize64k, 0u); + auto allocation = memoryManager->createAllocWithAlignment(allocationData, MemoryConstants::pageSize, 4u, MemoryConstants::pageSize64k, 0u); EXPECT_EQ(reinterpret_cast(0x12345678), allocation->getMmapPtr()); - EXPECT_EQ(0u, munmapCalledCount); + EXPECT_EQ(1u, munmapCalledCount); memoryManager->freeGraphicsMemory(allocation); EXPECT_EQ(2u, munmapCalledCount); munmapCalledCount = 0u; diff --git a/shared/source/os_interface/linux/drm_allocation.h b/shared/source/os_interface/linux/drm_allocation.h index 3bcea35310..db8d626e77 100644 --- a/shared/source/os_interface/linux/drm_allocation.h +++ b/shared/source/os_interface/linux/drm_allocation.h @@ -105,7 +105,7 @@ class DrmAllocation : public GraphicsAllocation { BufferObjects bufferObjects{}; StackVec registeredBoBindHandles; MemAdviseFlags enabledMemAdviseFlags{}; - StackVec memoryToUnmap; + StackVec memoryToUnmap; void *mmapPtr = nullptr; size_t mmapSize = 0u; diff --git a/shared/source/os_interface/linux/drm_memory_manager_local_memory.cpp b/shared/source/os_interface/linux/drm_memory_manager_local_memory.cpp index 4dc030c104..daef3a8a21 100644 --- a/shared/source/os_interface/linux/drm_memory_manager_local_memory.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager_local_memory.cpp @@ -70,7 +70,8 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData & if (pointerDiff != 0) { allocation->registerMemoryToUnmap(cpuBasePointer, pointerDiff, this->munmapFunction); } - allocation->registerMemoryToUnmap(ptrOffset(cpuPointer, alignedSize), alignment - pointerDiff, this->munmapFunction); + [[maybe_unused]] int retCode = this->munmapFunction(ptrOffset(cpuPointer, alignedSize), alignment - pointerDiff); + DEBUG_BREAK_IF(retCode != 0); allocation->setReservedAddressRange(reinterpret_cast(gpuAddress), alignedSize); bo.release();