Reinstate fixLimits - complain if limits are too small.

This commit is contained in:
Bob Lantz
2012-03-13 23:15:13 -07:00
parent 67b06f3a83
commit ebfc4d0d72
2 changed files with 22 additions and 5 deletions
+1 -1
View File
@@ -565,7 +565,7 @@ def init():
# May want to loosen this to handle mnexec in the current dir.
if not quietRun( 'which mnexec' ):
raise Exception( "Could not find mnexec - check $PATH" )
#fixLimits()
fixLimits()
init.inited = True
init.inited = False
+21 -4
View File
@@ -1,12 +1,12 @@
"Utility functions for Mininet."
from time import sleep
from resource import setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
from resource import setrlimit, getrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
import select
from subprocess import call, check_call, Popen, PIPE, STDOUT
import os
from mininet.log import error
from mininet.log import error, warn
# Command execution support
@@ -207,5 +207,22 @@ def makeNumeric( s ):
def fixLimits():
"Fix ridiculously small resource limits."
setrlimit( RLIMIT_NPROC, ( 4096, 8192 ) )
setrlimit( RLIMIT_NOFILE, ( 16384, 32768 ) )
manyprocs = 8192
manyfiles = 32768
minprocs, maxprocs = getrlimit( RLIMIT_NPROC )
minfiles, maxfiles = getrlimit( RLIMIT_NOFILE )
# Root can raise limits
if os.getuid() == 0:
maxprocs = max( maxprocs, manyprocs )
maxfiles = max( maxfiles, manyfiles )
minprocs = min( manyprocs, maxprocs )
minfiles = min( manyfiles, maxfiles )
setrlimit( RLIMIT_NPROC, ( minprocs, maxprocs ) )
setrlimit( RLIMIT_NOFILE, ( minfiles, maxfiles ) )
nprocs = max( getrlimit( RLIMIT_NPROC ) )
nfiles = max( getrlimit( RLIMIT_NOFILE ) )
# Complain if limits are too low
if nprocs < manyprocs:
warn( '*** Warning: process limit is low:', nprocs, 'procs\n' )
if nfiles < manyfiles:
warn( '*** Warning: open file limit is low:', nfiles, 'files \n' )