From 2a1069eda2eca74d0c44356bb66f0a419a449741 Mon Sep 17 00:00:00 2001 From: Slawomir Milczarek Date: Thu, 21 Jan 2021 12:52:48 +0000 Subject: [PATCH] Configure 2MB alignment for allocations on standard heap 64k Signed-off-by: Slawomir Milczarek --- ...ager_allocate_in_device_pool_tests_dg1.cpp | 18 ++--- .../linux/drm_memory_manager_tests.cpp | 6 +- .../source/memory_manager/gfx_partition.cpp | 12 ++-- shared/source/memory_manager/gfx_partition.h | 8 ++- shared/source/utilities/heap_allocator.h | 11 ++-- .../utilities/heap_allocator_tests.cpp | 65 +++++++++++-------- 6 files changed, 69 insertions(+), 51 deletions(-) diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests_dg1.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests_dg1.cpp index 9196eb858b..7abb74b2a4 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests_dg1.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests_dg1.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -577,15 +577,17 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenNotSetUseSystemMemoryWhenGraphicsAl EXPECT_NE(0u, gpuAddress); auto heap = HeapIndex::HEAP_STANDARD64KB; + auto sizeReserved = alignUp(sizeAligned, 2 * MemoryConstants::megaByte); if (memoryManager->getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_EXTENDED)) { heap = HeapIndex::HEAP_EXTENDED; + sizeReserved = alignUp(sizeAligned, MemoryConstants::pageSize); } EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapBase(heap)), gpuAddress); EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapLimit(heap)), gpuAddress); EXPECT_EQ(0u, allocation->getGpuBaseAddress()); EXPECT_EQ(sizeAligned, allocation->getUnderlyingBufferSize()); EXPECT_EQ(gpuAddress, reinterpret_cast(allocation->getReservedAddressPtr())); - EXPECT_EQ(sizeAligned, allocation->getReservedAddressSize()); + EXPECT_EQ(sizeReserved, allocation->getReservedAddressSize()); EXPECT_EQ(1u, allocation->storageInfo.getNumBanks()); EXPECT_EQ(allocData.storageInfo.getMemoryBanks(), allocation->storageInfo.getMemoryBanks()); @@ -636,7 +638,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenNotSetUseSystemMemoryWhenGraphicsAl EXPECT_EQ(0u, allocation->getGpuBaseAddress()); EXPECT_EQ(sizeAligned, allocation->getUnderlyingBufferSize()); EXPECT_EQ(gpuAddress, reinterpret_cast(allocation->getReservedAddressPtr())); - EXPECT_EQ(sizeAligned, allocation->getReservedAddressSize()); + EXPECT_EQ(alignUp(sizeAligned, 2 * MemoryConstants::megaByte), allocation->getReservedAddressSize()); EXPECT_EQ(1u, allocation->storageInfo.getNumBanks()); EXPECT_EQ(allocData.storageInfo.getMemoryBanks(), allocation->storageInfo.getMemoryBanks()); @@ -925,18 +927,18 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenOversizedAllocationWhenGraphicsAllo if (memoryManager->getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_EXTENDED)) { heap = HeapIndex::HEAP_EXTENDED; } - auto largerSize = 3 * MemoryConstants::pageSize64k; + auto largerSize = 6 * MemoryConstants::megaByte; auto gpuAddress1 = memoryManager->getGfxPartition(0)->heapAllocate(heap, largerSize); EXPECT_NE(0u, gpuAddress1); - EXPECT_EQ(3 * MemoryConstants::pageSize64k, largerSize); + EXPECT_EQ(6 * MemoryConstants::megaByte, largerSize); auto gpuAddress2 = memoryManager->getGfxPartition(0)->heapAllocate(heap, largerSize); EXPECT_NE(0u, gpuAddress2); - EXPECT_EQ(3 * MemoryConstants::pageSize64k, largerSize); + EXPECT_EQ(6 * MemoryConstants::megaByte, largerSize); memoryManager->getGfxPartition(0)->heapFree(heap, gpuAddress1, largerSize); auto status = MemoryManager::AllocationStatus::Error; AllocationData allocData; - allocData.size = 2 * MemoryConstants::pageSize64k; + allocData.size = 5 * MemoryConstants::megaByte; allocData.type = GraphicsAllocation::AllocationType::BUFFER; allocData.rootDeviceIndex = rootDeviceIndex; auto allocation = memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status); @@ -1248,7 +1250,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenGraphicsAllocationInDevicePoolIsAll EXPECT_NE(0u, gpuAddress); EXPECT_EQ(sizeAlignedTo64KB, allocation->getUnderlyingBufferSize()); EXPECT_EQ(gpuAddress, reinterpret_cast(allocation->getReservedAddressPtr())); - EXPECT_EQ(sizeAlignedTo64KB, allocation->getReservedAddressSize()); + EXPECT_EQ(alignUp(sizeAlignedTo64KB, 2 * MemoryConstants::megaByte), allocation->getReservedAddressSize()); auto drmAllocation = static_cast(allocation); auto bo = drmAllocation->getBO(); diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index ca89514034..3d9e8bf757 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -1946,7 +1946,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemory ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); - EXPECT_EQ(size, graphicsAllocation->getUnderlyingBufferSize()); + EXPECT_EQ(alignUp(size, 2 * MemoryConstants::megaByte), graphicsAllocation->getUnderlyingBufferSize()); EXPECT_EQ(MemoryPool::SystemCpuInaccessible, graphicsAllocation->getMemoryPool()); EXPECT_EQ(this->mock->inputFd, static_cast(handle)); @@ -1958,7 +1958,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemory auto bo = drmAllocation->getBO(); EXPECT_EQ(this->mock->outputHandle, static_cast(bo->peekHandle())); EXPECT_EQ(gpuAddress, bo->peekAddress()); - EXPECT_EQ(size, bo->peekSize()); + EXPECT_EQ(alignUp(size, 2 * MemoryConstants::megaByte), bo->peekSize()); EXPECT_EQ(handle, graphicsAllocation->peekSharedHandle()); diff --git a/shared/source/memory_manager/gfx_partition.cpp b/shared/source/memory_manager/gfx_partition.cpp index 5f9a7d231b..2edfbfe4ca 100644 --- a/shared/source/memory_manager/gfx_partition.cpp +++ b/shared/source/memory_manager/gfx_partition.cpp @@ -34,7 +34,7 @@ GfxPartition::~GfxPartition() { reservedCpuAddressRange = {0}; } -void GfxPartition::Heap::init(uint64_t base, uint64_t size) { +void GfxPartition::Heap::init(uint64_t base, uint64_t size, size_t allocationAlignment) { this->base = base; this->size = size; @@ -43,7 +43,7 @@ void GfxPartition::Heap::init(uint64_t base, uint64_t size) { size -= 2 * GfxPartition::heapGranularity; } - alloc = std::make_unique(base + GfxPartition::heapGranularity, size); + alloc = std::make_unique(base + GfxPartition::heapGranularity, size, allocationAlignment); } void GfxPartition::Heap::initExternalWithFrontWindow(uint64_t base, uint64_t size) { @@ -52,7 +52,7 @@ void GfxPartition::Heap::initExternalWithFrontWindow(uint64_t base, uint64_t siz size -= GfxPartition::heapGranularity; - alloc = std::make_unique(base, size, 0u); + alloc = std::make_unique(base, size, MemoryConstants::pageSize, 0u); } void GfxPartition::Heap::initWithFrontWindow(uint64_t base, uint64_t size, uint64_t frontWindowSize) { @@ -63,14 +63,14 @@ void GfxPartition::Heap::initWithFrontWindow(uint64_t base, uint64_t size, uint6 size -= GfxPartition::heapGranularity; size -= frontWindowSize; - alloc = std::make_unique(base + frontWindowSize, size); + alloc = std::make_unique(base + frontWindowSize, size, MemoryConstants::pageSize); } void GfxPartition::Heap::initFrontWindow(uint64_t base, uint64_t size) { this->base = base; this->size = size; - alloc = std::make_unique(base, size, 0u); + alloc = std::make_unique(base, size, MemoryConstants::pageSize, 0u); } void GfxPartition::freeGpuAddressRange(uint64_t ptr, size_t size) { @@ -191,7 +191,7 @@ bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe // Split HEAP_STANDARD64K among root devices auto gfxStandard64KBSize = alignDown(gfxStandardSize / numRootDevices, GfxPartition::heapGranularity); - heapInit(HeapIndex::HEAP_STANDARD64KB, gfxBase + rootDeviceIndex * gfxStandard64KBSize, gfxStandard64KBSize); + heapInitWithAllocationAlignment(HeapIndex::HEAP_STANDARD64KB, gfxBase + rootDeviceIndex * gfxStandard64KBSize, gfxStandard64KBSize, 2 * MemoryConstants::megaByte); return true; } diff --git a/shared/source/memory_manager/gfx_partition.h b/shared/source/memory_manager/gfx_partition.h index d6c090edeb..9278487dbb 100644 --- a/shared/source/memory_manager/gfx_partition.h +++ b/shared/source/memory_manager/gfx_partition.h @@ -45,7 +45,11 @@ class GfxPartition { MOCKABLE_VIRTUAL bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useExternalFrontWindowPool); void heapInit(HeapIndex heapIndex, uint64_t base, uint64_t size) { - getHeap(heapIndex).init(base, size); + getHeap(heapIndex).init(base, size, MemoryConstants::pageSize); + } + + void heapInitWithAllocationAlignment(HeapIndex heapIndex, uint64_t base, uint64_t size, size_t allocationAlignment) { + getHeap(heapIndex).init(base, size, allocationAlignment); } void heapInitExternalWithFrontWindow(HeapIndex heapIndex, uint64_t base, uint64_t size) { @@ -112,7 +116,7 @@ class GfxPartition { class Heap { public: Heap() = default; - void init(uint64_t base, uint64_t size); + void init(uint64_t base, uint64_t size, size_t allocationAlignment); void initExternalWithFrontWindow(uint64_t base, uint64_t size); void initWithFrontWindow(uint64_t base, uint64_t size, uint64_t frontWindowSize); void initFrontWindow(uint64_t base, uint64_t size); diff --git a/shared/source/utilities/heap_allocator.h b/shared/source/utilities/heap_allocator.h index df489e3f29..70d554f7f2 100644 --- a/shared/source/utilities/heap_allocator.h +++ b/shared/source/utilities/heap_allocator.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -26,10 +26,13 @@ bool operator<(const HeapChunk &hc1, const HeapChunk &hc2); class HeapAllocator { public: - HeapAllocator(uint64_t address, uint64_t size) : HeapAllocator(address, size, 4 * MemoryConstants::megaByte) { + HeapAllocator(uint64_t address, uint64_t size) : HeapAllocator(address, size, MemoryConstants::pageSize) { } - HeapAllocator(uint64_t address, uint64_t size, size_t threshold) : size(size), availableSize(size), sizeThreshold(threshold) { + HeapAllocator(uint64_t address, uint64_t size, size_t allocationAlignment) : HeapAllocator(address, size, allocationAlignment, 4 * MemoryConstants::megaByte) { + } + + HeapAllocator(uint64_t address, uint64_t size, size_t allocationAlignment, size_t threshold) : size(size), availableSize(size), allocationAlignment(allocationAlignment), sizeThreshold(threshold) { pLeftBound = address; pRightBound = address + size; freedChunksBig.reserve(10); @@ -123,8 +126,8 @@ class HeapAllocator { uint64_t availableSize; uint64_t pLeftBound; uint64_t pRightBound; + size_t allocationAlignment; const size_t sizeThreshold; - size_t allocationAlignment = MemoryConstants::pageSize; std::vector freedChunksSmall; std::vector freedChunksBig; diff --git a/shared/test/unit_test/utilities/heap_allocator_tests.cpp b/shared/test/unit_test/utilities/heap_allocator_tests.cpp index 73042a2ca3..b71e80fa84 100644 --- a/shared/test/unit_test/utilities/heap_allocator_tests.cpp +++ b/shared/test/unit_test/utilities/heap_allocator_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,10 +17,12 @@ using namespace NEO; const size_t sizeThreshold = 16 * 4096; +const size_t allocationAlignment = MemoryConstants::pageSize; class HeapAllocatorUnderTest : public HeapAllocator { public: - HeapAllocatorUnderTest(uint64_t address, uint64_t size, size_t threshold) : HeapAllocator(address, size, threshold) {} + HeapAllocatorUnderTest(uint64_t address, uint64_t size, size_t alignment, size_t threshold) : HeapAllocator(address, size, alignment, threshold) {} + HeapAllocatorUnderTest(uint64_t address, uint64_t size, size_t alignment) : HeapAllocator(address, size, alignment) {} HeapAllocatorUnderTest(uint64_t address, uint64_t size) : HeapAllocator(address, size) {} uint64_t getLeftBound() const { return this->pLeftBound; } @@ -41,7 +43,14 @@ class HeapAllocatorUnderTest : public HeapAllocator { using HeapAllocator::allocationAlignment; }; -TEST(HeapAllocatorTest, WhenHeapAllocatorIsCreatedThenThresholdIsSet) { +TEST(HeapAllocatorTest, WhenHeapAllocatorIsCreatedWithAlignmentThenAlignmentIsSet) { + uint64_t ptrBase = 0x100000llu; + size_t size = 1024 * 4096; + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment); + EXPECT_EQ(MemoryConstants::pageSize, heapAllocator->allocationAlignment); +} + +TEST(HeapAllocatorTest, WhenHeapAllocatorIsCreatedThenThresholdAndAlignmentIsSet) { uint64_t ptrBase = 0x100000llu; size_t size = 1024 * 4096; auto heapAllocator = std::make_unique(ptrBase, size); @@ -68,7 +77,7 @@ TEST(HeapAllocatorTest, WhenAllocatingThenUsageStatisticsAreUpdated) { TEST(HeapAllocatorTest, GivenExactSizeChunkInFreedChunksWhenGetIsCalledThenChunkIsReturned) { uint64_t ptrBase = 0x100000llu; size_t size = 1024 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); std::vector freedChunks; uint64_t ptrFreed = 0x101000llu; @@ -84,7 +93,7 @@ TEST(HeapAllocatorTest, GivenExactSizeChunkInFreedChunksWhenGetIsCalledThenChunk TEST(HeapAllocatorTest, GivenOnlySmallerSizeChunksInFreedChunksWhenGetIsCalledThenNullptrIsReturned) { uint64_t ptrBase = 0x100000llu; size_t size = 1024 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); std::vector freedChunks; @@ -109,7 +118,7 @@ TEST(HeapAllocatorTest, GivenOnlyBiggerSizeChunksInFreedChunksWhenGetIsCalledThe size_t size = 1024 * 4096; auto pUpperBound = ptrBase + size; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); std::vector freedChunks; uint64_t ptrExpected = 0llu; @@ -140,7 +149,7 @@ TEST(HeapAllocatorTest, GivenOnlyMoreThanTwiceBiggerSizeChunksInFreedChunksWhenG size_t size = 1024 * 4096; auto pLowerBound = ptrBase; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); std::vector freedChunks; uint64_t ptrExpected = 0llu; @@ -171,7 +180,7 @@ TEST(HeapAllocatorTest, GivenStoredChunkAdjacentToLeftBoundaryOfIncomingChunkWhe size_t size = 1024 * 4096; auto pLowerBound = ptrBase; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); std::vector freedChunks; uint64_t ptrExpected = 0llu; @@ -206,7 +215,7 @@ TEST(HeapAllocatorTest, GivenStoredChunkAdjacentToRightBoundaryOfIncomingChunkWh size_t size = 1024 * 4096; auto pLowerBound = ptrBase; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); std::vector freedChunks; uint64_t ptrExpected = 0llu; @@ -244,7 +253,7 @@ TEST(HeapAllocatorTest, GivenStoredChunkNotAdjacentToIncomingChunkWhenStoreIsCal size_t size = 1024 * 4096; auto pLowerBound = ptrBase; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); std::vector freedChunks; @@ -271,7 +280,7 @@ TEST(HeapAllocatorTest, GivenStoredChunkNotAdjacentToIncomingChunkWhenStoreIsCal TEST(HeapAllocatorTest, WhenAllocatingThenEntryIsAddedToMap) { uint64_t ptrBase = 0x100000llu; size_t size = 1024 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); size_t ptrSize = 4096; uint64_t ptr = heapAllocator->allocate(ptrSize); @@ -292,7 +301,7 @@ TEST(HeapAllocatorTest, WhenFreeingThenEntryIsRemovedFromMapAndSpaceMadeAvailabl auto pLeftBound = ptrBase; auto pRightBound = pLeftBound + size; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); size_t ptrSize = 4096; uint64_t ptr = heapAllocator->allocate(ptrSize); @@ -325,7 +334,7 @@ TEST(HeapAllocatorTest, WhenAllocatingMultipleThenEachAllocationIsDistinct) { size_t doubleAllocSize = 4096 * 2; for (uint32_t i = 0u; i < 2u; i++) { - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); doubleAllocSize = allocSize * 2; auto pLeftBound = ptrBase; auto pRightBound = pLeftBound + size; @@ -366,7 +375,7 @@ TEST(HeapAllocatorTest, WhenAllocatingMultipleThenEachAllocationIsDistinct) { TEST(HeapAllocatorTest, GivenNoSpaceLeftWhenAllocatingThenZeroIsReturned) { uint64_t ptrBase = 0x100000llu; size_t size = 1024 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); size_t ptrSize = 4096; uint64_t ptr1 = heapAllocator->allocate(ptrSize); @@ -388,7 +397,7 @@ TEST(HeapAllocatorTest, GivenNoSpaceLeftWhenAllocatingThenZeroIsReturned) { TEST(HeapAllocatorTest, GivenReverseOrderWhenFreeingThenHeapAllocatorStateIsCorrect) { uint64_t ptrBase = 0x100000llu; size_t size = 1024 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); auto pLeftBound = ptrBase; auto pRightBound = pLeftBound + size; @@ -422,7 +431,7 @@ TEST(HeapAllocatorTest, GivenReverseOrderWhenFreeingThenHeapAllocatorStateIsCorr TEST(HeapAllocatorTest, GivenNoMemoryLeftWhenAllocatingThenZeroIsReturned) { uint64_t ptrBase = 0x100000llu; size_t size = 0; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); size_t ptrSize = 4096; uint64_t ptr = heapAllocator->allocate(ptrSize); @@ -434,7 +443,7 @@ TEST(HeapAllocatorTest, GivenNoMemoryLeftWhenAllocatingThenZeroIsReturned) { TEST(HeapAllocatorTest, GivenSizeGreaterThanMemoryLeftWhenAllocatingThenZeroIsReturned) { uint64_t ptrBase = 0x100000llu; size_t size = 11 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, 3 * 4096); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, 3 * 4096); size_t remainingSize = size; // first small succeeds @@ -477,7 +486,7 @@ TEST(HeapAllocatorTest, GivenSizeGreaterThanMemoryLeftWhenAllocatingThenZeroIsRe TEST(HeapAllocatorTest, GivenNullWhenFreeingThenNothingHappens) { uint64_t ptrBase = 0x100000llu; - auto heapAllocator = std::make_unique(ptrBase, sizeThreshold, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, sizeThreshold, allocationAlignment, sizeThreshold); heapAllocator->free(0llu, 0); @@ -488,7 +497,7 @@ TEST(HeapAllocatorTest, GivenNullWhenFreeingThenNothingHappens) { TEST(HeapAllocatorTest, WhenFreeingThenMemoryAvailableForAllocation) { uint64_t ptrBase = 0x100000llu; size_t size = 1024 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); auto pLeftBound = ptrBase; auto pRightBound = pLeftBound + size; @@ -538,7 +547,7 @@ TEST(HeapAllocatorTest, WhenFreeingThenMemoryAvailableForAllocation) { TEST(HeapAllocatorTest, WhenFreeingChunkThenMemoryAvailableForAllocation) { uint64_t ptrBase = 0x100000llu; size_t size = 1024 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); auto pLeftBound = ptrBase; auto pRightBound = pLeftBound + size; @@ -604,7 +613,7 @@ TEST(HeapAllocatorTest, WhenFreeingChunkThenMemoryAvailableForAllocation) { TEST(HeapAllocatorTest, GivenSmallAllocationGreaterThanAvailableSizeWhenAllocatingThenZeroIsReturned) { uint64_t ptrBase = 0x100000llu; size_t size = 1024 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); size_t ptrSize1 = size - 4096; uint64_t ptr1 = heapAllocator->allocate(ptrSize1); @@ -621,7 +630,7 @@ TEST(HeapAllocatorTest, GivenSmallAllocationGreaterThanAvailableSizeWhenAllocati TEST(HeapAllocatorTest, GivenBigAllocationGreaterThanAvailableSizeWhenAllocatingThenZeroIsReturned) { uint64_t ptrBase = 0x100000llu; size_t size = 1024 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, sizeThreshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, sizeThreshold); size_t ptrSize1 = 8192; uint64_t ptr1 = heapAllocator->allocate(ptrSize1); @@ -669,7 +678,7 @@ TEST(HeapAllocatorTest, WhenMemoryIsAllocatedThenAllocationsDoNotOverlap) { size_t bigAllocationThreshold = (512 + 256) * reqAlignment; memset(pBasePtr, 0, static_cast(allocatorSize)); - auto heapAllocator = std::make_unique(basePtr, allocatorSize, bigAllocationThreshold); + auto heapAllocator = std::make_unique(basePtr, allocatorSize, allocationAlignment, bigAllocationThreshold); heapAllocator->allocationAlignment = reqAlignment; for (uint32_t i = 0; i < maxIndex; i++) { @@ -732,7 +741,7 @@ TEST(HeapAllocatorTest, GivenLargeAllocationsWhenFreeingThenSpaceIsDefragmented) size_t doubleallocSize = 2 * allocSize; size_t tripleallocSize = 3 * allocSize; - auto heapAllocator = std::make_unique(ptrBase, size, threshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, threshold); std::vector &freedChunks = heapAllocator->getFreedChunksBig(); @@ -789,7 +798,7 @@ TEST(HeapAllocatorTest, GivenSmallAllocationsWhenFreeingThenSpaceIsDefragmented) size_t allocSize = MemoryConstants::pageSize; size_t doubleallocSize = 2 * allocSize; - auto heapAllocator = std::make_unique(ptrBase, size, threshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, threshold); std::vector &freedChunks = heapAllocator->getFreedChunksSmall(); @@ -840,7 +849,7 @@ TEST(HeapAllocatorTest, Given10SmallAllocationsWhenFreedInTheSameOrderThenLastCh size_t size = 1024 * 4096; size_t threshold = 2 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, threshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, threshold); std::vector &freedChunks = heapAllocator->getFreedChunksSmall(); @@ -876,7 +885,7 @@ TEST(HeapAllocatorTest, Given10SmallAllocationsWhenMergedToBigAllocatedAsSmallSp size_t threshold = 4 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, threshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, threshold); std::vector &freedChunksSmall = heapAllocator->getFreedChunksSmall(); std::vector &freedChunksBig = heapAllocator->getFreedChunksBig(); @@ -937,7 +946,7 @@ TEST(HeapAllocatorTest, Given10SmallAllocationsWhenMergedToBigAllocatedAsSmallNo size_t threshold = 4 * 4096; - auto heapAllocator = std::make_unique(ptrBase, size, threshold); + auto heapAllocator = std::make_unique(ptrBase, size, allocationAlignment, threshold); std::vector &freedChunksSmall = heapAllocator->getFreedChunksSmall(); std::vector &freedChunksBig = heapAllocator->getFreedChunksBig();