From 08851649e2bd757b7858949051fc3ec07e2aa2be Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 26 Oct 2022 17:01:00 +0800 Subject: [PATCH] update Signed-off-by: Weizhen Wang --- util/gctuner/memory_limit_tuner.go | 4 ++-- util/memory/memstats.go | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/util/gctuner/memory_limit_tuner.go b/util/gctuner/memory_limit_tuner.go index 14bb923a6d98b..4abbd8618ae00 100644 --- a/util/gctuner/memory_limit_tuner.go +++ b/util/gctuner/memory_limit_tuner.go @@ -44,7 +44,7 @@ func (t *memoryLimitTuner) tuning() { if !t.isTuning.Load() { return } - heapInuse := memory.ForceReadHeapInuse() + r := memory.ForceReadMemStats() gogc := util.GetGOGC() ratio := float64(100+gogc) / 100 // This `if` checks whether the **last** GC was triggered by MemoryLimit as far as possible. @@ -56,7 +56,7 @@ func (t *memoryLimitTuner) tuning() { // why the **last** GC is triggered. And MemoryLimit will not be reset this time. // - Only if NextGC >= MemoryLimit , the **next** GC will be triggered by MemoryLimit. Thus, we need to reset // MemoryLimit after the **next** GC happens if needed. - if float64(heapInuse)*ratio > float64(debug.SetMemoryLimit(-1)) { + if float64(r.HeapInuse)*ratio > float64(debug.SetMemoryLimit(-1)) { if t.nextGCTriggeredByMemoryLimit.Load() && t.waitingReset.CompareAndSwap(false, true) { go func() { debug.SetMemoryLimit(math.MaxInt64) diff --git a/util/memory/memstats.go b/util/memory/memstats.go index 093f1e018b5bb..cd0074ece52c7 100644 --- a/util/memory/memstats.go +++ b/util/memory/memstats.go @@ -43,15 +43,6 @@ func ForceReadMemStats() *runtime.MemStats { return &g.m } -// ForceReadHeapInuse is to force read memory stats and return heap in use. -func ForceReadHeapInuse() uint64 { - var g globalMstats - g.ts = time.Now() - runtime.ReadMemStats(&g.m) - stats.Store(&g) - return g.m.HeapInuse -} - type globalMstats struct { ts time.Time m runtime.MemStats