From: David E. Eisenstat <deisenst@cs.princeton.edu> Date: Mon, 5 Feb 2007 16:39:29 +0000 (+0000) Subject: Automatically adjust stack sizes downward to avoid exhausting virtual X-Git-Tag: planetlab-4_0-rc1~6 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=a474ff48b0b550c033464f3a063fc5d162bca13e;p=nodemanager.git Automatically adjust stack sizes downward to avoid exhausting virtual memory. --- diff --git a/nm.py b/nm.py index 23f5edc..6e56501 100644 --- a/nm.py +++ b/nm.py @@ -7,6 +7,8 @@ import time import xmlrpclib import socket import os +import sys +import resource import logger import tools @@ -14,6 +16,9 @@ import tools from config import Config from plcapi import PLCAPI + +savedargv = sys.argv[:] + parser = optparse.OptionParser() parser.add_option('-d', '--daemon', action='store_true', dest='daemon', default=False, help='run daemonized') parser.add_option('-s', '--startup', action='store_true', dest='startup', default=False, help='run all sliver startup scripts') @@ -70,7 +75,15 @@ def run(): except: logger.log_exc() -if __name__ == '__main__': run() +if __name__ == '__main__': + stacklim = 512*1024 # 0.5 MiB + curlim = resource.getrlimit(resource.RLIMIT_STACK)[0] # soft limit + if curlim > stacklim: + resource.setrlimit(resource.RLIMIT_STACK, (stacklim, stacklim)) + # for some reason, doesn't take effect properly without the exec() + python = '/usr/bin/python' + os.execv(python, [python] + savedargv) + run() else: # This is for debugging purposes. Open a copy of Python and import nm tools.as_daemon_thread(run)