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
4 changes: 4 additions & 0 deletions src/gpgmm/BuddyMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ namespace gpgmm {
return result;
}

const char* BuddyMemoryAllocator::GetTypename() const {
return "BuddyMemoryAllocator";
}

uint64_t BuddyMemoryAllocator::GetBuddyMemorySizeForTesting() const {
std::lock_guard<std::mutex> lock(mMutex);

Expand Down
1 change: 1 addition & 0 deletions src/gpgmm/BuddyMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace gpgmm {
uint64_t GetMemorySize() const override;
uint64_t GetMemoryAlignment() const override;
MEMORY_ALLOCATOR_INFO GetInfo() const override;
const char* GetTypename() const override;

uint64_t GetBuddyMemorySizeForTesting() const;

Expand Down
31 changes: 10 additions & 21 deletions src/gpgmm/ConditionalMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,21 @@ namespace gpgmm {
}
}

MEMORY_ALLOCATOR_INFO ConditionalMemoryAllocator::GetInfo() const {
std::lock_guard<std::mutex> lock(mMutex);
void ConditionalMemoryAllocator::DeallocateMemory(
std::unique_ptr<MemoryAllocation> allocation) {
// ConditionalMemoryAllocator cannot allocate memory itself, so it must not deallocate.
allocation->GetAllocator()->DeallocateMemory(std::move(allocation));
}

MEMORY_ALLOCATOR_INFO ConditionalMemoryAllocator::GetInfo() const {
MEMORY_ALLOCATOR_INFO result = {};
{
const MEMORY_ALLOCATOR_INFO& info = mFirstAllocator->GetInfo();
result.FreeMemoryUsage += info.FreeMemoryUsage;
result.UsedBlockCount += info.UsedBlockCount;
result.UsedMemoryUsage += info.UsedMemoryUsage;
result.UsedMemoryCount += info.UsedMemoryCount;
}
{
const MEMORY_ALLOCATOR_INFO& info = mSecondAllocator->GetInfo();
result.FreeMemoryUsage += info.FreeMemoryUsage;
result.UsedBlockCount += info.UsedBlockCount;
result.UsedMemoryUsage += info.UsedMemoryUsage;
result.UsedMemoryCount += info.UsedMemoryCount;
}

result += mFirstAllocator->GetInfo();
result += mSecondAllocator->GetInfo();
return result;
}

void ConditionalMemoryAllocator::DeallocateMemory(
std::unique_ptr<MemoryAllocation> allocation) {
// ConditionalMemoryAllocator cannot allocate memory itself, so it must not deallocate.
allocation->GetAllocator()->DeallocateMemory(std::move(allocation));
const char* ConditionalMemoryAllocator::GetTypename() const {
return "ConditionalMemoryAllocator";
}

MemoryAllocator* ConditionalMemoryAllocator::GetFirstAllocatorForTesting() const {
Expand Down
1 change: 1 addition & 0 deletions src/gpgmm/ConditionalMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace gpgmm {
void DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) override;

MEMORY_ALLOCATOR_INFO GetInfo() const override;
const char* GetTypename() const override;

MemoryAllocator* GetFirstAllocatorForTesting() const;
MemoryAllocator* GetSecondAllocatorForTesting() const;
Expand Down
4 changes: 4 additions & 0 deletions src/gpgmm/MemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,8 @@ namespace gpgmm {
return mInfo;
}

const char* MemoryAllocator::GetTypename() const {
return "MemoryAllocator";
}

} // namespace gpgmm
2 changes: 2 additions & 0 deletions src/gpgmm/MemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ namespace gpgmm {
// Should be overridden when a child allocator or block allocator is used.
virtual MEMORY_ALLOCATOR_INFO GetInfo() const;

virtual const char* GetTypename() const;

protected:
// Combine TryAllocateBlock and TryAllocateMemory into a single call so a partial
// or uninitalized memory allocation cannot be created. If memory cannot be allocated for
Expand Down
4 changes: 4 additions & 0 deletions src/gpgmm/PooledMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ namespace gpgmm {
return mPool->GetMemorySize();
}

const char* PooledMemoryAllocator::GetTypename() const {
return "PooledMemoryAllocator";
}

} // namespace gpgmm
1 change: 1 addition & 0 deletions src/gpgmm/PooledMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace gpgmm {
bool prefetchMemory) override;
void DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) override;
uint64_t GetMemorySize() const override;
const char* GetTypename() const override;

private:
MemoryPool* const mPool;
Expand Down
4 changes: 4 additions & 0 deletions src/gpgmm/SegmentedMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,8 @@ namespace gpgmm {
return count;
}

const char* SegmentedMemoryAllocator::GetTypename() const {
return "SegmentedMemoryAllocator";
}

} // namespace gpgmm
1 change: 1 addition & 0 deletions src/gpgmm/SegmentedMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace gpgmm {
void DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) override;
void ReleaseMemory() override;
uint64_t GetMemoryAlignment() const override;
const char* GetTypename() const override;

uint64_t GetSegmentSizeForTesting() const;

Expand Down
4 changes: 4 additions & 0 deletions src/gpgmm/SlabMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ namespace gpgmm {
return GetFirstChild()->GetMemorySize();
}

const char* SlabCacheAllocator::GetTypename() const {
return "SlabCacheAllocator";
}

uint64_t SlabCacheAllocator::GetSlabCacheSizeForTesting() const {
std::lock_guard<std::mutex> lock(mMutex);

Expand Down
2 changes: 2 additions & 0 deletions src/gpgmm/SlabMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ namespace gpgmm {

uint64_t GetMemorySize() const override;

const char* GetTypename() const override;

uint64_t GetSlabCacheSizeForTesting() const;

private:
Expand Down
4 changes: 4 additions & 0 deletions src/gpgmm/StandaloneMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ namespace gpgmm {
result += GetFirstChild()->GetInfo();
return result;
}

const char* StandaloneMemoryAllocator::GetTypename() const {
return "StandaloneMemoryAllocator";
}
} // namespace gpgmm
1 change: 1 addition & 0 deletions src/gpgmm/StandaloneMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace gpgmm {
void DeallocateMemory(std::unique_ptr<MemoryAllocation> subAllocation) override;

MEMORY_ALLOCATOR_INFO GetInfo() const override;
const char* GetTypename() const override;
};

} // namespace gpgmm
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ namespace gpgmm { namespace d3d12 {
if (allocation == nullptr) {
DebugEvent("ResourceAllocator.TryAllocateResource",
ALLOCATOR_MESSAGE_ID_RESOURCE_ALLOCATION_FAILED)
<< "Resource memory could not be allocated.";
<< std::string(allocator->GetTypename()) + " failed to allocate memory.";

return E_FAIL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ namespace gpgmm { namespace d3d12 {
// Return the current allocator usage.
RESOURCE_ALLOCATOR_INFO GetInfo() const override;

const char* GetTypename() const;
const char* GetTypename() const override;

private:
friend BufferAllocator;
Expand Down