2017-12-01 02:22:28 +00:00
|
|
|
#!/usr/bin/env python3
|
2017-12-01 04:09:14 +00:00
|
|
|
"""
|
|
|
|
Simplest program that tries to allocate a large amount of RAM.
|
2017-12-01 02:22:28 +00:00
|
|
|
|
2017-12-01 04:09:14 +00:00
|
|
|
malloc lies on Linux by default, so we use memset to force the
|
|
|
|
kernel to actually give us real memory.
|
2017-12-01 08:41:50 +00:00
|
|
|
|
|
|
|
NOTE: This file has to be duplicated & present in all the following locations:
|
|
|
|
- tests/memlimit/dockerfile/postBuild
|
|
|
|
- tests/memlimit/dockerfile/postBuild
|
2020-08-10 07:33:05 +00:00
|
|
|
See https://github.com/jupyterhub/repo2docker/issues/160 for reason
|
2017-12-01 04:09:14 +00:00
|
|
|
"""
|
|
|
|
from ctypes import cdll, c_void_p, memset
|
|
|
|
import os
|
|
|
|
|
|
|
|
libc = cdll.LoadLibrary("libc.so.6")
|
|
|
|
libc.malloc.restype = c_void_p
|
|
|
|
|
2019-05-31 09:10:17 +00:00
|
|
|
with open("mem_allocate_mb") as f:
|
2017-12-01 04:09:14 +00:00
|
|
|
mem_allocate_mb = int(f.read().strip())
|
|
|
|
|
|
|
|
size = 1024 * 1024 * mem_allocate_mb
|
|
|
|
print("trying to allocate {}MB".format(mem_allocate_mb))
|
|
|
|
|
|
|
|
ret = libc.malloc(size)
|
|
|
|
|
|
|
|
memset(ret, 0, size)
|