Skip to content

Commit 630a7e1

Browse files
Allow to reuse just completed allocation
Change-Id: I7c1ab153178b79348d49209ca09478543d35e197 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 337d374 commit 630a7e1

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

runtime/memory_manager/internal_allocation_storage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ GraphicsAllocation *AllocationsList::detachAllocationImpl(GraphicsAllocation *,
8686
auto currentTagValue = *req->csrTagAddress;
8787
if ((req->internalAllocationRequired == curr->is32BitAllocation) &&
8888
(curr->getUnderlyingBufferSize() >= req->requiredMinimalSize) &&
89-
((currentTagValue > curr->getTaskCount(req->contextId)) || (curr->getTaskCount(req->contextId) == 0))) {
89+
(currentTagValue >= curr->getTaskCount(req->contextId))) {
9090
return removeOneImpl(curr, nullptr);
9191
}
9292
curr = curr->next;

unit_tests/memory_manager/internal_allocation_storage_tests.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ TEST_F(InternalAllocationStorageTest, whenObtainAllocationFromEmptyReuseListThen
9292
EXPECT_EQ(nullptr, allocation2);
9393
}
9494

95-
TEST_F(InternalAllocationStorageTest, whenAllocationIsStoredAsReusableAndNotUsedThenCanBeObtained) {
95+
TEST_F(InternalAllocationStorageTest, whenCompletedAllocationIsStoredAsReusableAndThenCanBeObtained) {
9696
void *host_ptr = (void *)0x1234;
9797
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
9898
EXPECT_NE(nullptr, allocation);
@@ -102,7 +102,26 @@ TEST_F(InternalAllocationStorageTest, whenAllocationIsStoredAsReusableAndNotUsed
102102

103103
auto *hwTag = csr->getTagAddress();
104104

105-
*hwTag = 3u;
105+
*hwTag = 2u;
106+
auto reusedAllocation = storage->obtainReusableAllocation(1, false).release();
107+
108+
EXPECT_EQ(allocation, reusedAllocation);
109+
EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty());
110+
memoryManager->freeGraphicsMemory(allocation);
111+
}
112+
113+
TEST_F(InternalAllocationStorageTest, whenNotUsedAllocationIsStoredAsReusableAndThenCanBeObtained) {
114+
void *host_ptr = (void *)0x1234;
115+
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
116+
EXPECT_NE(nullptr, allocation);
117+
EXPECT_FALSE(allocation->peekWasUsed());
118+
EXPECT_EQ(0u, csr->peekTaskCount());
119+
*csr->getTagAddress() = 0; // initial hw tag for dll
120+
121+
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
122+
EXPECT_EQ(0u, allocation->getTaskCount(0u));
123+
EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty());
124+
106125
auto reusedAllocation = storage->obtainReusableAllocation(1, false).release();
107126

108127
EXPECT_EQ(allocation, reusedAllocation);
@@ -203,4 +222,4 @@ TEST_F(InternalAllocationStorageTest, givenInternalAllocationWhenItIsPutOnReusab
203222
EXPECT_EQ(allocation, internalAllocation.get());
204223
internalAllocation.release();
205224
memoryManager->freeGraphicsMemory(allocation);
206-
}
225+
}

0 commit comments

Comments
 (0)