Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
  • Loading branch information
hawkingrei committed Oct 26, 2022
1 parent a9ffb21 commit 0885164
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
4 changes: 2 additions & 2 deletions util/gctuner/memory_limit_tuner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions util/memory/memstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0885164

Please sign in to comment.