Skip to content

Commit

Permalink
Return to NoGCRegion now runtime bug is fixed (#6381)
Browse files Browse the repository at this point in the history
* Return to NoGCRegion now runtime bug is fixed

* Remove other comment
  • Loading branch information
benaadams committed Jan 3, 2024
1 parent 292acdd commit 0e6ffe7
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions src/Nethermind/Nethermind.Merge.Plugin/GC/GCKeeper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,16 @@ public GCKeeper(IGCStrategy gcStrategy, ILogManager logManager)

public IDisposable TryStartNoGCRegion(long? size = null)
{
// SustainedLowLatency is used rather than NoGCRegion
// due to runtime bug https://github.com/dotnet/runtime/issues/84096
// The code is left in as comments so it can be reverted when the bug is fixed
size ??= _defaultSize;
var priorLatencyMode = System.Runtime.GCSettings.LatencyMode;
//if (_gcStrategy.CanStartNoGCRegion())
if (priorLatencyMode != GCLatencyMode.SustainedLowLatency)
if (_gcStrategy.CanStartNoGCRegion())
{
FailCause failCause = FailCause.None;
try
{
GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;
//if (!System.GC.TryStartNoGCRegion(size.Value, true))
//{
// failCause = FailCause.GCFailedToStartNoGCRegion;
//}
if (!System.GC.TryStartNoGCRegion(size.Value, true))
{
failCause = FailCause.GCFailedToStartNoGCRegion;
}
}
catch (ArgumentOutOfRangeException)
{
Expand All @@ -60,10 +54,10 @@ public IDisposable TryStartNoGCRegion(long? size = null)
if (_logger.IsError) _logger.Error($"{nameof(System.GC.TryStartNoGCRegion)} failed with exception.", e);
}

return new NoGCRegion(this, priorLatencyMode, failCause, size, _logger);
return new NoGCRegion(this, failCause, size, _logger);
}

return new NoGCRegion(this, priorLatencyMode, FailCause.StrategyDisallowed, size, _logger);
return new NoGCRegion(this, FailCause.StrategyDisallowed, size, _logger);
}

private enum FailCause
Expand All @@ -79,35 +73,27 @@ private enum FailCause
private class NoGCRegion : IDisposable
{
private readonly GCKeeper _gcKeeper;
private readonly GCLatencyMode _priorMode;
private readonly FailCause _failCause;
private readonly long? _size;
private readonly ILogger _logger;

internal NoGCRegion(GCKeeper gcKeeper, GCLatencyMode priorMode, FailCause failCause, long? size, ILogger logger)
internal NoGCRegion(GCKeeper gcKeeper, FailCause failCause, long? size, ILogger logger)
{
_gcKeeper = gcKeeper;
_priorMode = priorMode;
_failCause = failCause;
_size = size;
_logger = logger;
}

public void Dispose()
{
// SustainedLowLatency is used rather than NoGCRegion
// due to runtime bug https://github.com/dotnet/runtime/issues/84096
// The code is left in as comments so it can be reverted when the bug is fixed
if (_failCause == FailCause.None)
{
//if (GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
if (GCSettings.LatencyMode == GCLatencyMode.SustainedLowLatency &&
_priorMode != GCLatencyMode.SustainedLowLatency)
if (GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
{
try
{
GCSettings.LatencyMode = _priorMode;
//System.GC.EndNoGCRegion();
System.GC.EndNoGCRegion();
_gcKeeper.ScheduleGC();
}
catch (InvalidOperationException)
Expand Down

0 comments on commit 0e6ffe7

Please sign in to comment.