[PATCH 1/5] Move swapSuggestion to storage and use a new suggested algorithm for it

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 suggests swap size as the square root of size of RAM in GBs.

(ported 84b3444a277b73abeaddf7d4b186a79569eb56d2 from rhel6-branch)
---
 pyanaconda/installclass.py            |    3 +-
 pyanaconda/iutil.py                   |   41 ----------------------
 pyanaconda/kickstart.py               |    5 ++-
 pyanaconda/storage/devicelibs/swap.py |   60 +++++++++++++++++++++++++++++++++
 4 files changed, 65 insertions(+), 44 deletions(-)

diff --git a/pyanaconda/installclass.py b/pyanaconda/installclass.py
index 8aea1bb..0855319 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)
@@ -184,7 +185,7 @@ class BaseInstallClass(object):
         if bootreq:
             autorequests.extend(bootreq)
 
-        (minswap, maxswap) = iutil.swapSuggestion()
+        (minswap, maxswap) = swap.swapSuggestion()
         autorequests.append(PartSpec(fstype="swap", size=minswap, maxSize=maxswap,
                                      grow=True, lv=True, encrypted=True))
 
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index 5c68e02..c93f68d 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 5afe027..a13be6b 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
@@ -535,7 +536,7 @@ class LogVolData(commands.logvol.F17_LogVolData):
             type = "swap"
             self.mountpoint = ""
             if self.recommended:
-                (self.size, self.maxSizeMB) = iutil.swapSuggestion()
+                (self.size, self.maxSizeMB) = swap.swapSuggestion()
                 self.grow = True
         else:
             if self.fstype != "":
@@ -841,7 +842,7 @@ class PartitionData(commands.partition.F17_PartData):
             type = "swap"
             self.mountpoint = ""
             if self.recommended:
-                (self.size, self.maxSizeMB) = iutil.swapSuggestion()
+                (self.size, self.maxSizeMB) = swap.swapSuggestion()
                 self.grow = True
         # if people want to specify no mountpoint for some reason, let them
         # this is really needed for pSeries boot partitions :(
diff --git a/pyanaconda/storage/devicelibs/swap.py b/pyanaconda/storage/devicelibs/swap.py
index 02c8737..0313d8d 100644
--- a/pyanaconda/storage/devicelibs/swap.py
+++ b/pyanaconda/storage/devicelibs/swap.py
@@ -123,3 +123,63 @@ def swapstatus(device):
 
     return status
 
+def swapSuggestion(quiet=0):
+    """
+    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.
+
+    """
+
+    mem = iutil.memInstalled()/1024
+    mem = ((mem/16)+1)*16
+    if not quiet:
+        log.info("Detected %sM of memory", mem)
+
+    #table suggested in rhbz#744129
+    if mem <= 4096:
+        minswap = 1024
+        maxswap = 2048
+
+    elif 4096 < mem <= 16384:
+        minswap = 2048
+        maxswap = 4096
+
+    elif 16384 < mem <= 65536:
+        minswap = 4096
+        maxswap = 8192
+
+    elif 65536 < mem <= 262144:
+        minswap = 8192
+        maxswap = 16384
+
+    else:
+        minswap = 16384
+        maxswap = 32768
+
+    if isS390():
+        minswap = 1
+
+    if not quiet:
+        log.info("Swap attempt of %sM to %sM", minswap, maxswap)
+
+    return (minswap, maxswap)
+
+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


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux