Skip to content

Commit

Permalink
api: move to virt-mem and mem
Browse files Browse the repository at this point in the history
  • Loading branch information
seirl committed Jan 31, 2018
1 parent cf26cbe commit b203b81
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
33 changes: 25 additions & 8 deletions camisole/isolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,30 @@ async def communicate(cmdline, data=None, **kwargs):
return retcode, stdout, stderr


OPTIONS = [
'cg-mem',
CAMISOLE_OPTIONS = [
'extra-time',
'fsize',
'mem',
'processes',
'quota',
'stack',
'time',
'virt-mem',
'wall-time',
]

CAMISOLE_TO_ISOLATE_OPTS = {
# Memory is resident, if you want address space it's virtual memory
'virt-mem': 'mem',
'mem': 'cg-mem',
}

ISOLATE_TO_CAMISOLE_META = {
# Consistency with the limit name
# https://github.com/ioi/isolate/issues/20
'time-wall': 'wall-time',
}


class Isolator:
def __init__(self, opts, allowed_dirs=None):
Expand Down Expand Up @@ -136,9 +148,12 @@ async def __aexit__(self, exc, value, tb):
'XX': 'INTERNAL_ERROR',
}
self.meta['status'] = verbose_status[self.meta['status']]
# replace time-wall with wall-time for consistency with the limit name
# https://github.com/ioi/isolate/issues/20
self.meta['wall-time'] = self.meta.pop('time-wall')
print(self.meta)

This comment has been minimized.

Copy link
@zopieux

zopieux Jan 31, 2018

Member

Much debug print() wow.


for imeta, cmeta in ISOLATE_TO_CAMISOLE_META.items():
if imeta in self.meta:
self.meta[cmeta] = self.meta.pop(imeta)
print(self.meta)

self.info = {
'stdout': self.stdout,
Expand All @@ -161,12 +176,14 @@ async def run(self, cmdline, data=None, env=None,
cmd_run += list(itertools.chain(
*[('-d', d) for d in self.allowed_dirs]))

for opt in OPTIONS:
for opt in CAMISOLE_OPTIONS:
v = self.opts.get(opt)
iopt = CAMISOLE_TO_ISOLATE_OPTS.get(opt, opt)

if v is not None:
cmd_run.append(f'--{opt}={v!s}')
cmd_run.append(f'--{iopt}={v!s}')
# Unlike isolate, we don't limit the number of processes by default
elif opt == 'processes':
elif iopt == 'processes':
cmd_run.append('-p')

for e in ['PATH', 'LD_LIBRARY_PATH', 'LANG']:
Expand Down
1 change: 1 addition & 0 deletions camisole/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def explore(obj, schema, path):
'quota': O(str),
'stack': O(int),
'time': O(number),
'virt-mem': O(int),
'wall-time': O(number),
}

Expand Down
5 changes: 5 additions & 0 deletions doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ instance running on port 42920. Test your installation by visiting this URL::

$ curl http://localhost:42920/

**Note**: You can log into the VM with root:camisole or camisole:camisole. Be
careful to change the passwords and/or disable sshd before exposing the VM to
your infrastructure. Ideally, the virtual machine shouldn't be accessible
directly from the internet.

Archlinux packages
------------------

Expand Down
8 changes: 4 additions & 4 deletions doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ for the compilation and the execution, respectively.
There are a lot of ways you can limit the resources of both the compilation and
the execution of your program:

- ``cg-mem``: limit the available memory of each process (kilobytes)
- ``time``: limit the user time of the program (seconds)
- ``wall-time``: limit the wall time of the program (seconds)
- ``extra-time``: grace period before killing a program after it exceeded a
time limit (seconds)
- ``mem``: limit the available memory of each process (kilobytes)
- ``virt-mem``: limit the address space of each process (kilobytes)
- ``fsize``: limit the size of files created by the program (kilobytes)
- ``mem``: limit the address space of each process (kilobytes)
- ``processes``: limit the number of processes and/or threads
- ``quota``: limit the disk quota to a number of blocks and inodes (separate
both numbers by a comma, eg. ``10,30``)
- ``stack``: limit the stack size of each process (kilobytes)
- ``time``: limit the user time of the program (seconds)
- ``wall-time``: limit the wall time of the program (seconds)

This example demonstrates the use of resource limitations for both the
compilation and execution:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def python_list(n, max_mem=None):
args = {}
if max_mem:
args['execute'] = {'mem': max_mem}
args['execute'] = {'virt-mem': max_mem}
return camisole.languages.python.Python({
'tests': [{}],
'source': 'print(list(range({}))[-1])'.format(n),
Expand Down

0 comments on commit b203b81

Please sign in to comment.