|
| 1 | +# Kdump configuration common methods |
| 2 | +# |
| 3 | +# Copyright (C) 2014 Red Hat, Inc. |
| 4 | +# |
| 5 | +# This copyrighted material is made available to anyone wishing to use, |
| 6 | +# modify, copy, or redistribute it subject to the terms and conditions of |
| 7 | +# the GNU General Public License v.2, or (at your option) any later version. |
| 8 | +# This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 | +# ANY WARRANTY expressed or implied, including the implied warranties of |
| 10 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 11 | +# Public License for more details. You should have received a copy of the |
| 12 | +# GNU General Public License along with this program; if not, write to the |
| 13 | +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 14 | +# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the |
| 15 | +# source code or documentation are not subject to the GNU General Public |
| 16 | +# License and may only be used or replicated with the express permission of |
| 17 | +# Red Hat, Inc. |
| 18 | +# |
| 19 | +# Red Hat Author(s): David Shea <dshea@redhat.com> |
| 20 | +# |
| 21 | + |
| 22 | +__all__ = ["getReservedMemory", "getTotalMemory", "getMemoryBounds"] |
| 23 | + |
| 24 | +from pyanaconda.isys import total_memory |
| 25 | +from pyanaconda.flags import flags |
| 26 | + |
| 27 | +_reservedMemory = None |
| 28 | +def getReservedMemory(): |
| 29 | + """Return the amount of memory currently reserved for kdump in MB.""" |
| 30 | + global _reservedMemory |
| 31 | + |
| 32 | + # Check if the value has already been read |
| 33 | + if _reservedMemory is not None: |
| 34 | + return _reservedMemory |
| 35 | + |
| 36 | + try: |
| 37 | + with open("/sys/kernel/kexec_crash_size", "r") as fobj: |
| 38 | + _reservedMemory = int(fobj.read()) / (1024*1024) |
| 39 | + return _reservedMemory |
| 40 | + except (ValueError, IOError): |
| 41 | + return 0 |
| 42 | + |
| 43 | +def getTotalMemory(): |
| 44 | + """Return the total amount of system memory in MB |
| 45 | +
|
| 46 | + This is the amount reported by /proc/meminfo plus the aount |
| 47 | + currently reserved for kdump. |
| 48 | + """ |
| 49 | + |
| 50 | + # total_memory return memory in KB, convert to MB |
| 51 | + availMem = total_memory() / 1024 |
| 52 | + |
| 53 | + return availMem + getReservedMemory() |
| 54 | + |
| 55 | +def getMemoryBounds(): |
| 56 | + """Return a tuple of (lower, upper, step) for kdump reservation limits. |
| 57 | +
|
| 58 | + If there is not enough memory available to use kdump, both lower and |
| 59 | + upper will be 0. |
| 60 | + """ |
| 61 | + |
| 62 | + totalMemory = getTotalMemory() |
| 63 | + |
| 64 | + if flags.targetarch == 'ppc64': |
| 65 | + lowerBound = 256 |
| 66 | + minUsable = 1024 |
| 67 | + step = 1 |
| 68 | + else: |
| 69 | + lowerBound = 128 |
| 70 | + minUsable = 256 |
| 71 | + step = 1 |
| 72 | + |
| 73 | + upperBound = (totalMemory - minUsable) - (totalMemory % step) |
| 74 | + |
| 75 | + if upperBound < lowerBound: |
| 76 | + upperBound = lowerBound = 0 |
| 77 | + |
| 78 | + return (lowerBound, upperBound, step) |
0 commit comments