We were using an algorithm that suggested the swap size as 2 GB + size of RAM, but this resulted in huge swaps on machines with a lot of RAM. The new algorithm comes from the discussion with other teams. (ported 84b3444a277b73abeaddf7d4b186a79569eb56d2 from rhel6-branch) (ported 37415063594d00c896ff3c50496582f0c4e9e3d9 from rhel6-branch) --- pyanaconda/installclass.py | 7 ++-- pyanaconda/iutil.py | 41 ----------------------- pyanaconda/kickstart.py | 13 ++++--- pyanaconda/storage/devicelibs/swap.py | 58 +++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 50 deletions(-) diff --git a/pyanaconda/installclass.py b/pyanaconda/installclass.py index c6c50d4..1dd72b4 100644 --- a/pyanaconda/installclass.py +++ b/pyanaconda/installclass.py @@ -32,6 +32,7 @@ import types from constants import * from product import * from storage.partspec import * +from .storage.devicelibs import swap import gettext _ = lambda x: gettext.ldgettext("anaconda", x) @@ -183,9 +184,9 @@ class BaseInstallClass(object): if bootreq: autorequests.extend(bootreq) - (minswap, maxswap) = iutil.swapSuggestion() - autorequests.append(PartSpec(fstype="swap", size=minswap, maxSize=maxswap, - grow=True, lv=True, encrypted=True)) + swap = swap.swapSuggestion() + autorequests.append(PartSpec(fstype="swap", size=swap, grow=False, + lv=True, encrypted=True)) storage.autoPartitionRequests = autorequests diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py index dd691dc..0d1fd9f 100644 --- a/pyanaconda/iutil.py +++ b/pyanaconda/iutil.py @@ -440,34 +440,6 @@ def memInstalled(): return long(mem) -## Suggest the size of the swap partition that will be created. -# @param quiet Should size information be logged? -# @return A tuple of the minimum and maximum swap size, in megabytes. -def swapSuggestion(quiet=0): - mem = memInstalled()/1024 - mem = ((mem/16)+1)*16 - if not quiet: - log.info("Detected %sM of memory", mem) - - if mem <= 256: - minswap = 256 - maxswap = 512 - else: - if mem > 2048: - minswap = 1024 - maxswap = 2048 + mem - else: - minswap = mem - maxswap = 2*mem - - if isS390(): - minswap = 1 - - if not quiet: - log.info("Swap attempt of %sM to %sM", minswap, maxswap) - - return (minswap, maxswap) - ## Create a directory path. Don't fail if the directory already exists. # @param dir The directory path to create. def mkdirChain(dir): @@ -482,19 +454,6 @@ def mkdirChain(dir): log.error("could not create directory %s: %s" % (dir, e.strerror)) -## Get the total amount of swap memory. -# @return The total amount of swap memory in kilobytes, or 0 if unknown. -def swapAmount(): - f = open("/proc/meminfo", "r") - lines = f.readlines() - f.close() - - for l in lines: - if l.startswith("SwapTotal:"): - fields = string.split(l) - return int(fields[1]) - return 0 - ## Copy a device node. # Copies a device node by looking at the device type, major and minor device # numbers, and doing a mknod on the new device name. diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 8d313f0..eba3644 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -25,6 +25,7 @@ from storage.devicelibs.mpath import MultipathConfigWriter, MultipathTopology from storage.formats import getFormat from storage.partitioning import clearPartitions from storage.partitioning import shouldClear +from .storage.devicelibs import swap import storage.iscsi import storage.fcoe import storage.zfcp @@ -538,9 +539,9 @@ class LogVolData(commands.logvol.F17_LogVolData): if self.mountpoint == "swap": type = "swap" self.mountpoint = "" - if self.recommended: - (self.size, self.maxSizeMB) = iutil.swapSuggestion() - self.grow = True + if self.recommended or self.hibernation: + self.size = swap.swapSuggestion(hibernation=self.hibernation) + self.grow = False else: if self.fstype != "": type = self.fstype @@ -844,9 +845,9 @@ class PartitionData(commands.partition.F17_PartData): if self.mountpoint == "swap": type = "swap" self.mountpoint = "" - if self.recommended: - (self.size, self.maxSizeMB) = iutil.swapSuggestion() - self.grow = True + if self.recommended or self.hibernation: + self.size = swap.swapSuggestion(hibernation=self.hibernation) + self.grow = False # if people want to specify no mountpoint for some reason, let them # this is really needed for pSeries boot partitions :( elif self.mountpoint == "None": diff --git a/pyanaconda/storage/devicelibs/swap.py b/pyanaconda/storage/devicelibs/swap.py index 02c8737..512b648 100644 --- a/pyanaconda/storage/devicelibs/swap.py +++ b/pyanaconda/storage/devicelibs/swap.py @@ -31,6 +31,8 @@ from . import dm import gettext _ = lambda x: gettext.ldgettext("anaconda", x) +import logging +log = logging.getLogger("anaconda") def mkswap(device, label='', progress=None): # We use -f to force since mkswap tends to refuse creation on lvs with @@ -123,3 +125,59 @@ def swapstatus(device): return status +def swapSuggestion(quiet=False, hibernation=False): + """ + Suggest the size of the swap partition that will be created. + + @param quiet: log size information + @param hibernation: calculate swap size big enough for hibernation + @return: calculated swap size + + """ + + mem = iutil.memInstalled()/1024 + mem = ((mem/16)+1)*16 + if not quiet: + log.info("Detected %sM of memory", mem) + + #chart suggested in the discussion with other teams + if mem < 2048: + swap = 2 * mem + + elif 2048 <= mem < 8192: + swap = mem + + elif 8192 <= mem < 65536: + swap = mem / 2 + + else: + swap = 4096 + + if hibernation: + if mem <= 65536: + swap = mem + swap + else: + log.info("Ignoring --hibernation option on systems with 64 GB of RAM or more") + + if not quiet: + log.info("Swap attempt of %sM", swap) + + return swap + +def swapAmount(): + """ + Get the total amount of swap memory. + + @return: The total amount of swap memory in kilobytes, or 0 if unknown. + + """ + + f = open("/proc/meminfo", "r") + lines = f.readlines() + f.close() + + for l in lines: + if l.startswith("SwapTotal:"): + fields = l.split() + return int(fields[1]) + return 0 -- 1.7.4.4 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list