ATLAS Offline Software
ResourceLimits.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 # File: AthenaCommon/python/ResourceLimits.py
4 # Author: Grigori Rybkine (Grigori.Rybkine@rhul.ac.uk)
5 # Modified: Wim Lavrijsen (WLavrijsen@lbl.gov)
6 
7 """Helper to max soft resource limits to the hard ones."""
8 
9 from AthenaCommon.Logging import logging
10 import resource
11 
12 
13 
14 __version__ = '1.2.1'
15 __author__ = 'Grigori Rybkine (Grigori.Rybkine@cern.ch)'
16 
17 __all__ = [ 'SetMaxLimits' ]
18 
19 log = logging.getLogger( 'ResourceLimits' )
20 
21 
22 
23 def _maxout( what, descr ):
24  soft, hard = resource.getrlimit( what )
25  if soft < hard or ( hard == -1 and soft != hard ):
26  log.debug( 'setting soft %s limit to %s (was: %s)', descr,
27  hard == -1 and 'unlimited' or str(hard),
28  soft == -1 and 'unlimited' or str(soft), )
29  try:
30  resource.setrlimit( what, (hard,hard) )
31  except ValueError:
32  if what != resource.RLIMIT_AS or hard != -1: raise
33  import platform
34  if platform.architecture()[0] != '32bit': raise
35  if platform.machine() in ['i386', 'i486', 'i586', 'i686']: raise
36  _max_32bit_address_space( soft, descr )
37 
38 def _max_32bit_address_space( soft, descr ):
39  MAX_AS = 2**32
40  _64MB = 64*1024*1024
41  hard = MAX_AS
42  while hard > soft:
43  try:
44  log.debug( 'setting soft %s limit to %s (was: %s)', descr,
45  str(hard),
46  str(soft), )
47  resource.setrlimit( resource.RLIMIT_AS, (hard,hard) )
48  except ValueError:
49  hard -= _64MB
50  else:
51  log.debug( 'set soft %s limit to %s (was: %s)', descr,
52  str(hard),
53  str(soft), )
54  return
55 
56 
58  try:
59  _maxout( resource.RLIMIT_AS, 'address space' )
60  _maxout( resource.RLIMIT_RSS, 'resident state' )
61  except (ValueError,resource.error) as e:
62  log.warning( 'failed to set max resource limits (%s)', str(e) )
63 
python.ResourceLimits.SetMaxLimits
def SetMaxLimits()
max out soft resource limits to hard ones -----------------------------—
Definition: ResourceLimits.py:57
python.ResourceLimits._maxout
def _maxout(what, descr)
private helper --------------------------------------------------------—
Definition: ResourceLimits.py:23
str
Definition: BTagTrackIpAccessor.cxx:11
python.ResourceLimits._max_32bit_address_space
def _max_32bit_address_space(soft, descr)
Definition: ResourceLimits.py:38