These patches are together port of the commit 98a347672c4a7c6972fa7e4af3d22d041588ca3d from rhel6-branch. We should do the same on master/rhel7-branch as well.
Vratislav Podzimek (1): Take into account disk space when calculating swap suggestion (#1016673)
pyanaconda/installclass.py | 5 ++++- pyanaconda/kickstart.py | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-)
On e.g. virtual machines with smalls disks and high amount of memory it doesn't make sense to create large swap space leaving only a little for the system and user data.
(port of 98a347672c4a7c6972fa7e4af3d22d041588ca3d from rhel6-branch)
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com --- pyanaconda/installclass.py | 5 ++++- pyanaconda/kickstart.py | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/pyanaconda/installclass.py b/pyanaconda/installclass.py index d7f0d74..e2c7f32 100644 --- a/pyanaconda/installclass.py +++ b/pyanaconda/installclass.py @@ -33,6 +33,7 @@ import logging log = logging.getLogger("anaconda")
from pyanaconda.flags import flags +from pyanaconda.kickstart import getAvailableDiskSpace
class BaseInstallClass(object): # default to not being hidden @@ -88,7 +89,9 @@ class BaseInstallClass(object): if bootreqs: autorequests.extend(bootreqs)
- swp = swap.swapSuggestion() + + disk_space = getAvailableDiskSpace(storage) + swp = swap.swapSuggestion(disk_space=disk_space) autorequests.append(PartSpec(fstype="swap", size=swp, grow=False, lv=True, encrypted=True))
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 34929b9..a6ac057 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -201,6 +201,25 @@ def removeExistingFormat(device, storage):
storage.devicetree.registerAction(ActionDestroyFormat(device))
+def getAvailableDiskSpace(storage): + """ + Get overall disk space available on disks we may use (not free space on the + disks, but overall space on the disks). + + :param storage: blivet.Blivet instance + :return: overall disk space available in MB + :rtype: int + + """ + + disk_space = 0 + for disk in storage.disks: + if not storage.config.clearPartDisks or \ + disk.name in storage.config.clearPartDisks: + disk_space += disk.size + + return disk_space + ### ### SUBCLASSES OF PYKICKSTART COMMAND HANDLERS ### @@ -650,7 +669,8 @@ class LogVolData(commands.logvol.F20_LogVolData): ty = "swap" self.mountpoint = "" if self.recommended or self.hibernation: - self.size = swap.swapSuggestion(hibernation=self.hibernation) + disk_space = getAvailableDiskSpace(storage) + self.size = swap.swapSuggestion(hibernation=self.hibernation, disk_space=disk_space) self.grow = False else: if self.fstype != "": @@ -871,7 +891,8 @@ class PartitionData(commands.partition.F18_PartData): ty = "swap" self.mountpoint = "" if self.recommended or self.hibernation: - self.size = swap.swapSuggestion(hibernation=self.hibernation) + disk_space = getAvailableDiskSpace(storage) + self.size = swap.swapSuggestion(hibernation=self.hibernation, disk_space=disk_space) self.grow = False # if people want to specify no mountpoint for some reason, let them # this is really needed for pSeries boot partitions :(
On e.g. virtual machines with smalls disks and high amount of memory it doesn't make sense to create large swap space leaving only a little for the system and user data.
Related: rhbz#1016673
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com --- blivet/devicelibs/swap.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/blivet/devicelibs/swap.py b/blivet/devicelibs/swap.py index fc3f940..0fb2c69 100644 --- a/blivet/devicelibs/swap.py +++ b/blivet/devicelibs/swap.py @@ -33,6 +33,9 @@ _ = lambda x: gettext.ldgettext("blivet", x) import logging log = logging.getLogger("blivet")
+# maximum ratio of swap size to disk size (10 %) +MAX_SWAP_DISK_RATIO = 0.1 + def mkswap(device, label=''): # We use -f to force since mkswap tends to refuse creation on lvs with # a message about erasing bootbits sectors on whole disks. Bah. @@ -116,13 +119,17 @@ def swapstatus(device):
return status
-def swapSuggestion(quiet=False, hibernation=False): +def swapSuggestion(quiet=False, hibernation=False, disk_space=None): """ 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 + :param quiet: whether to log size information or not + :type quiet: bool + :param hibernation: calculate swap size big enough for hibernation + :type hibernation: bool + :param disk_space: how much disk space is available + :type disk_space: int + :return: calculated swap size
"""
@@ -150,6 +157,16 @@ def swapSuggestion(quiet=False, hibernation=False): else: log.info("Ignoring --hibernation option on systems with 64 GB of RAM or more")
+ if disk_space is not None: + max_swap = int(disk_space * MAX_SWAP_DISK_RATIO) + if swap > max_swap: + log.info("Suggested swap size (%(swap)d M) exceeds %(percent)d %% of " + "disk space, using %(percent)d %% of disk space (%(size)d M) " + "instead." % {"percent": MAX_SWAP_DISK_RATIO*100, + "swap": swap, + "size": max_swap}) + swap = max_swap + if not quiet: log.info("Swap attempt of %sM", swap)
On Tue, 2013-10-08 at 16:16 +0200, Vratislav Podzimek wrote:
These patches are together port of the commit 98a347672c4a7c6972fa7e4af3d22d041588ca3d from rhel6-branch. We should do the same on master/rhel7-branch as well.
Looks okay to me.
Vratislav Podzimek (1): Take into account disk space when calculating swap suggestion (#1016673)
pyanaconda/installclass.py | 5 ++++- pyanaconda/kickstart.py | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-)
anaconda-patches@lists.fedorahosted.org