Skip to content

Commit 4eb2706

Browse files
committed
libcontainer: set PidsLimit to be a pointer
Signed-off-by: Peter Hunt <[email protected]>
1 parent fefc1d3 commit 4eb2706

File tree

8 files changed

+19
-11
lines changed

8 files changed

+19
-11
lines changed

libcontainer/cgroups/fs/pids.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ func (s *PidsGroup) Apply(path string, _ *configs.Resources, pid int) error {
2020
}
2121

2222
func (s *PidsGroup) Set(path string, r *configs.Resources) error {
23+
if r.PidsLimit == nil {
24+
return nil
25+
}
2326
// "max" is the fallback value.
2427
limit := "max"
2528

26-
if r.PidsLimit > 0 {
27-
limit = strconv.FormatInt(r.PidsLimit, 10)
29+
if *r.PidsLimit > 0 {
30+
limit = strconv.FormatInt(*r.PidsLimit, 10)
2831
}
2932

3033
return cgroups.WriteFile(path, "pids.max", limit)

libcontainer/cgroups/fs2/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func needAnyControllers(r *configs.Resources) (bool, error) {
3939
return ok
4040
}
4141

42-
if have("pids") {
42+
if r.PidsLimit != nil && have("pids") {
4343
return true, nil
4444
}
4545
if isMemorySet(r) && have("memory") {

libcontainer/cgroups/fs2/pids.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import (
1414
)
1515

1616
func setPids(dirPath string, r *configs.Resources) error {
17-
if val := numToStr(r.PidsLimit); val != "" {
17+
if r.PidsLimit == nil {
18+
return nil
19+
}
20+
if val := numToStr(*r.PidsLimit); val != "" {
1821
if err := cgroups.WriteFile(dirPath, "pids.max", val); err != nil {
1922
return err
2023
}

libcontainer/cgroups/systemd/v1.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ func genV1ResourcesProperties(r *configs.Resources, cm *dbusConnManager) ([]syst
9898
newProp("BlockIOWeight", uint64(r.BlkioWeight)))
9999
}
100100

101-
if r.PidsLimit > 0 || r.PidsLimit == -1 {
101+
if r.PidsLimit != nil && (*r.PidsLimit > 0 || *r.PidsLimit == -1) {
102102
properties = append(properties,
103-
newProp("TasksMax", uint64(r.PidsLimit)))
103+
newProp("TasksMax", uint64(*r.PidsLimit)))
104104
}
105105

106106
err = addCpuset(cm, &properties, r.CpusetCpus, r.CpusetMems)

libcontainer/cgroups/systemd/v2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ func genV2ResourcesProperties(dirPath string, r *configs.Resources, cm *dbusConn
257257

258258
addCpuQuota(cm, &properties, r.CpuQuota, r.CpuPeriod)
259259

260-
if r.PidsLimit > 0 || r.PidsLimit == -1 {
260+
if r.PidsLimit != nil && (*r.PidsLimit > 0 || *r.PidsLimit == -1) {
261261
properties = append(properties,
262-
newProp("TasksMax", uint64(r.PidsLimit)))
262+
newProp("TasksMax", uint64(*r.PidsLimit)))
263263
}
264264

265265
err = addCpuset(cm, &properties, r.CpusetCpus, r.CpusetMems)

libcontainer/configs/cgroup_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type Resources struct {
8888
CPUIdle *int64 `json:"cpu_idle,omitempty"`
8989

9090
// Process limit; set <= `0' to disable limit.
91-
PidsLimit int64 `json:"pids_limit"`
91+
PidsLimit *int64 `json:"pids_limit"`
9292

9393
// Specifies per cgroup weight, range is from 10 to 1000.
9494
BlkioWeight uint16 `json:"blkio_weight"`

libcontainer/specconv/spec_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,8 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi
768768
c.Resources.CPUIdle = r.CPU.Idle
769769
}
770770
if r.Pids != nil {
771-
c.Resources.PidsLimit = r.Pids.Limit
771+
l := r.Pids.Limit
772+
c.Resources.PidsLimit = &l
772773
}
773774
if r.BlockIO != nil {
774775
if r.BlockIO.Weight != nil {

update.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,9 @@ other options are ignored.
310310
config.Cgroups.Resources.MemoryReservation = *r.Memory.Reservation
311311
config.Cgroups.Resources.MemorySwap = *r.Memory.Swap
312312
config.Cgroups.Resources.MemoryCheckBeforeUpdate = *r.Memory.CheckBeforeUpdate
313-
config.Cgroups.Resources.PidsLimit = r.Pids.Limit
314313
config.Cgroups.Resources.Unified = r.Unified
314+
l := r.Pids.Limit
315+
config.Cgroups.Resources.PidsLimit = &l
315316

316317
// Update Intel RDT
317318
l3CacheSchema := context.String("l3-cache-schema")

0 commit comments

Comments
 (0)