fix: remove incorrect code

- freed pointer cannot overlap with freed chunks, therefore there is no way
to merge it with freed chunks if they overlap

Signed-off-by: Mrozek, Michal <michal.mrozek@intel.com>
This commit is contained in:
Mrozek, Michal 2024-11-05 17:49:58 +00:00 committed by Compute-Runtime-Automation
parent bccd26413b
commit 2febf0597e
2 changed files with 1 additions and 33 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -83,13 +83,6 @@ class HeapAllocator {
freedChunk.size += size;
return;
}
if ((freedChunk.ptr + freedChunk.size) == (ptr + size)) {
if (ptr < freedChunk.ptr) {
freedChunk.ptr = ptr;
freedChunk.size = size;
return;
}
}
}
freedChunks.emplace_back(ptr, size);

View File

@ -325,31 +325,6 @@ TEST(HeapAllocatorTest, GivenStoredChunkNotAdjacentToIncomingChunkWhenStoreIsCal
EXPECT_EQ(sizeToStore, freedChunks[2].size);
}
TEST(HeapAllocatorTest, GivenStoredChunkExpandableByIncomingChunkWhenStoreIsCalledThenChunksAreMerged) {
uint64_t ptrBase = 0x100000llu;
size_t size = 1024 * 4096;
auto heapAllocator = std::make_unique<HeapAllocatorUnderTest>(ptrBase, size, allocationAlignment, sizeThreshold);
std::vector<HeapChunk> freedChunks;
freedChunks.emplace_back(0x100000llu, 4096);
freedChunks.emplace_back(0x103000llu, 4096);
EXPECT_EQ(2u, freedChunks.size());
uint64_t ptrToStore = 0x102000llu;
size_t sizeToStore = 2 * 4096;
heapAllocator->storeInFreedChunks(ptrToStore, sizeToStore, freedChunks);
EXPECT_EQ(2u, freedChunks.size());
auto ptrReturned = heapAllocator->getFromFreedChunks(2 * 4096, freedChunks, allocationAlignment);
EXPECT_EQ(0x102000llu, ptrReturned);
EXPECT_EQ(1u, freedChunks.size());
}
TEST(HeapAllocatorTest, WhenAllocatingThenEntryIsAddedToMap) {
uint64_t ptrBase = 0x100000llu;
size_t size = 1024 * 4096;