8000 Add pids-limit support in docker update · moby/moby@74eb258 · GitHub
[go: up one dir, main page]

Skip to content

Commit 74eb258

Browse files
darkowlzzcpuguy83
authored andcommitted
Add pids-limit support in docker update
- Adds updating PidsLimit in UpdateContainer(). - Adds setting PidsLimit in toContainerResources(). Signed-off-by: Sunny Gogoi <indiasuny000@gmail.com> Signed-off-by: Brian Goff <cpuguy83@gmail.com>
1 parent d440fea commit 74eb258

File tree

11 files changed

+98
-10
lines changed

11 files changed

+98
-10
lines changed

api/swagger.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,10 @@ definitions:
460460
type: "boolean"
461461
x-nullable: true
462462
PidsLimit:
463-
description: "Tune a container's pids limit. Set -1 for unlimited."
463+
description: "Tune a container's pids limit. Set 0 or -1 for unlimited. Leave null to not change"
464464
type: "integer"
465465
format: "int64"
466+
x-nullable: true
466467
Ulimits:
467468
description: |
468469
A list of resource limits to set in the container. For example: `{"Name": "nofile", "Soft": 1024, "Hard": 2048}`"
@@ -3689,6 +3690,10 @@ definitions:
36893690
See [cpuset(7)](https://www.kernel.org/doc/Documentation/cgroup-v1/cpusets.txt)
36903691
type: "boolean"
36913692
example: true
3693+
PidsLimit:
3694+
description: "Indicates if the host kernel has PID limit support enabled."
3695+
type: "boolean"
3696+
example: true
36923697
OomKillDisable:
36933698
description: "Indicates if OOM killer disable is supported on the host."
36943699
type: "boolean"
@@ -4625,7 +4630,7 @@ paths:
46254630
OomKillDisable: false
46264631
OomScoreAdj: 500
46274632
PidMode: ""
4628-
PidsLimit: -1
4633+
PidsLimit: 0
46294634
PortBindings:
46304635
22/tcp:
46314636
- HostPort: "11022"

api/types/container/host_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ type Resources struct {
334334
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
335335
MemorySwappiness *int64 // Tuning container memory swappiness behaviour
336336
OomKillDisable *bool // Whether to disable OOM Killer or not
337-
PidsLimit int64 // Setting pids limit for a container
337+
PidsLimit *int64 // Setting pids limit for a container
338338
Ulimits []*units.Ulimit // List of ulimits to be set in the container
339339

340340
// Applicable to Windows

api/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ type Info struct {
164164
CPUCfsQuota bool `json:"CpuCfsQuota"`
165165
CPUShares bool
166166
CPUSet bool
167+
PidsLimit bool
167168
IPv4Forwarding bool
168169
BridgeNfIptables bool
169170
BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`

container/container_unix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfi
342342
if resources.CPURealtimeRuntime != 0 {
343343
cResources.CPURealtimeRuntime = resources.CPURealtimeRuntime
344344
}
345+
if resources.PidsLimit != nil {
346+
cResources.PidsLimit = resources.PidsLimit
347+
}
345348

346349
// update HostConfig of container
347350
if hostConfig.RestartPolicy.Name != "" {

container/container_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfi
159159
resources.MemorySwap != 0 ||
160160
resources.MemorySwappiness != nil ||
161161
resources.OomKillDisable != nil ||
162-
resources.PidsLimit != 0 ||
162+
(resources.PidsLimit != nil && *resources.PidsLimit != 0) ||
163163
len(resources.Ulimits) != 0 ||
164164
resources.CPUCount != 0 ||
165165
resources.CPUPercent != 0 ||

daemon/daemon_unix.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ func getMemoryResources(config containertypes.Resources) *specs.LinuxMemory {
118118
return &memory
119119
}
120120

121+
func getPidsLimit(config containertypes.Resources) *specs.LinuxPids {
122+
limit := &specs.LinuxPids{}
123+
if config.PidsLimit != nil {
124+
limit.Limit = *config.PidsLimit
125+
if limit.Limit == 0 {
126+
// docker API allows 0 to unset this to be consistent with default values.
127+
// when updating values, runc requires -1
128+
limit.Limit = -1
129+
}
130+
}
131+
return limit
132+
}
133+
121134
func getCPUResources(config containertypes.Resources) (*specs.LinuxCPU, error) {
122135
cpu := specs.LinuxCPU{}
123136

@@ -453,9 +466,10 @@ func verifyPlatformContainerResources(resources *containertypes.Resources, sysIn
453466
if resources.OomKillDisable != nil && *resources.OomKillDisable && resources.Memory == 0 {
454467
warnings = append(warnings, "OOM killer is disabled for the container, but no memory limit is set, this can result in the system running out of resources.")
455468
}
456-
if resources.PidsLimit != 0 && !sysInfo.PidsLimit {
469+
if resources.PidsLimit != nil && *resources.PidsLimit != 0 && !sysInfo.PidsLimit {
457470
warnings = append(warnings, "Your kernel does not support pids limit capabilities or the cgroup is not mounted. PIDs limit discarded.")
458-
resources.PidsLimit = 0
471+
var limit int64
472+
resources.PidsLimit = &limit
459473
}
460474

461475
// cpu subsystem checks and adjustments

daemon/daemon_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func verifyPlatformContainerResources(resources *containertypes.Resources, isHyp
181181
if resources.OomKillDisable != nil && *resources.OomKillDisable {
182182
return warnings, fmt.Errorf("invalid option: Windows does not support OomKillDisable")
183183
}
184-
if resources.PidsLimit != 0 {
184+
if resources.PidsLimit != nil && *resources.PidsLimit != 0 {
185185
return warnings, fmt.Errorf("invalid option: Windows does not support PidsLimit")
186186
}
187187
if len(resources.Ulimits) != 0 {

daemon/info_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func (daemon *Daemon) fillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo)
2727
v.CPUCfsQuota = sysInfo.CPUCfsQuota
2828
v.CPUShares = sysInfo.CPUShares
2929
v.CPUSet = sysInfo.Cpuset
30+
v.PidsLimit = sysInfo.PidsLimit
3031
v.Runtimes = daemon.configStore.GetAllRuntimes()
3132
v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
3233
v.InitBinary = daemon.configStore.GetInitPath()

daemon/oci_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ func setResources(s *specs.Spec, r containertypes.Resources) error {
7272
ThrottleReadIOPSDevice: readIOpsDevice,
7373
ThrottleWriteIOPSDevice: writeIOpsDevice,
7474
},
75-
Pids: &specs.LinuxPids{
76-
Limit: r.PidsLimit,
77-
},
75+
Pids: getPidsLimit(r),
7876
}
7977

8078
if s.Linux.Resources != nil && len(s.Linux.Resources.Devices) > 0 {

daemon/update_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ func toContainerdResources(resources container.Resources) *libcontainerd.Resourc
5050
r.Memory.Swap = &resources.MemorySwap
5151
}
5252

53+
r.Pids = getPidsLimit(resources)
5354
return &r
5455
}

0 commit comments

Comments
 (0)
0