[blivet][PATCH 1/3] Move the swapSuggestion function outside of blivet

Vratislav Podzimek vpodzime at redhat.com
Fri Jan 23 14:18:16 UTC 2015


It doesn't belong to blivet and it's only used by Anaconda.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 blivet/devicelibs/swap.py | 67 -----------------------------------------------
 1 file changed, 67 deletions(-)

diff --git a/blivet/devicelibs/swap.py b/blivet/devicelibs/swap.py
index 63e0dec9..5314810 100644
--- a/blivet/devicelibs/swap.py
+++ b/blivet/devicelibs/swap.py
@@ -22,19 +22,14 @@
 
 import resource
 import os
-from decimal import Decimal
 
 from ..errors import DMError, OldSwapError, SuspendError, SwapError, UnknownSwapError
 from .. import util
 from . import dm
-from ..size import Size
 
 import logging
 log = logging.getLogger("blivet")
 
-# maximum ratio of swap size to disk size (10 %)
-MAX_SWAP_DISK_RATIO = Decimal('0.1')
-
 def mkswap(device, label=None):
     # We use -f to force since mkswap tends to refuse creation on lvs with
     # a message about erasing bootbits sectors on whole disks. Bah.
@@ -117,65 +112,3 @@ def swapstatus(device):
             break
 
     return status
-
-def swapSuggestion(quiet=False, hibernation=False, disk_space=None):
-    """
-    Suggest the size of the swap partition that will be created.
-
-    :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: :class:`~.size.Size`
-    :return: calculated swap size
-
-    """
-
-    mem = util.total_memory()
-    mem = ((mem / 16) + 1) * 16
-    if not quiet:
-        log.info("Detected %s of memory", mem)
-
-    sixtyfour_GiB = Size("64 GiB")
-
-    # the succeeding if-statement implements the following formula for
-    # suggested swap size.
-    #
-    # swap(mem) = 2 * mem, if mem < 2 GiB
-    #           = mem,     if 2 GiB <= mem < 8 GiB
-    #           = mem / 2, if 8 GIB <= mem < 64 GiB
-    #           = 4 GiB,   if mem >= 64 GiB
-    if mem < Size("2 GiB"):
-        swap = 2 * mem
-
-    elif mem < Size("8 GiB"):
-        swap = mem
-
-    elif mem < sixtyfour_GiB:
-        swap = mem / 2
-
-    else:
-        swap = Size("4 GiB")
-
-    if hibernation:
-        if mem <= sixtyfour_GiB:
-            swap = mem + swap
-        else:
-            log.info("Ignoring --hibernation option on systems with %s of RAM or more", sixtyfour_GiB)
-
-    if disk_space is not None and not hibernation:
-        max_swap = disk_space * MAX_SWAP_DISK_RATIO
-        if swap > max_swap:
-            log.info("Suggested swap size (%(swap)s) exceeds %(percent)d %% of "
-                     "disk space, using %(percent)d %% of disk space (%(size)s) "
-                     "instead.", {"percent": MAX_SWAP_DISK_RATIO*100,
-                                  "swap": swap,
-                                  "size": max_swap})
-            swap = max_swap
-
-    if not quiet:
-        log.info("Swap attempt of %s", swap)
-
-    return swap
-
-- 
2.1.0



More information about the anaconda-patches mailing list