mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Add support for cgroup v2 to the installer memory checker
Support both the case where there is a limit imposed on the container and when there isn't. https://pagure.io/freeipa/issue/8635 Signed-off-by: Rob Crittenden <rcritten@redhat.com> Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
parent
279d8b7ec4
commit
176fe83a01
@ -1072,27 +1072,49 @@ def check_available_memory(ca=False):
|
|||||||
|
|
||||||
Use Kb instead of KiB to leave a bit of slush for the OS
|
Use Kb instead of KiB to leave a bit of slush for the OS
|
||||||
"""
|
"""
|
||||||
|
available = None
|
||||||
minimum_suggested = 1000 * 1000 * 1000 * 1.2
|
minimum_suggested = 1000 * 1000 * 1000 * 1.2
|
||||||
if not ca:
|
if not ca:
|
||||||
minimum_suggested -= 150 * 1000 * 1000
|
minimum_suggested -= 150 * 1000 * 1000
|
||||||
if in_container():
|
if in_container():
|
||||||
|
# cgroup v1
|
||||||
if os.path.exists(
|
if os.path.exists(
|
||||||
'/sys/fs/cgroup/memory/memory.limit_in_bytes'
|
'/sys/fs/cgroup/memory/memory.limit_in_bytes'
|
||||||
) and os.path.exists('/sys/fs/cgroup/memory/memory.usage_in_bytes'):
|
) and os.path.exists('/sys/fs/cgroup/memory/memory.usage_in_bytes'):
|
||||||
with open('/sys/fs/cgroup/memory/memory.limit_in_bytes') as fd:
|
limit_file = '/sys/fs/cgroup/memory/memory.limit_in_bytes'
|
||||||
limit = int(fd.readline())
|
usage_file = '/sys/fs/cgroup/memory/memory.usage_in_bytes'
|
||||||
with open('/sys/fs/cgroup/memory/memory.usage_in_bytes') as fd:
|
# cgroup v2
|
||||||
used = int(fd.readline())
|
elif os.path.exists(
|
||||||
available = limit - used
|
'/sys/fs/cgroup/memory.current'
|
||||||
|
) and os.path.exists('/sys/fs/cgroup/memory.max'):
|
||||||
|
limit_file = '/sys/fs/cgroup/memory.max'
|
||||||
|
usage_file = '/sys/fs/cgroup/memory.current'
|
||||||
else:
|
else:
|
||||||
raise ScriptError(
|
raise ScriptError(
|
||||||
"Unable to determine the amount of available RAM"
|
"Unable to determine the amount of available RAM"
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
|
with open(limit_file) as fd:
|
||||||
|
limit = fd.readline()
|
||||||
|
with open(usage_file) as fd:
|
||||||
|
used = int(fd.readline())
|
||||||
|
|
||||||
|
# In cgroup v2 if there is no limit on the container then
|
||||||
|
# the maximum host memory is available. Fall back to the psutil
|
||||||
|
# method for determining availability.
|
||||||
|
if limit != 'max':
|
||||||
|
available = int(limit) - used
|
||||||
|
|
||||||
|
if available is None:
|
||||||
# delay import of psutil. On import it opens files in /proc and
|
# delay import of psutil. On import it opens files in /proc and
|
||||||
# can trigger a SELinux violation.
|
# can trigger a SELinux violation.
|
||||||
import psutil
|
import psutil
|
||||||
available = psutil.virtual_memory().available
|
available = psutil.virtual_memory().available
|
||||||
|
|
||||||
|
if available is None:
|
||||||
|
raise ScriptError(
|
||||||
|
"Unable to determine the amount of available RAM"
|
||||||
|
)
|
||||||
logger.debug("Available memory is %sB", available)
|
logger.debug("Available memory is %sB", available)
|
||||||
if available < minimum_suggested:
|
if available < minimum_suggested:
|
||||||
raise ScriptError(
|
raise ScriptError(
|
||||||
|
Loading…
Reference in New Issue
Block a user