Skip to content

Commit 69cf037

Browse files
committed
pids limit support
update bash commpletion for pids limit update check config for kernel add docs for pids limit add pids stats add stats to docker client Signed-off-by: Jessica Frazelle <[email protected]>
1 parent 9e2c4de commit 69cf037

21 files changed

Lines changed: 83 additions & 4 deletions

api/client/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (cli *DockerCli) CmdStats(args ...string) error {
164164
fmt.Fprint(cli.out, "\033[2J")
165165
fmt.Fprint(cli.out, "\033[H")
166166
}
167-
io.WriteString(w, "CONTAINER\tCPU %\tMEM USAGE / LIMIT\tMEM %\tNET I/O\tBLOCK I/O\n")
167+
io.WriteString(w, "CONTAINER\tCPU %\tMEM USAGE / LIMIT\tMEM %\tNET I/O\tBLOCK I/O\tPIDS\n")
168168
}
169169

170170
for range time.Tick(500 * time.Millisecond) {

api/client/stats_helpers.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type containerStats struct {
2424
NetworkTx float64
2525
BlockRead float64
2626
BlockWrite float64
27+
PidsCurrent uint64
2728
mu sync.RWMutex
2829
err error
2930
}
@@ -167,13 +168,14 @@ func (s *containerStats) Display(w io.Writer) error {
167168
if s.err != nil {
168169
return s.err
169170
}
170-
fmt.Fprintf(w, "%s\t%.2f%%\t%s / %s\t%.2f%%\t%s / %s\t%s / %s\n",
171+
fmt.Fprintf(w, "%s\t%.2f%%\t%s / %s\t%.2f%%\t%s / %s\t%s / %s\t%d\n",
171172
s.Name,
172173
s.CPUPercentage,
173174
units.HumanSize(s.Memory), units.HumanSize(s.MemoryLimit),
174175
s.MemoryPercentage,
175176
units.HumanSize(s.NetworkRx), units.HumanSize(s.NetworkTx),
176-
units.HumanSize(s.BlockRead), units.HumanSize(s.BlockWrite))
177+
units.HumanSize(s.BlockRead), units.HumanSize(s.BlockWrite),
178+
s.PidsCurrent)
177179
return nil
178180
}
179181

api/client/stats_unit_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ func TestDisplay(t *testing.T) {
1919
NetworkTx: 800 * 1024 * 1024,
2020
BlockRead: 100 * 1024 * 1024,
2121
BlockWrite: 800 * 1024 * 1024,
22+
PidsCurrent: 1,
2223
mu: sync.RWMutex{},
2324
}
2425
var b bytes.Buffer
2526
if err := c.Display(&b); err != nil {
2627
t.Fatalf("c.Display() gave error: %s", err)
2728
}
2829
got := b.String()
29-
want := "app\t30.00%\t104.9 MB / 2.147 GB\t4.88%\t104.9 MB / 838.9 MB\t104.9 MB / 838.9 MB\n"
30+
want := "app\t30.00%\t104.9 MB / 2.147 GB\t4.88%\t104.9 MB / 838.9 MB\t104.9 MB / 838.9 MB\t1\n"
3031
if got != want {
3132
t.Fatalf("c.Display() = %q, want %q", got, want)
3233
}

contrib/check-config.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ echo 'Optional Features:'
202202
{
203203
check_flags SECCOMP
204204
}
205+
{
206+
check_flags CGROUP_PIDS
207+
}
205208
{
206209
check_flags MEMCG_KMEM MEMCG_SWAP MEMCG_SWAP_ENABLED
207210
if is_set MEMCG_SWAP && ! is_set MEMCG_SWAP_ENABLED; then

contrib/completion/bash/docker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,7 @@ _docker_run() {
16371637
--net-alias
16381638
--oom-score-adj
16391639
--pid
1640+
--pids-limit
16401641
--publish -p
16411642
--restart
16421643
--security-opt

contrib/completion/zsh/_docker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ __docker_subcommand() {
534534
"($help)*--net-alias=[Add network-scoped alias for the container]:alias: "
535535
"($help)--oom-kill-disable[Disable OOM Killer]"
536536
"($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]"
537+
"($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]"
537538
"($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]"
538539
"($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports"
539540
"($help)--pid=[PID namespace to use]:PID: "

daemon/container_operations_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro
198198
BlkioThrottleWriteBpsDevice: writeBpsDevice,
199199
BlkioThrottleReadIOpsDevice: readIOpsDevice,
200200
BlkioThrottleWriteIOpsDevice: writeIOpsDevice,
201+
PidsLimit: c.HostConfig.PidsLimit,
201202
MemorySwappiness: -1,
202203
}
203204

daemon/daemon_unix.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi
285285
resources.OomKillDisable = nil
286286
}
287287

288+
if resources.PidsLimit != 0 && !sysInfo.PidsLimit {
289+
warnings = append(warnings, "Your kernel does not support pids limit capabilities, pids limit discarded.")
290+
logrus.Warnf("Your kernel does not support pids limit capabilities, pids limit discarded.")
291+
resources.PidsLimit = 0
292+
}
293+
288294
// cpu subsystem checks and adjustments
289295
if resources.CPUShares > 0 && !sysInfo.CPUShares {
290296
warnings = append(warnings, "Your kernel does not support CPU shares. Shares discarded.")

daemon/execdriver/driver_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Resources struct {
5050
CPUPeriod int64 `json:"cpu_period"`
5151
Rlimits []*units.Rlimit `json:"rlimits"`
5252
OomKillDisable bool `json:"oom_kill_disable"`
53+
PidsLimit int64 `json:"pids_limit"`
5354
MemorySwappiness int64 `json:"memory_swappiness"`
5455
}
5556

@@ -201,6 +202,7 @@ func SetupCgroups(container *configs.Config, c *Command) error {
201202
container.Cgroups.Resources.BlkioThrottleReadIOPSDevice = c.Resources.BlkioThrottleReadIOpsDevice
202203
container.Cgroups.Resources.BlkioThrottleWriteIOPSDevice = c.Resources.BlkioThrottleWriteIOpsDevice
203204
container.Cgroups.Resources.OomKillDisable = c.Resources.OomKillDisable
205+
container.Cgroups.Resources.PidsLimit = c.Resources.PidsLimit
204206
container.Cgroups.Resources.MemorySwappiness = c.Resources.MemorySwappiness
205207
}
206208

daemon/stats_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func convertStatsToAPITypes(ls *libcontainer.Stats) *types.StatsJSON {
6161
Stats: mem.Stats,
6262
Failcnt: mem.Usage.Failcnt,
6363
}
64+
pids := cs.PidsStats
65+
s.PidsStats = types.PidsStats{
66+
Current: pids.Current,
67+
}
6468
}
6569

6670
return s

0 commit comments

Comments
 (0)