Browse Source

Allow to set limit memory on containers

This will add the features `--memory`, `--memory-swap` and
`--memory-swappiness`

Conflicts:
	paunch/builder/compose1.py
	paunch/builder/podman.py
	paunch/tests/test_builder_compose1.py
	paunch/tests/test_builder_podman.py

Change-Id: Icb44564906dbbe2d0407eaf1ab01eb450fcc73ce
Closes-Bug: #1801949
(cherry picked from commit 797e7ae19c)
changes/33/692433/3
Marc Methot 1 year ago
parent
commit
ccc7b278c1
3 changed files with 21 additions and 1 deletions
  1. +6
    -0
      paunch/builder/compose1.py
  2. +7
    -1
      paunch/tests/test_builder_compose1.py
  3. +8
    -0
      releasenotes/notes/cgroups-memory-limit-ca571375d8047425.yaml

+ 6
- 0
paunch/builder/compose1.py View File

@@ -199,6 +199,12 @@ class ComposeV1Builder(object):
cmd.append('--cpuset-cpus=%s' % cconfig['cpuset_cpus'])
else:
cmd.append('--cpuset-cpus=%s' % common.get_cpus_allowed_list())
if 'mem_limit' in cconfig:
cmd.append('--memory=%s' % cconfig['mem_limit'])
if 'memswap_limit' in cconfig:
cmd.append('--memory-swap=%s' % cconfig['memswap_limit'])
if 'mem_swappiness' in cconfig:
cmd.append('--memory-swappiness=%s' % cconfig['mem_swappiness'])

cmd.append(cconfig.get('image', ''))
cmd.extend(self.command_argument(cconfig.get('command')))

+ 7
- 1
paunch/tests/test_builder_compose1.py View File

@@ -434,7 +434,10 @@ three-12345678 three''', '', 0),
},
'env_file': '/tmp/foo.env',
'log_tag': '{{.ImageName}}/{{.Name}}/{{.ID}}',
'security_opt': 'label:disable'
'security_opt': 'label:disable',
'mem_limit': '1G',
'memswap_limit': '1G',
'mem_swappiness': '60'
}
}
builder = compose1.ComposeV1Builder('foo', config, None)
@@ -450,6 +453,9 @@ three-12345678 three''', '', 0),
'--privileged=true', '--restart=always', '--user=bar',
'--log-opt=tag={{.ImageName}}/{{.Name}}/{{.ID}}',
'--security-opt=label:disable', '--cpuset-cpus=0,1,2,3',
'--memory=1G',
'--memory-swap=1G',
'--memory-swappiness=60',
'centos:7'],
cmd
)

+ 8
- 0
releasenotes/notes/cgroups-memory-limit-ca571375d8047425.yaml View File

@@ -0,0 +1,8 @@
---
features:
- |
Add `--memory=x` option for the action run a container. This allows
setting constraints on max memory usage, which is `memory.limit_in_bytes`
in memory cgroup.
Also added `--memory-swap` and `--memory-swappiness` options to control
swap settings.

Loading…
Cancel
Save