mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
Merge pull request #107112 from linxiulei/fix_pidmax
Consider threads-max when deciding MaxPID.
This commit is contained in:
commit
40c2d04946
@ -25,7 +25,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
|
||||
)
|
||||
|
||||
@ -33,11 +33,22 @@ import (
|
||||
func Stats() (*statsapi.RlimitStats, error) {
|
||||
rlimit := &statsapi.RlimitStats{}
|
||||
|
||||
if content, err := ioutil.ReadFile("/proc/sys/kernel/pid_max"); err == nil {
|
||||
if maxPid, err := strconv.ParseInt(string(content[:len(content)-1]), 10, 64); err == nil {
|
||||
rlimit.MaxPID = &maxPid
|
||||
taskMax := int64(-1)
|
||||
// Calculate the mininum of kernel.pid_max and kernel.threads-max as they both specify the
|
||||
// system-wide limit on the number of tasks.
|
||||
for _, file := range []string{"/proc/sys/kernel/pid_max", "/proc/sys/kernel/threads-max"} {
|
||||
if content, err := ioutil.ReadFile(file); err == nil {
|
||||
if limit, err := strconv.ParseInt(string(content[:len(content)-1]), 10, 64); err == nil {
|
||||
if taskMax == -1 || taskMax > limit {
|
||||
taskMax = limit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Both reads did not fail.
|
||||
if taskMax >= 0 {
|
||||
rlimit.MaxPID = &taskMax
|
||||
}
|
||||
|
||||
var info syscall.Sysinfo_t
|
||||
syscall.Sysinfo(&info)
|
||||
|
@ -65,9 +65,11 @@ type NodeStats struct {
|
||||
type RlimitStats struct {
|
||||
Time metav1.Time `json:"time"`
|
||||
|
||||
// The max PID of OS.
|
||||
// The max number of extant process (threads, precisely on Linux) of OS. See RLIMIT_NPROC in getrlimit(2).
|
||||
// The operating system ceiling on the number of process IDs that can be assigned.
|
||||
// On Linux, tasks (either processes or threads) consume 1 PID each.
|
||||
MaxPID *int64 `json:"maxpid,omitempty"`
|
||||
// The number of running process in the OS.
|
||||
// The number of running process (threads, precisely on Linux) in the OS.
|
||||
NumOfRunningProcesses *int64 `json:"curproc,omitempty"`
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user