Skip to content

Commit 2fbc1f6

Browse files
Choose alignment as next power of 2 for HEAP_EXTENDED allocations.
This way we will get as big pages as possible without leftovers. Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
1 parent 7ff258f commit 2fbc1f6

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,7 @@ uint64_t getGpuAddress(const AlignmentSelector &alignmentSelector, HeapAssigner
13451345
default:
13461346
AlignmentSelector::CandidateAlignment alignment = alignmentSelector.selectAlignment(sizeAllocated);
13471347
if (gfxPartition->getHeapLimit(HeapIndex::HEAP_EXTENDED) > 0 && !resource48Bit) {
1348+
alignment.alignment = Math::nextPowerOfTwo(sizeAllocated);
13481349
alignment.heap = HeapIndex::HEAP_EXTENDED;
13491350
}
13501351
gpuAddress = gmmHelper.canonize(gfxPartition->heapAllocateWithCustomAlignment(alignment.heap, sizeAllocated, alignment.alignment));

shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4897,6 +4897,38 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenOversize
48974897
memoryManager->freeGraphicsMemory(allocation);
48984898
}
48994899

4900+
TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenHeapExtendedWhenAllocationsAreMadeTheyAreAlignedToNextPowerOfTwo) {
4901+
if (!memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_EXTENDED)) {
4902+
GTEST_SKIP();
4903+
}
4904+
4905+
auto size = 16 * MemoryConstants::megaByte;
4906+
4907+
auto status = MemoryManager::AllocationStatus::Error;
4908+
AllocationData allocData;
4909+
allocData.size = size;
4910+
allocData.type = AllocationType::BUFFER;
4911+
allocData.rootDeviceIndex = rootDeviceIndex;
4912+
auto allocation = memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status);
4913+
EXPECT_EQ(MemoryManager::AllocationStatus::Success, status);
4914+
ASSERT_NE(nullptr, allocation);
4915+
EXPECT_EQ(allocData.size, allocation->getUnderlyingBufferSize());
4916+
EXPECT_EQ(allocData.size, static_cast<DrmAllocation *>(allocation)->getBO()->peekSize());
4917+
EXPECT_TRUE(allocation->getGpuAddress() % size == 0u);
4918+
4919+
size = 32 * MemoryConstants::megaByte;
4920+
allocData.size = size;
4921+
auto allocation2 = memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status);
4922+
EXPECT_EQ(MemoryManager::AllocationStatus::Success, status);
4923+
ASSERT_NE(nullptr, allocation2);
4924+
EXPECT_EQ(allocData.size, allocation2->getUnderlyingBufferSize());
4925+
EXPECT_EQ(allocData.size, static_cast<DrmAllocation *>(allocation2)->getBO()->peekSize());
4926+
EXPECT_TRUE(allocation2->getGpuAddress() % size == 0u);
4927+
4928+
memoryManager->freeGraphicsMemory(allocation);
4929+
memoryManager->freeGraphicsMemory(allocation2);
4930+
}
4931+
49004932
struct DrmMemoryManagerToTestCopyMemoryToAllocationBanks : public DrmMemoryManager {
49014933
DrmMemoryManagerToTestCopyMemoryToAllocationBanks(ExecutionEnvironment &executionEnvironment, size_t lockableLocalMemorySize)
49024934
: DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment) {

0 commit comments

Comments
 (0)