From ba685a95e1b297f85f89d26a1c5195fd5ad0b8e2 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 11 Oct 2024 09:34:54 +0100 Subject: [PATCH] Re Add Malloc Trim --- src/Nethermind/Nethermind.Consensus/GC/GCScheduler.cs | 5 ++++- src/Nethermind/Nethermind.Merge.Plugin/GC/GCKeeper.cs | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/GC/GCScheduler.cs b/src/Nethermind/Nethermind.Consensus/GC/GCScheduler.cs index c66daea0de1..ddb2d5caee4 100644 --- a/src/Nethermind/Nethermind.Consensus/GC/GCScheduler.cs +++ b/src/Nethermind/Nethermind.Consensus/GC/GCScheduler.cs @@ -6,6 +6,8 @@ using System.Runtime; using System.Threading; using System.Threading.Tasks; +using Nethermind.Core.Extensions; +using Nethermind.Core.Memory; namespace Nethermind.Consensus; @@ -180,7 +182,8 @@ public bool GCCollect(int generation, GCCollectionMode mode, bool blocking, bool // Reset the block counter after GC _countToGC = MaxBlocksWithoutGC; System.GC.Collect(generation, mode, blocking: blocking, compacting: compacting); - + // Also trim native memory used by Db + MallocHelper.Instance.MallocTrim((uint)1.MiB()); // Indicate that GC has finished MarkGCResumed(); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/GC/GCKeeper.cs b/src/Nethermind/Nethermind.Merge.Plugin/GC/GCKeeper.cs index e2d3a48957d..e1bbd1eb58c 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/GC/GCKeeper.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/GC/GCKeeper.cs @@ -8,7 +8,6 @@ using FastEnumUtility; using Nethermind.Consensus; using Nethermind.Core.Extensions; -using Nethermind.Core.Memory; using Nethermind.Logging; namespace Nethermind.Merge.Plugin.GC; @@ -150,8 +149,8 @@ private async Task ScheduleGCInternal() { // This should give time to finalize response in Engine API // Normally we should get block every 12s (5s on some chains) - // Lets say we process block in 2s, then delay 500ms, then invoke GC - await Task.Delay(500); + // Lets say we process block in 2s, then delay 125ms, then invoke GC + await Task.Delay(125); if (GCSettings.LatencyMode != GCLatencyMode.NoGCRegion) {