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