ATLAS Offline Software
Loading...
Searching...
No Matches
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
9from AthenaCommon.Logging import logging
10import resource
11
12
13
14__version__ = '1.2.1'
15__author__ = 'Grigori Rybkine (Grigori.Rybkine@cern.ch)'
16
17__all__ = [ 'SetMaxLimits' ]
18
19log = logging.getLogger( 'ResourceLimits' )
20
21
22
23def _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
38def _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
_maxout(what, descr)
private helper --------------------------------------------------------—
SetMaxLimits()
max out soft resource limits to hard ones -----------------------------—
_max_32bit_address_space(soft, descr)