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)
This commit is contained in:
parent
7d940454fb
commit
92736c3486
@ -139,31 +139,6 @@ EraseDiskPage::doAutopartition( Device* dev )
|
|||||||
#define MiB * static_cast< qint64 >( 1024 ) * 1024
|
#define MiB * static_cast< qint64 >( 1024 ) * 1024
|
||||||
#define GiB * static_cast< qint64 >( 1024 ) * 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
|
// Partition sizes are expressed in MiB, should be multiples of
|
||||||
// the logical sector size (usually 512B).
|
// the logical sector size (usually 512B).
|
||||||
int uefisys_part_size = 0;
|
int uefisys_part_size = 0;
|
||||||
@ -208,12 +183,14 @@ EraseDiskPage::doAutopartition( Device* dev )
|
|||||||
|
|
||||||
bool shouldCreateSwap = false;
|
bool shouldCreateSwap = false;
|
||||||
qint64 availableSpaceB = ( dev->totalSectors() - firstFreeSector ) * dev->logicalSectorSize();
|
qint64 availableSpaceB = ( dev->totalSectors() - firstFreeSector ) * dev->logicalSectorSize();
|
||||||
|
qint64 suggestedSwapSizeB = swapSuggestion( availableSpaceB );
|
||||||
qint64 requiredSpaceB =
|
qint64 requiredSpaceB =
|
||||||
( Calamares::JobQueue::instance()->
|
( Calamares::JobQueue::instance()->
|
||||||
globalStorage()->
|
globalStorage()->
|
||||||
value( "requiredStorageGB" ).toDouble() + 0.1 + 2.0 ) GiB +
|
value( "requiredStorageGB" ).toDouble() + 0.1 + 2.0 ) GiB +
|
||||||
suggestedSwapSizeB;
|
suggestedSwapSizeB;
|
||||||
|
|
||||||
|
// If there is enough room for ESP + root + swap, create swap, otherwise don't.
|
||||||
shouldCreateSwap = availableSpaceB > requiredSpaceB;
|
shouldCreateSwap = availableSpaceB > requiredSpaceB;
|
||||||
|
|
||||||
qint64 lastSectorForRoot = dev->totalSectors() - 1; //last sector of the device
|
qint64 lastSectorForRoot = dev->totalSectors() - 1; //last sector of the device
|
||||||
@ -293,3 +270,46 @@ EraseDiskPage::updatePreviews()
|
|||||||
layout->addRow( tr( "After:" ), preview );
|
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;
|
||||||
|
}
|
||||||
|
@ -43,6 +43,7 @@ private:
|
|||||||
void setNextEnabled( bool enabled );
|
void setNextEnabled( bool enabled );
|
||||||
void doAutopartition( Device* dev );
|
void doAutopartition( Device* dev );
|
||||||
void updatePreviews();
|
void updatePreviews();
|
||||||
|
qint64 swapSuggestion( const qint64 availableSpaceB ) const;
|
||||||
|
|
||||||
QListView* m_drivesView;
|
QListView* m_drivesView;
|
||||||
PartitionCoreModule* m_core;
|
PartitionCoreModule* m_core;
|
||||||
|
Loading…
Reference in New Issue
Block a user