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

cgroup: get right value when cgroup set max value #38661

Merged
merged 11 commits into from
Oct 28, 2022
11 changes: 11 additions & 0 deletions util/memory/meminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/util/cgroup"
"github.com/pingcap/tidb/util/mathutil"
"github.com/shirou/gopsutil/v3/mem"
)

Expand Down Expand Up @@ -105,6 +106,11 @@ func MemTotalCGroup() (uint64, error) {
if err != nil {
return memo, err
}
v, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
memo = mathutil.Min(v.Total, memo)
memLimit.set(memo, time.Now())
return memo, nil
}
Expand All @@ -119,6 +125,11 @@ func MemUsedCGroup() (uint64, error) {
if err != nil {
return memo, err
}
v, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
memo = mathutil.Min(v.Used, memo)
memUsage.set(memo, time.Now())
return memo, nil
}
Expand Down