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

br: set memory limit #53793

Merged
merged 8 commits into from
Aug 5, 2024
Merged
Changes from 1 commit
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
Next Next commit
set memory limit
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
  • Loading branch information
Leavrth committed Jun 4, 2024
commit c8f2b0a6a2c96f25b4d6e03ea8d083e63854fd46
27 changes: 27 additions & 0 deletions br/cmd/br/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime/debug"
"sync"
"sync/atomic"
"time"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/pingcap/tidb/pkg/util/memory"
"github.com/pingcap/tidb/pkg/util/redact"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var (
Expand Down Expand Up @@ -162,6 +164,31 @@ func Init(cmd *cobra.Command) (err error) {
}
log.ReplaceGlobals(lg, p)
memory.InitMemoryHook()
if debug.SetMemoryLimit(-1) == 0 {
memtotal, e := memory.MemTotal()
if e != nil {
err = e
return
}
memused, e := memory.MemUsed()
if e != nil {
err = e
return
}
halfGB := uint64(512 * 1024 * 1024)
// 0 memused memtotal-512MB memtotal
// +--------+--------------------+--------------+
// br mem upper limit
memleft := memtotal - memused - halfGB
// 0 512MB +inf
// +--------+-------------------->
// ^____________________>
// GOMEMLIMIT range
if memleft > halfGB {
log.Info("set memory limit", zap.Uint64("limit", memleft))
debug.SetMemoryLimit(int64(memleft))
}
}

redactLog, e := cmd.Flags().GetBool(FlagRedactLog)
if e != nil {
Expand Down
Loading