Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return to NoGCRegion now runtime bug is fixed #6381

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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