Skip to content

Commit

Permalink
Fix Rene's deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
chillenzer committed Aug 2, 2024
1 parent 5a696ca commit 39373e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/include/mallocMC/creationPolicies/Scatter/AccessBlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,22 @@ namespace mallocMC::CreationPolicies::ScatterAlloc
uint32_t& chunkSizeCache) -> bool
{
bool appropriate = false;
if(enterPage(acc, index, numBytes))
auto oldFilling = enterPage(acc, index, numBytes);

// At this point, we're only testing against our desired `numBytes`. Due to the `wastefactor` the actual
// `chunkSize` of the page might be larger and, thus, the actual `numChunks` might be smaller than what
// we're testing for here. But if this fails already, we save one atomic.
if(oldFilling < MyPageInterpretation::numChunks(numBytes))
{
uint32_t oldChunkSize = alpaka::atomicCas(acc, &pageTable._chunkSizes[index], 0U, numBytes);
appropriate = (oldChunkSize == 0U || isInAllowedRange(oldChunkSize, numBytes));
chunkSizeCache = std::max(oldChunkSize, numBytes);
chunkSizeCache = oldChunkSize == 0U ? numBytes : oldChunkSize;

// Now that we know the real chunk size of the page, we can check again if our previous assessment was
// correct.
if(oldFilling < MyPageInterpretation::numChunks(chunkSizeCache))
{
appropriate = isInAllowedRange(chunkSizeCache, numBytes);
}
}
if(not appropriate)
{
Expand All @@ -431,12 +442,12 @@ namespace mallocMC::CreationPolicies::ScatterAlloc
ALPAKA_FN_INLINE ALPAKA_FN_ACC auto enterPage(
TAcc const& acc,
uint32_t const pageIndex,
uint32_t const expectedChunkSize) -> bool
uint32_t const expectedChunkSize) -> uint32_t
{
auto const oldFilling = alpaka::atomicAdd(acc, &pageTable._fillingLevels[pageIndex], 1U);
// We assume that this page has the correct chunk size. If not, the chunk size is either 0 (and oldFilling
// must be 0, too) or the next check will fail.
return oldFilling < MyPageInterpretation::numChunks(expectedChunkSize);
return oldFilling;
}

template<typename TAcc>
Expand Down
1 change: 1 addition & 0 deletions tests/unit/AccessBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ TEMPLATE_LIST_TEST_CASE("AccessBlock", "", BlockAndPageSizes)
{
uint32_t const arbitraryValue = 42;
auto* ptr = static_cast<uint32_t*>(accessBlock.create(accSerial, chunkSize));
REQUIRE(ptr != nullptr);
*ptr = arbitraryValue;
CHECK(*ptr == arbitraryValue);
}
Expand Down

0 comments on commit 39373e3

Please sign in to comment.