5#include "Containers/Array.h"
7#include "HAL/CriticalSection.h"
8#include "HAL/LowLevelMemStats.h"
9#include "HAL/LowLevelMemTracker.h"
10#include "HAL/MallocJemalloc.h"
11#include "HAL/MemoryBase.h"
12#include "HAL/PlatformAtomics.h"
13#include "Math/UnrealMathUtility.h"
14#include "Stats/Stats.h"
15#include "Stats/Stats2.h"
22#define USE_INTERNAL_LOCKS
23#if USE_CACHE_FREED_OS_ALLOCS
27#ifndef USE_OS_SMALL_BLOCK_ALLOC
31#ifndef USE_OS_SMALL_BLOCK_GRAB_MEMORY_FROM_OS
39#if defined USE_LOCKFREE_DELETE
40# define USE_INTERNAL_LOCKS
41# define USE_COARSE_GRAIN_LOCKS
44#if defined CACHE_FREED_OS_ALLOCS
45 #define MAX_CACHED_OS_FREES (64
)
47 #define MAX_CACHED_OS_FREES_BYTE_LIMIT (64
*1024
*1024
)
49 #define MAX_CACHED_OS_FREES_BYTE_LIMIT (16
*1024
*1024
)
54# define USE_FINE_GRAIN_LOCKS
58typedef int64 BINNED_STAT_TYPE;
60typedef int32 BINNED_STAT_TYPE;
66# ifdef USE_COARSE_GRAIN_LOCKS
67# define BINNED_STAT BINNED_STAT_TYPE
68# define BINNED_INCREMENT_STATCOUNTER(counter) (++(counter))
69# define BINNED_DECREMENT_STATCOUNTER(counter) (--(counter))
70# define BINNED_ADD_STATCOUNTER(counter, value) ((counter) += (value))
71# define BINNED_PEAK_STATCOUNTER(PeakCounter, CompareVal) ((PeakCounter) = FMath::Max((PeakCounter), (CompareVal)))
73# define BINNED_STAT volatile BINNED_STAT_TYPE
74# define BINNED_INCREMENT_STATCOUNTER(counter) (FPlatformAtomics::InterlockedIncrement(&(counter)))
75# define BINNED_DECREMENT_STATCOUNTER(counter) (FPlatformAtomics::InterlockedDecrement(&(counter)))
76# define BINNED_ADD_STATCOUNTER(counter, value) (FPlatformAtomics::InterlockedAdd(&counter, (value)))
77# define BINNED_PEAK_STATCOUNTER(PeakCounter, CompareVal) {
78 BINNED_STAT_TYPE NewCompare;
79 BINNED_STAT_TYPE NewPeak;
82 NewCompare = (PeakCounter);
83 NewPeak = FMath::Max((PeakCounter), (CompareVal));
85 while (FPlatformAtomics::InterlockedCompareExchange(&(PeakCounter), NewPeak, NewCompare) != NewCompare);
89# define BINNED_STAT BINNED_STAT_TYPE
90# define BINNED_INCREMENT_STATCOUNTER(counter)
91# define BINNED_DECREMENT_STATCOUNTER(counter)
92# define BINNED_ADD_STATCOUNTER(counter, value)
93# define BINNED_PEAK_STATCOUNTER(PeakCounter, CompareVal)
108DECLARE_LLM_MEMORY_STAT_EXTERN(TEXT(
"Nano Malloc Pages Current"), STAT_Binned_NanoMallocPages_Current,STATGROUP_LLMPlatform, );
109DECLARE_LLM_MEMORY_STAT_EXTERN(TEXT(
"Nano Malloc Pages Peak"), STAT_Binned_NanoMallocPages_Peak,STATGROUP_LLMPlatform, );
110DECLARE_LLM_MEMORY_STAT_EXTERN(TEXT(
"Nano Malloc Pages Waste Current"), STAT_Binned_NanoMallocPages_WasteCurrent,STATGROUP_LLMPlatform, );
111DECLARE_LLM_MEMORY_STAT_EXTERN(TEXT(
"Nano Malloc Pages Waste Peak"),STAT_Binned_NanoMallocPages_WastePeak,STATGROUP_LLMPlatform, );
135 struct PoolHashBucket;
137#ifdef CACHE_FREED_OS_ALLOCS
207#ifdef USE_LOCKFREE_DELETE
209
210
211
248#ifdef CACHE_FREED_OS_ALLOCS
267#if USE_OS_SMALL_BLOCK_GRAB_MEMORY_FROM_OS
293
294
295
299
300
301 virtual void*
Malloc( SIZE_T Size, uint32 Alignment )
override;
304
305
306 virtual void*
Realloc(
void* Ptr, SIZE_T NewSize, uint32 Alignment )
override;
309
310
311 virtual void Free(
void* Ptr )
override;
314
315
316
317
318
319
325
326
336
337
338
339
#define ENABLE_LOW_LEVEL_MEM_TRACKER
#define USE_OS_SMALL_BLOCK_ALLOC
#define USE_OS_SMALL_BLOCK_GRAB_MEMORY_FROM_OS
#define USE_INTERNAL_LOCKS
DECLARE_DWORD_COUNTER_STAT_EXTERN(TEXT("Binned Current Allocs"), STAT_Binned_CurrentAllocs, STATGROUP_MemoryAllocator,)
#define USE_FINE_GRAIN_LOCKS
FWindowsCriticalSection FCriticalSection
virtual void * Realloc(void *Ptr, SIZE_T NewSize, uint32 Alignment) override
FPoolTable PagePoolTable[EXTENDED_PAGE_POOL_ALLOCATION_COUNT]
uint64 IndirectPoolBitShift
PoolHashBucket * HashBuckets
uint64 BinnedOSTableIndex
uint64 IndirectPoolBlockSize
virtual bool ValidateHeap() override
virtual bool IsInternallyThreadSafe() const override
virtual void InitializeStatsMetadata() override
virtual const TCHAR * GetDescriptiveName() override
@ MAX_POOLED_ALLOCATION_SIZE
@ EXTENDED_PAGE_POOL_ALLOCATION_COUNT
virtual void * Malloc(SIZE_T Size, uint32 Alignment) override
FCriticalSection AccessGuard
uint64 MaxBookKeepingOverhead
FPoolTable * MemSizeToPoolTable[MAX_POOLED_ALLOCATION_SIZE+EXTENDED_PAGE_POOL_ALLOCATION_COUNT]
FMallocBinned(uint32 InPageSize, uint64 AddressLimit)
virtual void Free(void *Ptr) override
virtual bool GetAllocationSize(void *Original, SIZE_T &SizeOut) override
FPoolTable PoolTable[POOL_COUNT]
virtual void UpdateStats() override
virtual void DumpAllocatorStats(class FOutputDevice &Ar) override
virtual SIZE_T QuantizeSize(SIZE_T Count, uint32 Alignment) override
PoolHashBucket * HashBucketFreeList
virtual void GetAllocatorStats(FGenericMemoryStats &out_Stats) override
uint64 MaxHashBucketWaste
FPoolInfo * ExhaustedPool
FCriticalSection CriticalSection