[PATCH] Take into account disk space when calculating swap suggestion (#1016673)

Vratislav Podzimek vpodzime at redhat.com
Tue Oct 8 14:16:40 UTC 2013


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 at 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 :(
-- 
1.7.11.7



More information about the anaconda-patches mailing list