Skip to content

Commit 3a1a429

Browse files
author
Matthew Fisher
committed
Merge pull request #3214 from aledbf/disable_swap
feat(controller): disable swap usage if there is a memory limit
2 parents eec5c24 + 91d50a0 commit 3a1a429

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

deis/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os.path
77
import random
88
import string
9+
import semantic_version
910
import sys
1011
import tempfile
1112

@@ -340,3 +341,12 @@
340341
if os.path.exists('/templates/confd_settings.py'):
341342
sys.path.append('/templates')
342343
from confd_settings import * # noqa
344+
345+
346+
DOCKER_VERSION = os.environ.get('DOCKER_VERSION', '1.4.1')
347+
348+
DISABLE_SWAP = ""
349+
350+
if (semantic_version.validate(DOCKER_VERSION) and
351+
semantic_version.Version(DOCKER_VERSION) >= semantic_version.Version('1.5.0')):
352+
DISABLE_SWAP = "--memory-swap=-1"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ paramiko==1.15.2
1616
psycopg2==2.6
1717
python-etcd==0.3.2
1818
PyYAML==3.11
19+
semantic_version==2.3.1
1920
setproctitle==1.1.8
2021
static==1.1.1
2122
South==1.0.2

scheduler/fleet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _create_container(self, name, image, command, unit, **kwargs):
129129
# prepare memory limit for the container type
130130
mem = kwargs.get('memory', {}).get(l['c_type'], None)
131131
if mem:
132-
l.update({'memory': '-m {}'.format(mem.lower())})
132+
l.update({'memory': '-m {} {} '.format(mem.lower(), settings.DISABLE_SWAP)})
133133
else:
134134
l.update({'memory': ''})
135135
# prepare memory limit for the container type

0 commit comments

Comments
 (0)