Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gpgmm/common/SlabMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace gpgmm {
Slab* freeSlab = cache->FreeList.head()->value();
ASSERT(freeSlab != nullptr);

if (freeSlab->Allocation->GetSize() >= slabSize) {
if (freeSlab->Allocation && freeSlab->Allocation->GetSize() >= slabSize) {
return freeSlab->Allocation->GetSize();
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/tests/unittests/SlabMemoryAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,26 @@ TEST_F(SlabCacheAllocatorTests, SlabPrefetch) {
}
}

TEST_F(SlabCacheAllocatorTests, CachedMemory) {
constexpr uint64_t kBlockSize = 32;
constexpr uint64_t kMaxSlabSize = 512;

SlabCacheAllocator allocator(
kMaxSlabSize, kDefaultSlabSize, kDefaultSlabAlignment, kDefaultSlabFragmentationLimit,
/*prefetchSlab*/ true, kNoSlabGrowthFactor, std::make_unique<DummyMemoryAllocator>());

// Re-requesting same size from cached memory should always succeed.
MemoryAllocationRequest request = CreateBasicRequest(kBlockSize, 1);
request.AlwaysCacheSize = true;

std::unique_ptr<MemoryAllocation> allocation = allocator.TryAllocateMemory(request);
ASSERT_NE(allocation, nullptr);
allocator.DeallocateMemory(std::move(allocation));

request.AvailableForAllocation = 0;
EXPECT_EQ(allocator.TryAllocateMemory(request), nullptr);
}

// Verify creating more slabs than memory available fails.
TEST_F(SlabCacheAllocatorTests, OutOfMemory) {
SlabCacheAllocator allocator(kDefaultSlabSize, kDefaultSlabSize, kDefaultSlabAlignment,
Expand Down