Updated mininet/util.py to support better resource setting semantics and protected with try block

This commit is contained in:
Brian O'Connor
2013-09-12 13:49:40 -07:00
parent 501a164eba
commit 4ea0c0936d
+13 -6
View File
@@ -1,6 +1,6 @@
"Utility functions for Mininet."
from mininet.log import output, info, error, warn
from mininet.log import output, info, error, warn, debug
from time import sleep
from resource import getrlimit, setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
@@ -361,16 +361,17 @@ def sysctlTestAndSet( name, limit ):
if '/' not in name:
name = '/proc/sys/' + name.replace( '.', '/' )
#read limit
f = open( name, 'r+' )
oldLimit = f.readline()
with open( name, 'r' ) as readFile:
oldLimit = readFile.readline()
if type( limit ) is int:
#compare integer limits before overriding
if int( oldLimit ) < limit:
f.write( "%d" % limit )
with open( name, 'w' ) as writeFile:
writeFile.write( "%d" % limit )
else:
#overwrite non-integer limits
f.write( limit )
f.close()
with open( name, 'w' ) as writeFile:
writeFile.write( limit )
def rlimitTestAndSet( name, limit ):
"Helper function to set rlimits"
@@ -381,6 +382,8 @@ def rlimitTestAndSet( name, limit ):
def fixLimits():
"Fix ridiculously small resource limits."
debug( "*** Setting resource limits\n" )
try:
rlimitTestAndSet( RLIMIT_NPROC, 8192 )
rlimitTestAndSet( RLIMIT_NOFILE, 16384 )
#Increase open file limit
@@ -399,6 +402,10 @@ def fixLimits():
sysctlTestAndSet( 'net.ipv4.route.max_size', 32768 )
#Increase number of PTYs for nodes
sysctlTestAndSet( 'kernel.pty.max', 20000 )
assert False
except:
warn( "*** Error setting resource limits. "
"Mininet's performance may be affected.\n" )
def mountCgroups():
"Make sure cgroups file system is mounted"