UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CachedOSVeryLargePageAllocator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
5#include "Containers/List.h"
6#include "CoreTypes.h"
9#include "HAL/PlatformMutex.h"
10#include "HAL/UnrealMemory.h"
11
12
13#if UE_USE_VERYLARGEPAGEALLOCATOR
14
15#if PLATFORM_64BITS
16#define CACHEDOSVERYLARGEPAGEALLOCATOR_BYTE_LIMIT (128*1024*1024)
17#else
18#define CACHEDOSVERYLARGEPAGEALLOCATOR_BYTE_LIMIT (16*1024*1024)
19#endif
20//#define CACHEDOSVERYLARGEPAGEALLOCATOR_MAX_CACHED_OS_FREES (CACHEDOSVERYLARGEPAGEALLOCATOR_BYTE_LIMIT/(1024*64))
21#define CACHEDOSVERYLARGEPAGEALLOCATOR_MAX_CACHED_OS_FREES (256)
22
23#ifndef UE_VERYLARGEPAGEALLOCATOR_RESERVED_SIZE_IN_GB
24#define UE_VERYLARGEPAGEALLOCATOR_RESERVED_SIZE_IN_GB 4 //default to 4GB
25#endif
26
27#ifndef UE_VERYLARGEPAGEALLOCATOR_PAGESIZE_KB
28#define UE_VERYLARGEPAGEALLOCATOR_PAGESIZE_KB 2048 //default to 2MB
29#endif
30
32{
33 static constexpr uint64 AddressSpaceToReserve = ((1024LL * 1024LL * 1024LL) * UE_VERYLARGEPAGEALLOCATOR_RESERVED_SIZE_IN_GB);
35
37 static constexpr uint64 SizeOfSubPage = (1024 * 64);
40public:
41
43 : bEnabled(true)
44 , CachedFree(0)
46 {
47 Init();
48 }
49
51 {
52 // this leaks everything!
53 }
54
55 void* Allocate(SIZE_T Size, uint32 AllocationHint = 0, UE::FPlatformRecursiveMutex* Mutex = nullptr);
56
57 void Free(void* Ptr, SIZE_T Size, UE::FPlatformRecursiveMutex* Mutex = nullptr, bool ThreadIsTimeCritical = false);
58
59 void FreeAll(UE::FPlatformRecursiveMutex* Mutex = nullptr);
60
61 // Refresh cached os allocator if needed. Will preallocate / reduce backstore if preallocation is enabled
62 void Refresh();
63
64 void UpdateStats();
65
66 uint64 GetCachedFreeTotal() const
67 {
68 return CachedFree + CachedOSPageAllocator.GetCachedFreeTotal();
69 }
70
71 uint64 GetCachedImmediatelyFreeable() const
72 {
73 return ImmediatelyFreeable + CachedOSPageAllocator.GetCachedImmediatelyFreeable();
74 }
75
76 inline bool IsSmallBlockAllocation(const void* Ptr) const
77 {
79 {
80 return true;
81 }
82 return false;
83 }
84
85private:
86 struct FLargePage : public TIntrusiveLinkedList<FLargePage>
87 {
91
92 uintptr_t BaseAddress;
93
94 void Init(void* InBaseAddress)
95 {
96 BaseAddress = (uintptr_t)InBaseAddress;
98 uintptr_t Ptr = BaseAddress;
99 for (int i = 0; i < NumberOfFreeSubPages; i++)
100 {
101 FreeSubPages[i] = Ptr;
102 Ptr += SizeOfSubPage;
103 }
104 }
105
106 void Free(void* Ptr)
107 {
109 }
110
111 void* Allocate()
112 {
113 void* ret = nullptr;
115 {
117 }
118 return ret;
119 }
120 };
121
122 void Init();
126
127 bool bEnabled;
132 uint64 ImmediatelyFreeable; // the amount of memory that can be immediately returned to the OS
135
137
139
140 FLargePage* UsedLargePagesHead[FMemory::AllocationHints::Max]; // has backing store and is full
141
142 FLargePage* UsedLargePagesWithSpaceHead[FMemory::AllocationHints::Max]; // has backing store and still has room
143
145
147
149
150};
152
153#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_7
154#include "HAL/CriticalSection.h"
155#endif
156
157#endif // UE_USE_VERYLARGEPAGEALLOCATOR
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
void Init()
Definition LockFreeList.h:4
uint32 Size
Definition VulkanMemory.cpp:4034
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition AndroidPlatformMemory.h:38
Definition List.h:349
FPThreadsRecursiveMutex FPlatformRecursiveMutex
Definition AndroidPlatformMutex.h:12
AllocationHints
Definition UnrealMemory.h:97
@ Max
Definition UnrealMemory.h:103
Definition CachedOSPageAllocator.h:37