5#include "Containers/Array.h"
21#define USE_INTERNAL_LOCKS
22#if USE_CACHE_FREED_OS_ALLOCS
26#ifndef USE_OS_SMALL_BLOCK_ALLOC
27#define USE_OS_SMALL_BLOCK_ALLOC PLATFORM_IOS
30#ifndef USE_OS_SMALL_BLOCK_GRAB_MEMORY_FROM_OS
31#define USE_OS_SMALL_BLOCK_GRAB_MEMORY_FROM_OS (USE_OS_SMALL_BLOCK_ALLOC && PLATFORM_IOS && 0)
34#ifdef USE_INTERNAL_LOCKS
38#if defined USE_LOCKFREE_DELETE
39# define USE_INTERNAL_LOCKS
40# define USE_COARSE_GRAIN_LOCKS
43#if defined CACHE_FREED_OS_ALLOCS
44 #define MAX_CACHED_OS_FREES (64)
46 #define MAX_CACHED_OS_FREES_BYTE_LIMIT (64*1024*1024)
48 #define MAX_CACHED_OS_FREES_BYTE_LIMIT (16*1024*1024)
52#if defined USE_INTERNAL_LOCKS && !defined USE_COARSE_GRAIN_LOCKS
53# define USE_FINE_GRAIN_LOCKS
65# ifdef USE_COARSE_GRAIN_LOCKS
66# define BINNED_STAT BINNED_STAT_TYPE
67# define BINNED_INCREMENT_STATCOUNTER(counter) (++(counter))
68# define BINNED_DECREMENT_STATCOUNTER(counter) (--(counter))
69# define BINNED_ADD_STATCOUNTER(counter, value) ((counter) += (value))
70# define BINNED_PEAK_STATCOUNTER(PeakCounter, CompareVal) ((PeakCounter) = FMath::Max((PeakCounter), (CompareVal)))
72# define BINNED_STAT volatile BINNED_STAT_TYPE
73# define BINNED_INCREMENT_STATCOUNTER(counter) (FPlatformAtomics::InterlockedIncrement(&(counter)))
74# define BINNED_DECREMENT_STATCOUNTER(counter) (FPlatformAtomics::InterlockedDecrement(&(counter)))
75# define BINNED_ADD_STATCOUNTER(counter, value) (FPlatformAtomics::InterlockedAdd(&counter, (value)))
76# define BINNED_PEAK_STATCOUNTER(PeakCounter, CompareVal) { \
77 BINNED_STAT_TYPE NewCompare; \
78 BINNED_STAT_TYPE NewPeak; \
81 NewCompare = (PeakCounter); \
82 NewPeak = FMath::Max((PeakCounter), (CompareVal)); \
84 while (FPlatformAtomics::InterlockedCompareExchange(&(PeakCounter), NewPeak, NewCompare) != NewCompare); \
88# define BINNED_STAT BINNED_STAT_TYPE
89# define BINNED_INCREMENT_STATCOUNTER(counter)
90# define BINNED_DECREMENT_STATCOUNTER(counter)
91# define BINNED_ADD_STATCOUNTER(counter, value)
92# define BINNED_PEAK_STATCOUNTER(PeakCounter, CompareVal)
106#if USE_OS_SMALL_BLOCK_GRAB_MEMORY_FROM_OS && ENABLE_LOW_LEVEL_MEM_TRACKER
124 enum { POOL_COUNT = 41 };
127 enum { EXTENDED_PAGE_POOL_ALLOCATION_COUNT = 2 };
128 enum { MAX_POOLED_ALLOCATION_SIZE = 32768+1 };
136#ifdef CACHE_FREED_OS_ALLOCS
138 struct FFreePageBlock
157#ifdef USE_FINE_GRAIN_LOCKS
187 , ExhaustedPool(
nullptr)
206#ifdef USE_LOCKFREE_DELETE
223 uint64 MaxHashBucketWaste;
224 uint64 MaxBookKeepingOverhead;
227 uint64 IndirectPoolBitShift;
228 uint64 IndirectPoolBlockSize;
234 uint64 BinnedOSTableIndex;
237 FPoolTable PoolTable[POOL_COUNT];
239 FPoolTable PagePoolTable[EXTENDED_PAGE_POOL_ALLOCATION_COUNT];
240 FPoolTable* MemSizeToPoolTable[MAX_POOLED_ALLOCATION_SIZE+EXTENDED_PAGE_POOL_ALLOCATION_COUNT];
247#ifdef CACHE_FREED_OS_ALLOCS
249 uint32 FreedPageBlocksNum;
266#if USE_OS_SMALL_BLOCK_GRAB_MEMORY_FROM_OS
275#if USE_OS_SMALL_BLOCK_ALLOC
310 virtual void Free(
void* Ptr )
override;
344#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_7
#define DECLARE_DWORD_COUNTER_STAT_EXTERN(CounterName, StatId, GroupId, API)
Definition Stats.h:682
#define DECLARE_MEMORY_STAT_EXTERN(CounterName, StatId, GroupId, API)
Definition Stats.h:687
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_LLM_MEMORY_STAT_EXTERN(CounterName, StatId, GroupId, API)
Definition LowLevelMemStats.h:51
#define BINNED_STAT
Definition MallocBinned.h:88
int32 BINNED_STAT_TYPE
Definition MallocBinned.h:59
uint32 Size
Definition VulkanMemory.cpp:4034
Definition MallocBinned.h:118
virtual void * Malloc(SIZE_T Size, uint32 Alignment) override
Definition MallocBinned.cpp:1286
virtual void GetAllocatorStats(FGenericMemoryStats &out_Stats) override
Definition MallocBinned.cpp:1020
virtual const TCHAR * GetDescriptiveName() override
Definition MallocBinned.cpp:1812
virtual void InitializeStatsMetadata() override
Definition MallocBinned.cpp:1094
virtual SIZE_T QuantizeSize(SIZE_T Count, uint32 Alignment) override
Definition MallocBinned.cpp:1564
virtual void DumpAllocatorStats(class FOutputDevice &Ar) override
Definition MallocBinned.cpp:1700
virtual bool GetAllocationSize(void *Original, SIZE_T &SizeOut) override
Definition MallocBinned.cpp:1522
virtual void * Realloc(void *Ptr, SIZE_T NewSize, uint32 Alignment) override
Definition MallocBinned.cpp:1421
virtual bool IsInternallyThreadSafe() const override
Definition MallocBinned.cpp:1277
virtual bool ValidateHeap() override
Definition MallocBinned.cpp:1603
virtual ~FMallocBinned()
Definition MallocBinned.cpp:1273
virtual void UpdateStats() override
Definition MallocBinned.cpp:1635
Definition MemoryBase.h:99
Definition OutputDevice.h:133
Definition OverriddenPropertySet.cpp:45
FPThreadsRecursiveMutex FPlatformRecursiveMutex
Definition AndroidPlatformMutex.h:12
Definition MemoryMisc.h:21
Definition MallocBinned.cpp:41
Definition MallocBinned.cpp:50
Definition MallocBinned.cpp:118