Skip to content

Commit 201aae9

Browse files
Try reducing memory pressure during object writing (#83181)
1 parent 97de75b commit 201aae9

File tree

1 file changed

+20
-1
lines changed
  • src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis

1 file changed

+20
-1
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ObjectWriter.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1150,14 +1150,30 @@ public static void EmitObject(string objectFilePath, IReadOnlyCollection<Depende
11501150
}
11511151

11521152
if (logger.IsVerbose)
1153-
logger.LogMessage($"Finalizing output to '{objectFilePath}'...");
1153+
logger.LogMessage($"Emitting debug information");
1154+
1155+
// Native side of the object writer is going to do more native memory allocations.
1156+
// Free up as much memory as possible so that we don't get OOM killed.
1157+
// This is potentially a waste of time. We're about to end the process and let the
1158+
// OS "garbage collect" the entire address space.
1159+
var gcMemoryInfo = GC.GetGCMemoryInfo();
1160+
if (gcMemoryInfo.TotalCommittedBytes > gcMemoryInfo.TotalAvailableMemoryBytes / 2)
1161+
{
1162+
if (logger.IsVerbose)
1163+
logger.LogMessage($"Freeing up memory");
1164+
1165+
GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive);
1166+
}
11541167

11551168
objectWriter.EmitDebugModuleInfo();
11561169

11571170
succeeded = true;
11581171
}
11591172
finally
11601173
{
1174+
if (logger.IsVerbose)
1175+
logger.LogMessage($"Finalizing output to '{objectFilePath}'...");
1176+
11611177
objectWriter.Dispose();
11621178

11631179
if (!succeeded)
@@ -1173,6 +1189,9 @@ public static void EmitObject(string objectFilePath, IReadOnlyCollection<Depende
11731189
}
11741190
}
11751191
}
1192+
1193+
if (logger.IsVerbose)
1194+
logger.LogMessage($"Done writing object file");
11761195
}
11771196

11781197
[DllImport(NativeObjectWriterFileName)]

0 commit comments

Comments
 (0)