From 27309619d32e92c600a6e7aa69615ac0dc4e1863 Mon Sep 17 00:00:00 2001
From: Teo Mrnjavac <teo@kde.org>
Date: Fri, 26 Jun 2015 15:49:02 +0200
Subject: [PATCH] Optionally do not allow a swap partition smaller than
 physical RAM.

---
 src/modules/partition/gui/EraseDiskPage.cpp | 48 ++++++++++++++-------
 1 file changed, 33 insertions(+), 15 deletions(-)

diff --git a/src/modules/partition/gui/EraseDiskPage.cpp b/src/modules/partition/gui/EraseDiskPage.cpp
index 47992b71fd..9e161e1609 100644
--- a/src/modules/partition/gui/EraseDiskPage.cpp
+++ b/src/modules/partition/gui/EraseDiskPage.cpp
@@ -292,22 +292,40 @@ EraseDiskPage::swapSuggestion( const qint64 availableSpaceB ) const {
         overestimationFactor = 1.10;
     }
 
-    if ( availableRamB < 2 GiB )
-        suggestedSwapSizeB = qMax( 2 GiB, availableRamB * 2 );
-    else if ( availableRamB >= 2 GiB && availableRamB < 8 GiB )
-        suggestedSwapSizeB = availableRamB;
-    else if ( availableRamB >= 8 GiB && availableRamB < 64 GiB )
-        suggestedSwapSizeB = availableRamB / 2;
-    else
-        suggestedSwapSizeB = 4 GiB;
-
-    suggestedSwapSizeB *= overestimationFactor;
+    bool ensureSuspendToDisk =
+        Calamares::JobQueue::instance()->globalStorage()->
+            value( "ensureSuspendToDisk" ).toBool();
 
-    // don't use more 10% of available space
-    qreal maxSwapDiskRatio = 1.10;
-    qint64 maxSwapSizeB = availableSpaceB * maxSwapDiskRatio;
-    if ( suggestedSwapSizeB > maxSwapSizeB )
-        suggestedSwapSizeB = maxSwapSizeB;
+    if ( ensureSuspendToDisk )
+    {
+        if ( availableRamB < 4 GiB )
+            suggestedSwapSizeB = qMax( 2 GiB, availableRamB * 2 );
+        else if ( availableRamB >= 4 GiB && availableRamB < 8 GiB )
+            suggestedSwapSizeB = 8 GiB;
+        else
+            suggestedSwapSizeB = availableRamB;
+
+        suggestedSwapSizeB *= overestimationFactor;
+    }
+    else //if we don't care about suspend to disk
+    {
+        if ( availableRamB < 2 GiB )
+            suggestedSwapSizeB = qMax( 2 GiB, availableRamB * 2 );
+        else if ( availableRamB >= 2 GiB && availableRamB < 8 GiB )
+            suggestedSwapSizeB = availableRamB;
+        else if ( availableRamB >= 8 GiB && availableRamB < 64 GiB )
+            suggestedSwapSizeB = availableRamB / 2;
+        else
+            suggestedSwapSizeB = 4 GiB;
+
+        suggestedSwapSizeB *= overestimationFactor;
+
+        // don't use more than 10% of available space
+        qreal maxSwapDiskRatio = 1.10;
+        qint64 maxSwapSizeB = availableSpaceB * maxSwapDiskRatio;
+        if ( suggestedSwapSizeB > maxSwapSizeB )
+            suggestedSwapSizeB = maxSwapSizeB;
+    }
 
     cDebug() << "Suggested swap size:" << suggestedSwapSizeB / 1024. / 1024. /1024. << "GiB";
 
-- 
GitLab