forked from pingcap/tiflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sorter(ticdc): use correct cgroup memory limit in some scenarios (pin…
- Loading branch information
Showing
6 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package util | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/KimMachineGun/automemlimit/memlimit" | ||
"github.com/pingcap/log" | ||
"github.com/pingcap/tidb/util/memory" | ||
"github.com/pingcap/tiflow/pkg/errors" | ||
"go.uber.org/zap" | ||
) | ||
|
||
const memoryMax uint64 = math.MaxUint64 | ||
|
||
var MemTotal func() (uint64, error) = GetMemoryLimit | ||
|
||
// MemTotal gets the memory limit of current process based on cgroup. | ||
// If the cgourp is not set or memory.max is set to max, returns the available | ||
// memory of host. | ||
func GetMemoryLimit() (uint64, error) { | ||
totalMemory, err := memlimit.FromCgroup() | ||
if err != nil || totalMemory == memoryMax { | ||
log.Info("no cgroup memory limit", zap.Error(err)) | ||
totalMemory, err = memory.MemTotal() | ||
if err != nil { | ||
return 0, errors.Trace(err) | ||
} | ||
} | ||
return totalMemory, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetMemoryLimit(t *testing.T) { | ||
t.Parallel() | ||
limit, err := MemTotal() | ||
require.NoError(t, err) | ||
require.Less(t, limit, memoryMax) | ||
} |