From 92736c34862b6fe35a26dc276a2fef9a13e3f0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramon=20Buld=C3=B3?= Date: Thu, 25 Jun 2015 14:10:56 +0200 Subject: [PATCH] Change how swap is calculated in automatic installation. It uses same values as Thus/Anaconda. Takes into account available disk space (don't use more than 10% of it) --- src/modules/partition/gui/EraseDiskPage.cpp | 70 +++++++++++++-------- src/modules/partition/gui/EraseDiskPage.h | 1 + 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/modules/partition/gui/EraseDiskPage.cpp b/src/modules/partition/gui/EraseDiskPage.cpp index 09def0563..47992b71f 100644 --- a/src/modules/partition/gui/EraseDiskPage.cpp +++ b/src/modules/partition/gui/EraseDiskPage.cpp @@ -139,31 +139,6 @@ EraseDiskPage::doAutopartition( Device* dev ) #define MiB * static_cast< qint64 >( 1024 ) * 1024 #define GiB * static_cast< qint64 >( 1024 ) * 1024 * 1024 - // If there is enough room for ESP + root + swap, create swap, otherwise don't. - // Physical memory Swap - // <4 GiB 2 * memory (min. 2 GiB) + overallocation - // 4-8 GiB 8 GiB + overallocation - // >8 GiB = memory + overallocation - qint64 suggestedSwapSizeB = 0; - qint64 availableRamB = CalamaresUtils::getPhysicalMemoryB(); - qreal overestimationFactor = 1.01; - if ( !availableRamB ) - { - availableRamB = CalamaresUtils::getTotalMemoryB(); - overestimationFactor = 1.10; - } - - 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; - - cDebug() << "Suggested swap size:" << suggestedSwapSizeB / 1024. / 1024. /1024. << "GiB"; - // Partition sizes are expressed in MiB, should be multiples of // the logical sector size (usually 512B). int uefisys_part_size = 0; @@ -208,12 +183,14 @@ EraseDiskPage::doAutopartition( Device* dev ) bool shouldCreateSwap = false; qint64 availableSpaceB = ( dev->totalSectors() - firstFreeSector ) * dev->logicalSectorSize(); + qint64 suggestedSwapSizeB = swapSuggestion( availableSpaceB ); qint64 requiredSpaceB = ( Calamares::JobQueue::instance()-> globalStorage()-> value( "requiredStorageGB" ).toDouble() + 0.1 + 2.0 ) GiB + suggestedSwapSizeB; + // If there is enough room for ESP + root + swap, create swap, otherwise don't. shouldCreateSwap = availableSpaceB > requiredSpaceB; qint64 lastSectorForRoot = dev->totalSectors() - 1; //last sector of the device @@ -293,3 +270,46 @@ EraseDiskPage::updatePreviews() layout->addRow( tr( "After:" ), preview ); } } + + +qint64 +EraseDiskPage::swapSuggestion( const qint64 availableSpaceB ) const { + +#define MiB * static_cast< qint64 >( 1024 ) * 1024 +#define GiB * static_cast< qint64 >( 1024 ) * 1024 * 1024 + + // swap(mem) = max(2, 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 + + qint64 suggestedSwapSizeB = 0; + qint64 availableRamB = CalamaresUtils::getPhysicalMemoryB(); + qreal overestimationFactor = 1.01; + if ( !availableRamB ) + { + availableRamB = CalamaresUtils::getTotalMemoryB(); + 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; + + // don't use more 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"; + + return suggestedSwapSizeB; +} diff --git a/src/modules/partition/gui/EraseDiskPage.h b/src/modules/partition/gui/EraseDiskPage.h index 45587629c..227d2e113 100644 --- a/src/modules/partition/gui/EraseDiskPage.h +++ b/src/modules/partition/gui/EraseDiskPage.h @@ -43,6 +43,7 @@ private: void setNextEnabled( bool enabled ); void doAutopartition( Device* dev ); void updatePreviews(); + qint64 swapSuggestion( const qint64 availableSpaceB ) const; QListView* m_drivesView; PartitionCoreModule* m_core;