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/fuzzers/D3D12ResidencyManagerFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {

// Keep allocating until we reach the budget.
uint64_t memoryUnderBudget = GetBudgetLeft(gResidencyManager.Get(), bufferMemorySegment);
while (gResourceAllocator->GetInfo().UsedMemoryUsage + kBufferMemorySize < memoryUnderBudget) {
while (gResourceAllocator->GetStats().UsedMemoryUsage + kBufferMemorySize < memoryUnderBudget) {
ComPtr<gpgmm::d3d12::IResourceAllocation> allocation;
if (FAILED(gResourceAllocator->CreateResource({}, bufferDesc, D3D12_RESOURCE_STATE_COMMON,
nullptr, &allocation))) {
Expand Down
14 changes: 7 additions & 7 deletions src/gpgmm/common/BuddyMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ namespace gpgmm {
subAllocation);

MemoryBlock* block = subAllocation->GetBlock();
mInfo.UsedBlockCount++;
mInfo.UsedBlockUsage += block->Size;
mStats.UsedBlockCount++;
mStats.UsedBlockUsage += block->Size;

// Memory allocation offset is always memory-relative.
const uint64_t memoryOffset = block->Offset % mMemorySize;
Expand All @@ -104,8 +104,8 @@ namespace gpgmm {

ASSERT(subAllocation != nullptr);

mInfo.UsedBlockCount--;
mInfo.UsedBlockUsage -= subAllocation->GetSize();
mStats.UsedBlockCount--;
mStats.UsedBlockUsage -= subAllocation->GetSize();

const uint64_t memoryIndex = GetMemoryIndex(subAllocation->GetBlock()->Offset);

Expand All @@ -132,11 +132,11 @@ namespace gpgmm {
return mMemoryAlignment;
}

MemoryAllocatorInfo BuddyMemoryAllocator::GetInfo() const {
MemoryAllocatorStats BuddyMemoryAllocator::GetStats() const {
std::lock_guard<std::mutex> lock(mMutex);

MemoryAllocatorInfo result = mInfo;
const MemoryAllocatorInfo& memoryInfo = GetNextInChain()->GetInfo();
MemoryAllocatorStats result = mStats;
const MemoryAllocatorStats& memoryInfo = GetNextInChain()->GetStats();
result.UsedMemoryCount = memoryInfo.UsedMemoryCount;
result.UsedMemoryUsage = memoryInfo.UsedMemoryUsage;
result.FreeMemoryUsage = memoryInfo.FreeMemoryUsage;
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/BuddyMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace gpgmm {

uint64_t GetMemorySize() const override;
uint64_t GetMemoryAlignment() const override;
MemoryAllocatorInfo GetInfo() const override;
MemoryAllocatorStats GetStats() const override;
const char* GetTypename() const override;

private:
Expand Down
8 changes: 4 additions & 4 deletions src/gpgmm/common/ConditionalMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ namespace gpgmm {
allocation->GetAllocator()->DeallocateMemory(std::move(allocation));
}

MemoryAllocatorInfo ConditionalMemoryAllocator::GetInfo() const {
MemoryAllocatorInfo result = {};
result += mFirstAllocator->GetInfo();
result += mSecondAllocator->GetInfo();
MemoryAllocatorStats ConditionalMemoryAllocator::GetStats() const {
MemoryAllocatorStats result = {};
result += mFirstAllocator->GetStats();
result += mSecondAllocator->GetStats();
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/ConditionalMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace gpgmm {
const MemoryAllocationRequest& request) override;
void DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) override;

MemoryAllocatorInfo GetInfo() const override;
MemoryAllocatorStats GetStats() const override;
const char* GetTypename() const override;

MemoryAllocator* GetFirstAllocatorForTesting() const;
Expand Down
14 changes: 7 additions & 7 deletions src/gpgmm/common/DedicatedMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace gpgmm {
std::unique_ptr<MemoryAllocation> allocation;
GPGMM_TRY_ASSIGN(GetNextInChain()->TryAllocateMemory(request), allocation);

mInfo.UsedBlockCount++;
mInfo.UsedBlockUsage += allocation->GetSize();
mStats.UsedBlockCount++;
mStats.UsedBlockUsage += allocation->GetSize();

return std::make_unique<MemoryAllocation>(
this, allocation->GetMemory(), /*offset*/ 0, allocation->GetMethod(),
Expand All @@ -49,17 +49,17 @@ namespace gpgmm {
std::lock_guard<std::mutex> lock(mMutex);

MemoryBlock* block = allocation->GetBlock();
mInfo.UsedBlockCount--;
mInfo.UsedBlockUsage -= block->Size;
mStats.UsedBlockCount--;
mStats.UsedBlockUsage -= block->Size;

SafeDelete(block);
GetNextInChain()->DeallocateMemory(std::move(allocation));
}

MemoryAllocatorInfo DedicatedMemoryAllocator::GetInfo() const {
MemoryAllocatorStats DedicatedMemoryAllocator::GetStats() const {
std::lock_guard<std::mutex> lock(mMutex);
MemoryAllocatorInfo result = mInfo;
result += GetNextInChain()->GetInfo();
MemoryAllocatorStats result = mStats;
result += GetNextInChain()->GetStats();
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/DedicatedMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace gpgmm {
void DeallocateMemory(std::unique_ptr<MemoryAllocation> subAllocation) override;
uint64_t GetMemoryAlignment() const override;

MemoryAllocatorInfo GetInfo() const override;
MemoryAllocatorStats GetStats() const override;

private:
const char* GetTypename() const override;
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/JSONSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace gpgmm {
}

// static
JSONDict JSONSerializer::Serialize(const MemoryAllocatorInfo& info) {
JSONDict JSONSerializer::Serialize(const MemoryAllocatorStats& info) {
JSONDict dict;
dict.AddItem("UsedBlockCount", info.UsedBlockCount);
dict.AddItem("UsedMemoryCount", info.UsedMemoryCount);
Expand Down
4 changes: 2 additions & 2 deletions src/gpgmm/common/JSONSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace gpgmm {

// Forward declare common types.
struct MemoryPoolInfo;
struct MemoryAllocatorInfo;
struct MemoryAllocatorStats;
struct MemoryAllocationInfo;
struct MemoryAllocationRequest;
struct EventMessageInfo;
Expand All @@ -30,7 +30,7 @@ namespace gpgmm {
public:
static JSONDict Serialize();
static JSONDict Serialize(const EventMessageInfo& info);
static JSONDict Serialize(const MemoryAllocatorInfo& info);
static JSONDict Serialize(const MemoryAllocatorStats& info);
static JSONDict Serialize(const MemoryAllocationRequest& desc);
static JSONDict Serialize(const MemoryAllocationInfo& info);
static JSONDict Serialize(const MemoryPoolInfo& desc);
Expand Down
16 changes: 8 additions & 8 deletions src/gpgmm/common/MemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ namespace gpgmm {
std::unique_ptr<MemoryAllocation> mAllocation;
};

// MemoryAllocatorInfo
// MemoryAllocatorStats

MemoryAllocatorInfo& MemoryAllocatorInfo::operator+=(const MemoryAllocatorInfo& rhs) {
MemoryAllocatorStats& MemoryAllocatorStats::operator+=(const MemoryAllocatorStats& rhs) {
UsedBlockCount += rhs.UsedBlockCount;
UsedBlockUsage += rhs.UsedBlockUsage;
FreeMemoryUsage += rhs.FreeMemoryUsage;
Expand Down Expand Up @@ -98,10 +98,10 @@ namespace gpgmm {
#if defined(GPGMM_ENABLE_ALLOCATOR_LEAK_CHECKS)
// If memory cannot be reused by a (parent) allocator, ensure no used memory leaked.
if (GetParent() == nullptr) {
ASSERT(mInfo.UsedBlockUsage == 0u);
ASSERT(mInfo.UsedBlockCount == 0u);
ASSERT(mInfo.UsedMemoryCount == 0u);
ASSERT(mInfo.UsedMemoryUsage == 0u);
ASSERT(mStats.UsedBlockUsage == 0u);
ASSERT(mStats.UsedBlockCount == 0u);
ASSERT(mStats.UsedMemoryCount == 0u);
ASSERT(mStats.UsedMemoryUsage == 0u);
}
#endif

Expand Down Expand Up @@ -145,9 +145,9 @@ namespace gpgmm {
return kNoRequiredAlignment;
}

MemoryAllocatorInfo MemoryAllocator::GetInfo() const {
MemoryAllocatorStats MemoryAllocator::GetStats() const {
std::lock_guard<std::mutex> lock(mMutex);
return mInfo;
return mStats;
}

const char* MemoryAllocator::GetTypename() const {
Expand Down
6 changes: 3 additions & 3 deletions src/gpgmm/common/MemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ namespace gpgmm {
Should be overridden when a child or block allocator is used to avoid
over-counting.

\return A MemoryAllocatorInfo struct containing the current usage.
\return A MemoryAllocatorStats struct containing the current usage.
*/
virtual MemoryAllocatorInfo GetInfo() const;
virtual MemoryAllocatorStats GetStats() const;

/** \brief Identifies the allocator type.

Expand Down Expand Up @@ -278,7 +278,7 @@ namespace gpgmm {

void CheckAndReportAllocationMisalignment(const MemoryAllocation& allocation);

MemoryAllocatorInfo mInfo = {};
MemoryAllocatorStats mStats = {};

mutable std::mutex mMutex;
std::shared_ptr<ThreadPool> mThreadPool;
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/MemoryPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace gpgmm {
return mMemorySize;
}

MemoryPoolInfo MemoryPool::GetInfo() const {
MemoryPoolInfo MemoryPool::GetStats() const {
return {GetPoolSize() * mMemorySize};
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/MemoryPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace gpgmm {

\return A MemoryPoolInfo struct containing the information.
*/
MemoryPoolInfo GetInfo() const;
MemoryPoolInfo GetStats() const;

/** \brief Returns the class name of this allocation.

Expand Down
14 changes: 7 additions & 7 deletions src/gpgmm/common/PooledMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ namespace gpgmm {
GPGMM_TRY_ASSIGN(GetNextInChain()->TryAllocateMemory(request), allocationPtr);
allocation = *allocationPtr;
} else {
mInfo.FreeMemoryUsage -= allocation.GetSize();
mStats.FreeMemoryUsage -= allocation.GetSize();
}

mInfo.UsedMemoryCount++;
mInfo.UsedMemoryUsage += allocation.GetSize();
mStats.UsedMemoryCount++;
mStats.UsedMemoryUsage += allocation.GetSize();

IMemoryObject* memory = allocation.GetMemory();
ASSERT(memory != nullptr);
Expand All @@ -66,9 +66,9 @@ namespace gpgmm {
std::lock_guard<std::mutex> lock(mMutex);

const uint64_t& allocationSize = allocation->GetSize();
mInfo.FreeMemoryUsage += allocationSize;
mInfo.UsedMemoryCount--;
mInfo.UsedMemoryUsage -= allocationSize;
mStats.FreeMemoryUsage += allocationSize;
mStats.UsedMemoryCount--;
mStats.UsedMemoryUsage -= allocationSize;

IMemoryObject* memory = allocation->GetMemory();
ASSERT(memory != nullptr);
Expand All @@ -79,7 +79,7 @@ namespace gpgmm {

uint64_t PooledMemoryAllocator::ReleaseMemory(uint64_t bytesToRelease) {
const uint64_t bytesReleased = mPool->ReleasePool(bytesToRelease);
mInfo.FreeMemoryUsage -= bytesReleased;
mStats.FreeMemoryUsage -= bytesReleased;
return bytesReleased;
}

Expand Down
14 changes: 7 additions & 7 deletions src/gpgmm/common/SegmentedMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ namespace gpgmm {
GPGMM_TRY_ASSIGN(GetNextInChain()->TryAllocateMemory(request), allocationPtr);
allocation = *allocationPtr;
} else {
mInfo.FreeMemoryUsage -= allocation.GetSize();
mStats.FreeMemoryUsage -= allocation.GetSize();
}

mInfo.UsedMemoryCount++;
mInfo.UsedMemoryUsage += allocation.GetSize();
mStats.UsedMemoryCount++;
mStats.UsedMemoryUsage += allocation.GetSize();

IMemoryObject* memory = allocation.GetMemory();
ASSERT(memory != nullptr);
Expand All @@ -158,9 +158,9 @@ namespace gpgmm {
ASSERT(allocation != nullptr);

const uint64_t& allocationSize = allocation->GetSize();
mInfo.FreeMemoryUsage += allocationSize;
mInfo.UsedMemoryCount--;
mInfo.UsedMemoryUsage -= allocationSize;
mStats.FreeMemoryUsage += allocationSize;
mStats.UsedMemoryCount--;
mStats.UsedMemoryUsage -= allocationSize;

IMemoryObject* memory = allocation->GetMemory();
ASSERT(memory != nullptr);
Expand All @@ -181,7 +181,7 @@ namespace gpgmm {
ASSERT(segment != nullptr);
const uint64_t bytesReleasedPerSegment = segment->ReleasePool(bytesToRelease);
bytesToRelease -= bytesReleasedPerSegment;
mInfo.FreeMemoryUsage -= bytesReleasedPerSegment;
mStats.FreeMemoryUsage -= bytesReleasedPerSegment;
totalBytesReleased += bytesReleasedPerSegment;

if (totalBytesReleased >= bytesToRelease) {
Expand Down
32 changes: 16 additions & 16 deletions src/gpgmm/common/SlabMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ namespace gpgmm {
if (prefetchedSlabAllocation != nullptr &&
prefetchedSlabAllocation->GetSize() == slabSize) {
pFreeSlab->Allocation = *prefetchedSlabAllocation;
mInfo.PrefetchedMemoryMissesEliminated++;
mStats.PrefetchedMemoryMissesEliminated++;
return pFreeSlab->Allocation.GetMemory();
}

Expand All @@ -286,7 +286,7 @@ namespace gpgmm {
<< prefetchedSlabAllocation->GetSize() << " bytes.";
}

mInfo.PrefetchedMemoryMisses++;
mStats.PrefetchedMemoryMisses++;

mMemoryAllocator->DeallocateMemory(std::move(prefetchedSlabAllocation));
}
Expand Down Expand Up @@ -373,8 +373,8 @@ namespace gpgmm {
// offset must be made relative to the slab's underlying memory and not the slab itself.
const uint64_t offsetFromMemory = pFreeSlab->Allocation.GetOffset() + blockInSlab->Offset;

mInfo.UsedBlockCount++;
mInfo.UsedBlockUsage += blockInSlab->Size;
mStats.UsedBlockCount++;
mStats.UsedBlockUsage += blockInSlab->Size;

return std::make_unique<MemoryAllocation>(this, subAllocation->GetMemory(),
offsetFromMemory, AllocationMethod::kSubAllocated,
Expand All @@ -401,8 +401,8 @@ namespace gpgmm {
/*pDstList*/ &pCache->FreeList);
}

mInfo.UsedBlockCount--;
mInfo.UsedBlockUsage -= blockInSlab->Size;
mStats.UsedBlockCount--;
mStats.UsedBlockUsage -= blockInSlab->Size;

pSlab->Allocator.DeallocateBlock(blockInSlab);
pSlab->UsedBlocksPerSlab--;
Expand Down Expand Up @@ -435,10 +435,10 @@ namespace gpgmm {
return pSlab;
}

MemoryAllocatorInfo SlabMemoryAllocator::GetInfo() const {
MemoryAllocatorStats SlabMemoryAllocator::GetStats() const {
std::lock_guard<std::mutex> lock(mMutex);
MemoryAllocatorInfo result = mInfo;
const MemoryAllocatorInfo& info = mMemoryAllocator->GetInfo();
MemoryAllocatorStats result = mStats;
const MemoryAllocatorStats& info = mMemoryAllocator->GetStats();
result.UsedMemoryCount = info.UsedMemoryCount;
result.UsedMemoryUsage = info.UsedMemoryUsage;
result.FreeMemoryUsage = info.FreeMemoryUsage;
Expand All @@ -450,13 +450,13 @@ namespace gpgmm {
}

bool SlabMemoryAllocator::IsPrefetchCoverageBelowThreshold() const {
if (mInfo.PrefetchedMemoryMissesEliminated >= mInfo.PrefetchedMemoryMisses) {
if (mStats.PrefetchedMemoryMissesEliminated >= mStats.PrefetchedMemoryMisses) {
return true;
}

const double currentCoverage =
SafeDivide(mInfo.PrefetchedMemoryMissesEliminated,
mInfo.PrefetchedMemoryMissesEliminated + mInfo.PrefetchedMemoryMisses);
SafeDivide(mStats.PrefetchedMemoryMissesEliminated,
mStats.PrefetchedMemoryMissesEliminated + mStats.PrefetchedMemoryMisses);
if (currentCoverage < kPrefetchCoverageWarnMinThreshold) {
WarnEvent(GetTypename(), EventMessageId::kPrefetchFailed)
<< "Prefetch coverage is below threshold (%): " << currentCoverage * 100 << " vs "
Expand Down Expand Up @@ -543,20 +543,20 @@ namespace gpgmm {
entry->Unref();
}

MemoryAllocatorInfo SlabCacheAllocator::GetInfo() const {
MemoryAllocatorStats SlabCacheAllocator::GetStats() const {
std::lock_guard<std::mutex> lock(mMutex);

MemoryAllocatorInfo result = {};
MemoryAllocatorStats result = {};
for (const auto& entry : mSizeCache) {
const MemoryAllocatorInfo& info = entry->GetValue().SlabAllocator->GetInfo();
const MemoryAllocatorStats& info = entry->GetValue().SlabAllocator->GetStats();
result.UsedBlockCount += info.UsedBlockCount;
result.UsedBlockUsage += info.UsedBlockUsage;
result.PrefetchedMemoryMisses += info.PrefetchedMemoryMisses;
result.PrefetchedMemoryMissesEliminated += info.PrefetchedMemoryMissesEliminated;
}

// Memory allocator is common across slab allocators.
const MemoryAllocatorInfo& info = GetNextInChain()->GetInfo();
const MemoryAllocatorStats& info = GetNextInChain()->GetStats();
result.FreeMemoryUsage = info.FreeMemoryUsage;
result.UsedMemoryCount = info.UsedMemoryCount;
result.UsedMemoryUsage = info.UsedMemoryUsage;
Expand Down
Loading