...

Source file src/github.com/opencontainers/runc/libcontainer/cgroups/fs/pids.go

Documentation: github.com/opencontainers/runc/libcontainer/cgroups/fs

     1  package fs
     2  
     3  import (
     4  	"math"
     5  	"strconv"
     6  
     7  	"github.com/opencontainers/runc/libcontainer/cgroups"
     8  	"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
     9  	"github.com/opencontainers/runc/libcontainer/configs"
    10  )
    11  
    12  type PidsGroup struct{}
    13  
    14  func (s *PidsGroup) Name() string {
    15  	return "pids"
    16  }
    17  
    18  func (s *PidsGroup) Apply(path string, _ *configs.Resources, pid int) error {
    19  	return apply(path, pid)
    20  }
    21  
    22  func (s *PidsGroup) Set(path string, r *configs.Resources) error {
    23  	if r.PidsLimit != 0 {
    24  		// "max" is the fallback value.
    25  		limit := "max"
    26  
    27  		if r.PidsLimit > 0 {
    28  			limit = strconv.FormatInt(r.PidsLimit, 10)
    29  		}
    30  
    31  		if err := cgroups.WriteFile(path, "pids.max", limit); err != nil {
    32  			return err
    33  		}
    34  	}
    35  
    36  	return nil
    37  }
    38  
    39  func (s *PidsGroup) GetStats(path string, stats *cgroups.Stats) error {
    40  	if !cgroups.PathExists(path) {
    41  		return nil
    42  	}
    43  	current, err := fscommon.GetCgroupParamUint(path, "pids.current")
    44  	if err != nil {
    45  		return err
    46  	}
    47  
    48  	max, err := fscommon.GetCgroupParamUint(path, "pids.max")
    49  	if err != nil {
    50  		return err
    51  	}
    52  	// If no limit is set, read from pids.max returns "max", which is
    53  	// converted to MaxUint64 by GetCgroupParamUint. Historically, we
    54  	// represent "no limit" for pids as 0, thus this conversion.
    55  	if max == math.MaxUint64 {
    56  		max = 0
    57  	}
    58  
    59  	stats.PidsStats.Current = current
    60  	stats.PidsStats.Limit = max
    61  	return nil
    62  }
    63  

View as plain text