MemoryTriggerGCAtPressureLevel
MemoryTriggerGCAtPressureLevel
#Overview
name: MemoryTriggerGCAtPressureLevel
The value of this variable can be defined or overridden in .ini config files. 1
.ini config file referencing this setting variable.
It is referenced in 11
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of MemoryTriggerGCAtPressureLevel is to control when garbage collection (GC) is triggered based on memory pressure in the Unreal Engine 5 cook-on-the-fly system. This variable is part of the memory management and optimization features for the cooking process.
MemoryTriggerGCAtPressureLevel is primarily used in the CookOnTheFlyServer subsystem, which is part of the UnrealEd module. This subsystem is responsible for cooking content on demand during development or when packaging a game.
The value of this variable is set in the GEditorIni configuration file under the [CookSettings] section. It is loaded during the initialization of the cook settings in the FInitializeConfigSettings::LoadLocal function.
MemoryTriggerGCAtPressureLevel interacts with other memory-related variables such as MemoryMinFreeVirtual, MemoryMinFreePhysical, and bUseSoftGC. These variables work together to manage memory usage during the cooking process.
Developers should be aware that:
- The variable accepts values of “None” or “Critical”, corresponding to the EMemoryPressureStatus enum.
- Setting this variable to “Critical” will only trigger GC when the system reports critical memory pressure, which may lead to more aggressive memory usage.
- If the platform doesn’t support memory pressure reporting, a warning will be logged, and the feature won’t be effective.
Best practices when using this variable include:
- Carefully consider the trade-off between memory usage and cooking performance when adjusting this setting.
- Monitor memory usage during cooking to ensure that the chosen setting is appropriate for your project’s needs.
- Use in conjunction with other memory-related settings to fine-tune the cooking process for optimal performance and stability.
- Test thoroughly after changing this setting, especially on platforms with limited memory resources.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseEditor.ini:368, section: [CookSettings]
- INI Section:
CookSettings
- Raw value:
None
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Classes/CookOnTheSide/CookOnTheFlyServer.h:330
Scope (from outer to inner):
file
class class UCookOnTheFlyServer : public UObject, public FTickableEditorObject, public FExec, public UE::Cook::ICookInfo
Source code excerpt:
uint64 MemoryMinFreeVirtual;
uint64 MemoryMinFreePhysical;
FGenericPlatformMemoryStats::EMemoryPressureStatus MemoryTriggerGCAtPressureLevel;
float MemoryExpectedFreedToSpreadRatio;
/** Max number of packages to save before we partial gc */
int32 MaxNumPackagesBeforePartialGC;
/** Max number of concurrent shader jobs reducing this too low will increase cook time */
int32 MaxConcurrentShaderJobs;
/** Min number of free UObject indices before the cooker should partial gc */
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:5004
Scope (from outer to inner):
file
function bool UCookOnTheFlyServer::PumpHasExceededMaxMemory
Source code excerpt:
bool bPressureTriggered = false;
if (MemoryTriggerGCAtPressureLevel != FPlatformMemoryStats::EMemoryPressureStatus::Unknown)
{
FPlatformMemoryStats::EMemoryPressureStatus PressureStatus = MemStats.GetMemoryPressureStatus();
if (PressureStatus == FPlatformMemoryStats::EMemoryPressureStatus::Unknown)
{
UE_CALL_ONCE([&]() {
UE_LOG(LogCook, Warning,
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:5018
Scope (from outer to inner):
file
function bool UCookOnTheFlyServer::PumpHasExceededMaxMemory
Source code excerpt:
static_assert(FPlatformMemoryStats::EMemoryPressureStatus::Critical > FPlatformMemoryStats::EMemoryPressureStatus::Nominal,
"We expect higher pressure to be higher integer values");
int RequiredValue = static_cast<int>(MemoryTriggerGCAtPressureLevel);
int CurrentValue = static_cast<int>(PressureStatus);
if (CurrentValue >= RequiredValue)
{
bPressureTriggered = true;
TriggerMessages.Appendf(TEXT("\n Operating system has signalled that memory pressure is high."));
}
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:6910
Scope (from outer to inner):
file
namespace UE::Cook
function void FInitializeConfigSettings::LoadLocal
Source code excerpt:
ReadMemorySetting(TEXT("MemoryMinFreePhysical"), MemoryMinFreePhysical);
FString ConfigText(TEXT("None"));
GConfig->GetString(TEXT("CookSettings"), TEXT("MemoryTriggerGCAtPressureLevel"), ConfigText, GEditorIni);
if (!LexTryParseString(MemoryTriggerGCAtPressureLevel, ConfigText))
{
UE_LOG(LogCook, Error, TEXT("Unrecognized value \"%s\" for MemoryTriggerGCAtPressureLevel. Expected None or Critical."),
*ConfigText);
}
GConfig->GetBool(TEXT("CookSettings"), TEXT("bUseSoftGC"), bUseSoftGC, GEditorIni);
GConfig->GetInt(TEXT("CookSettings"), TEXT("SoftGCStartNumerator"), SoftGCStartNumerator, GEditorIni);
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:6941
Scope (from outer to inner):
file
namespace UE::Cook
function void FInitializeConfigSettings::LoadLocal
Source code excerpt:
TEXT("\n\tUseSoftGC %s%s"),
MemoryMaxUsedVirtual / 1024 / 1024, MemoryMaxUsedPhysical / 1024 / 1024, MemoryMinFreeVirtual / 1024 / 1024, MemoryMinFreePhysical / 1024 / 1024,
*LexToString(MemoryTriggerGCAtPressureLevel),
bUseSoftGC ? TEXT("true") : TEXT("false"),
bUseSoftGC ? *FString::Printf(TEXT(" (%d/%d)"), SoftGCStartNumerator, SoftGCDenominator) : TEXT(""));
const FConfigSection* CacheSettings = GConfig->GetSection(TEXT("CookPlatformDataCacheSettings"), false, GEditorIni);
if (CacheSettings)
{
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookDirector.cpp:1068
Scope (from outer to inner):
file
namespace UE::Cook
function void FCookDirector::ActivateMachineResourceReduction
Source code excerpt:
COTFS.MemoryMinFreeVirtual = 0;
COTFS.MemoryMinFreePhysical = 0;
COTFS.MemoryTriggerGCAtPressureLevel = FGenericPlatformMemoryStats::EMemoryPressureStatus::Critical;
UE_LOG(LogCook, Display, TEXT("CookMultiprocess changed CookSettings for Memory:")
TEXT("\n\tMemoryMaxUsedVirtual %dMiB")
TEXT("\n\tMemoryMaxUsedPhysical %dMiB")
TEXT("\n\tMemoryMinFreeVirtual %dMiB")
TEXT("\n\tMemoryMinFreePhysical %dMiB")
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookDirector.cpp:1079
Scope (from outer to inner):
file
namespace UE::Cook
function void FCookDirector::ActivateMachineResourceReduction
Source code excerpt:
COTFS.MemoryMaxUsedVirtual / 1024 / 1024, COTFS.MemoryMaxUsedPhysical / 1024 / 1024,
COTFS.MemoryMinFreeVirtual / 1024 / 1024, COTFS.MemoryMinFreePhysical / 1024 / 1024,
*LexToString(COTFS.MemoryTriggerGCAtPressureLevel),
COTFS.bUseSoftGC ? TEXT("true") : TEXT("false"),
COTFS.bUseSoftGC ? *FString::Printf(TEXT(" (%d/%d)"), COTFS.SoftGCStartNumerator, COTFS.SoftGCDenominator) : TEXT("")
);
// Set CoreLimit for updating workerthreads in this process and passing to the commandline for workers
int32 NumProcesses = RequestedCookWorkerCount + 1;
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookTypes.cpp:625
Scope (from outer to inner):
file
function FCbWriter& operator<<
Source code excerpt:
Writer << "MemoryMinFreeVirtual" << Value.MemoryMinFreeVirtual;
Writer << "MemoryMinFreePhysical" << Value.MemoryMinFreePhysical;
Writer << "MemoryTriggerGCAtPressureLevel" << static_cast<uint8>(Value.MemoryTriggerGCAtPressureLevel);
Writer << "bUseSoftGC" << Value.bUseSoftGC;
Writer << "SoftGCStartNumerator" << Value.SoftGCStartNumerator;
Writer << "SoftGCDenominator" << Value.SoftGCDenominator;
Writer << "MinFreeUObjectIndicesBeforeGC" << Value.MinFreeUObjectIndicesBeforeGC;
Writer << "MaxNumPackagesBeforePartialGC" << Value.MaxNumPackagesBeforePartialGC;
Writer << "ConfigSettingDenyList" << Value.ConfigSettingDenyList;
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookTypes.cpp:654
Scope (from outer to inner):
file
function bool LoadFromCompactBinary
Source code excerpt:
if (LoadFromCompactBinary(Field["MemoryTriggerGCAtPressureLevel"], PressureLevelAsInt))
{
OutValue.MemoryTriggerGCAtPressureLevel = static_cast<FGenericPlatformMemoryStats::EMemoryPressureStatus>(PressureLevelAsInt);
}
else
{
OutValue.MemoryTriggerGCAtPressureLevel = FGenericPlatformMemoryStats::EMemoryPressureStatus::Unknown;
bOk = false;
}
bOk = LoadFromCompactBinary(Field["bUseSoftGC"], OutValue.bUseSoftGC) & bOk;
bOk = LoadFromCompactBinary(Field["SoftGCStartNumerator"], OutValue.SoftGCStartNumerator) & bOk;
bOk = LoadFromCompactBinary(Field["SoftGCDenominator"], OutValue.SoftGCDenominator) & bOk;
bOk = LoadFromCompactBinary(Field["MinFreeUObjectIndicesBeforeGC"], OutValue.MinFreeUObjectIndicesBeforeGC) & bOk;
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookTypes.cpp:688
Scope (from outer to inner):
file
namespace UE::Cook
function void FInitializeConfigSettings::MoveOrCopy
Source code excerpt:
Target.MemoryMinFreeVirtual = Source.MemoryMinFreeVirtual;
Target.MemoryMinFreePhysical = Source.MemoryMinFreePhysical;
Target.MemoryTriggerGCAtPressureLevel = Source.MemoryTriggerGCAtPressureLevel;
Target.bUseSoftGC = Source.bUseSoftGC;
Target.SoftGCStartNumerator = Source.SoftGCStartNumerator;
Target.SoftGCDenominator = Source.SoftGCDenominator;
Target.MinFreeUObjectIndicesBeforeGC = Source.MinFreeUObjectIndicesBeforeGC;
Target.MaxNumPackagesBeforePartialGC = Source.MaxNumPackagesBeforePartialGC;
Target.ConfigSettingDenyList = MoveTempIfPossible(Source.ConfigSettingDenyList);
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookTypes.h:320
Scope (from outer to inner):
file
namespace UE::Cook
Source code excerpt:
uint64 MemoryMinFreeVirtual;
uint64 MemoryMinFreePhysical;
FGenericPlatformMemoryStats::EMemoryPressureStatus MemoryTriggerGCAtPressureLevel;
int32 MinFreeUObjectIndicesBeforeGC;
int32 MaxNumPackagesBeforePartialGC;
int32 SoftGCStartNumerator;
int32 SoftGCDenominator;
TArray<FString> ConfigSettingDenyList;
TMap<FName, int32> MaxAsyncCacheForType; // max number of objects of a specific type which are allowed to async cache at once