21#define UE_MB2_MAX_CACHED_OS_FREES (64)
23# define UE_MB2_MAX_CACHED_OS_FREES_BYTE_LIMIT (64*1024*1024)
25# define UE_MB2_MAX_CACHED_OS_FREES_BYTE_LIMIT (16*1024*1024)
28#define UE_MB2_LARGE_ALLOC 65536
30#if AGGRESSIVE_MEMORY_SAVING
31# define UE_MB2_MAX_SMALL_POOL_SIZE (13104)
32# define UE_MB2_SMALL_POOL_COUNT 48
34# define UE_MB2_MAX_SMALL_POOL_SIZE (32768-16)
35# define UE_MB2_SMALL_POOL_COUNT 51
39#ifndef BINNED2_FORK_SUPPORT
40# define BINNED2_FORK_SUPPORT (UE_SERVER && (PLATFORM_UNIX || DEFAULT_SERVER_FAKE_FORKS))
43#define UE_MB2_ALLOCATOR_STATS UE_MBC_ALLOCATOR_STATS
44#define UE_MB2_ALLOCATOR_STATS_VALIDATION (UE_MB2_ALLOCATOR_STATS && 0)
46#if UE_MB2_ALLOCATOR_STATS_VALIDATION
58#if BINNED2_FORK_SUPPORT
109 void ExhaustPoolIfNecessary();
123 , NextFreeBlock(nullptr)
139 inline void* AllocateBin()
149 return (
uint8*)
this + (NumFreeBins * BinSize);
161 FFreeBlock* NextFreeBlock;
166 FPoolList() =
default;
171 FPoolInfo& GetFrontPool();
172 const FPoolInfo& GetFrontPool()
const;
174 void LinkToFront(FPoolInfo* Pool);
178 void ValidateActivePools()
const;
179 void ValidateExhaustedPools()
const;
182 FPoolInfo*
Front =
nullptr;
193#if UE_MB2_ALLOCATOR_STATS
208#if BINNED2_FORK_SUPPORT
215#if !PLATFORM_UNIX && !PLATFORM_ANDROID
216# if UE_USE_VERYLARGEPAGEALLOCATOR
225 FORCEINLINE bool IsOSAllocation(
const void* Ptr)
const
227#if UE_USE_VERYLARGEPAGEALLOCATOR && !PLATFORM_UNIX && !PLATFORM_ANDROID
234 static FORCEINLINE FFreeBlock* GetPoolHeaderFromPointer(
void* Ptr)
253 virtual void Free(
void* Ptr)
override;
257 if (!IsOSAllocation(Ptr))
259 const FFreeBlock*
Free = GetPoolHeaderFromPointer(Ptr);
290 return CachedOSPageAllocator.GetCachedImmediatelyFreeable();
294 return CachedOSPageAllocator.GetCachedFreeTotal();
304#if BINNED2_FORK_SUPPORT
308 if (
Block->CanaryAndForkState != CurrentCanary)
336#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_7
338# if UE_MB2_ALLOCATOR_STATS_VALIDATION
constexpr T AlignDown(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:34
constexpr bool IsAligned(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:50
#define check(expr)
Definition AssertionMacros.h:314
#define UE_AUTORTFM_NOAUTORTFM
Definition AutoRTFMDefines.h:113
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_MB2_MAX_SMALL_POOL_SIZE
Definition MallocBinned2.h:34
#define UE_MB2_LARGE_ALLOC
Definition MallocBinned2.h:28
#define UE_MB2_SMALL_POOL_COUNT
Definition MallocBinned2.h:35
EBlockCanary
Definition MallocBinned2.h:56
#define UE_MBC_BIN_SIZE_SHIFT
Definition MallocBinnedCommon.h:49
#define MAX_uint16
Definition NumericLimits.h:20
#define MAX_uint8
Definition NumericLimits.h:19
uint32 Size
Definition VulkanMemory.cpp:4034
Definition MallocBinned2.h:71
bool GetSmallAllocationSize(void *Ptr, SIZE_T &SizeOut) const
Definition MallocBinned2.h:255
void CanaryTest(const FFreeBlock *Block) const
Definition MallocBinned2.h:302
virtual void DumpAllocatorStats(class FOutputDevice &Ar) override
Definition MallocBinned2.cpp:904
void FlushCurrentThreadCacheInternal(bool bNewEpochOnly=false)
Definition MallocBinned2.cpp:890
void * MallocExternalLarge(SIZE_T Size, uint32 Alignment)
Definition MallocBinned2.cpp:613
void * MallocExternalSmall(SIZE_T Size, uint32 Alignment)
Definition MallocBinned2.cpp:543
virtual void OnPreFork() override
Definition MallocBinned2.cpp:465
FMallocBinned2()
Definition MallocBinned2.cpp:384
virtual ~FMallocBinned2()
Definition MallocBinned2.cpp:440
virtual void Trim(bool bTrimThreadCaches) override
Definition MallocBinned2.cpp:875
virtual bool GetAllocationSize(void *Ptr, SIZE_T &SizeOut) override
Definition MallocBinned2.h:267
virtual bool ValidateHeap() override
Definition MallocBinned2.cpp:851
void CanaryFail(const FFreeBlock *Block) const
Definition MallocBinned2.cpp:895
virtual FORCEINLINE SIZE_T QuantizeSize(SIZE_T Count, uint32 Alignment) override
Definition MallocBinned2.h:276
virtual uint64 GetImmediatelyFreeableCachedMemorySize() const override
Definition MallocBinned2.h:288
virtual void UpdateStats() override
Definition MallocBinned2.cpp:950
FPoolTable SmallPoolTables[UE_MB2_SMALL_POOL_COUNT]
Definition MallocBinned2.h:205
virtual const TCHAR * GetDescriptiveName() override
Definition MallocBinned2.cpp:865
static uint8 MemSizeToPoolIndex[1+(UE_MB2_MAX_SMALL_POOL_SIZE > > UE_MBC_BIN_SIZE_SHIFT)]
Definition MallocBinned2.h:101
virtual UE_AUTORTFM_NOAUTORTFM void * Realloc(void *Ptr, SIZE_T NewSize, uint32 Alignment) override
Definition MallocBinned2.cpp:660
static uint16 SmallBinSizes[UE_MB2_SMALL_POOL_COUNT]
Definition MallocBinned2.h:98
virtual void OnMallocInitialized() override
Definition MallocBinned2.cpp:444
static void FreeMetaDataMemory(void *Ptr, SIZE_T Size)
Definition MallocBinned2.cpp:968
static FMallocBinned2 * MallocBinned2
Definition MallocBinned2.h:319
FORCEINLINE uint32 PoolIndexToBinSize(uint32 PoolIndex) const
Definition MallocBinned2.h:326
void FreeBundles(FBundleNode *Bundles, uint32 PoolIndex)
Definition MallocBinned2.cpp:870
virtual bool IsInternallyThreadSafe() const override
Definition MallocBinned2.cpp:516
virtual void OnPostFork() override
Definition MallocBinned2.cpp:491
static void * AllocateMetaDataMemory(SIZE_T Size)
Definition MallocBinned2.cpp:961
virtual UE_AUTORTFM_NOAUTORTFM void * Malloc(SIZE_T Size, uint32 Alignment) override
Definition MallocBinned2.cpp:526
virtual uint64 GetTotalFreeCachedMemorySize() const override
Definition MallocBinned2.h:292
Definition OutputDevice.h:133
Definition MallocBinnedCommon.h:452
SIZE_T QuantizeSizeCommon(SIZE_T Count, uint32 Alignment, const FMallocBinned2 &Alloc) const
Definition MallocBinnedCommon.h:836
bool GetAllocationSizeExternal(void *Ptr, SIZE_T &SizeOut)
Definition MallocBinnedCommon.h:909
Definition OverriddenPropertySet.cpp:45
@ Front
Definition GeoEnum.h:84
FPThreadsRecursiveMutex FPlatformRecursiveMutex
Definition AndroidPlatformMutex.h:12
Definition MallocBinned2.h:78
FPoolInfo * Next
Definition MallocBinned2.h:90
uint32 AllocSize
Definition MallocBinned2.h:88
ECanary Canary
Definition MallocBinned2.h:87
uint16 Taken
Definition MallocBinned2.h:86
FFreeBlock * FirstFreeBlock
Definition MallocBinned2.h:89
void * AllocateBin()
Definition MallocBinned2.cpp:172
SIZE_T GetOSRequestedBytes() const
Definition MallocBinned2.cpp:181
void CheckCanary(ECanary ShouldBe) const
Definition MallocBinned2.cpp:121
void Unlink()
Definition MallocBinned2.cpp:214
SIZE_T GetOsAllocatedBytes() const
Definition MallocBinned2.cpp:186
FPoolInfo()
Definition MallocBinned2.cpp:111
bool HasFreeBin() const
Definition MallocBinned2.cpp:166
void SetCanary(ECanary ShouldBe, bool bPreexisting, bool bGuaranteedToBeNew)
Definition MallocBinned2.cpp:129
void SetOSAllocationSizes(SIZE_T InRequestedBytes, UPTRINT InAllocatedBytes)
Definition MallocBinned2.cpp:192
ECanary
Definition MallocBinned2.h:80
@ FirstFreeBlockIsOSAllocSize
FPoolInfo ** PtrToPrevNext
Definition MallocBinned2.h:91
Definition MallocBinned2.h:188
FPoolList ExhaustedPools
Definition MallocBinned2.h:190
UE::FPlatformRecursiveMutex Mutex
Definition MallocBinned2.h:199
FPoolList ActivePools
Definition MallocBinned2.h:189
uint32 BinSize
Definition MallocBinned2.h:191
Definition PooledVirtualMemoryAllocator.h:61
Definition CachedOSPageAllocator.h:37