Update the documentation and implementation of swap calculation.

Make the ramps consistent between suspend-to-disk and not,
and don't do the weird drop from 8GiB swap down to 4GiB for
large-memory systems.
main
Adriaan de Groot 6 years ago
parent 0f38e86223
commit e0cd90cab1

@ -45,17 +45,7 @@ using CalamaresUtils::operator""_MiB;
qint64
swapSuggestion( const qint64 availableSpaceB )
{
/* If suspend-to-disk is demanded, then we always need enough
* swap to write the whole memory to disk -- between 2GB and 8GB
* RAM give proportionally more swap, and from 8GB RAM keep
* swap = RAM.
*
* If suspend-to-disk is not demanded, then ramp up more slowly,
* to 8GB swap at 16GB memory, and then drop to 4GB for "large
* memory" machines, on the assumption that those don't need swap
* because they have tons of memory (or whatever they are doing,
* had better not run into swap).
*/
// See partition.conf for explanation
qint64 suggestedSwapSizeB = 0;
auto memory = CalamaresUtils::System::instance()->getTotalMemoryB();
qint64 availableRamB = memory.first;
@ -65,36 +55,25 @@ swapSuggestion( const qint64 availableSpaceB )
Calamares::JobQueue::instance()->globalStorage()->
value( "ensureSuspendToDisk" ).toBool();
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;
// Ramp up quickly to 8GiB, then follow memory size
if ( availableRamB <= 4_GiB )
suggestedSwapSizeB = availableRamB * 2;
else if ( 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 < 16_GiB )
suggestedSwapSizeB = 8_GiB;
else
suggestedSwapSizeB = 4_GiB;
// .. top out at 8GiB if we don't care about suspend
if ( !ensureSuspendToDisk )
suggestedSwapSizeB = qMin( 8_GiB, suggestedSwapSizeB );
suggestedSwapSizeB *= overestimationFactor;
// don't use more than 10% of available space
qreal maxSwapDiskRatio = 0.10;
qint64 maxSwapSizeB = availableSpaceB * maxSwapDiskRatio;
if ( suggestedSwapSizeB > maxSwapSizeB )
suggestedSwapSizeB = maxSwapSizeB;
}
// Allow for a fudge factor
suggestedSwapSizeB *= overestimationFactor;
// don't use more than 10% of available space
if ( !ensureSuspendToDisk )
suggestedSwapSizeB = qMin( suggestedSwapSizeB, qint64( 0.10 * availableSpaceB ) );
cDebug() << "Suggested swap size:" << suggestedSwapSizeB / 1024. / 1024. / 1024. << "GiB";

@ -6,11 +6,17 @@ efiSystemPartition: "/boot/efi"
# Make sure an autogenerated swap partition is big enough for hibernation in
# automated partitioning modes. Swap can be disabled through *neverCreateSwap*.
#
# When *ensureSuspendToDisk* is true, swap is never smaller than physical
# memory, follows the guideline 2 * memory until swap reaches 8GiB.
# When *ensureSuspendToDisk* is false, swap size scales up with memory
# size until 8GiB, then at roughly half of memory size.
#
# - *neverCreateSwap* is true: no swap is created
# - *neverCreateSwap* is false (the default): swap is created, as follows:
# - *ensureSuspendToDisk* is true (default): Swap is always at least total
# memory size, and up to 4GiB RAM follows the rule-of-thumb 2 * memory;
# from 4GiB to 8 GiB it stays steady at 8GiB, and over 8 GiB memory
# swap is the size of main memory.
# - *ensureSuspendToDisk* is false: Follows the rules above, but Swap is at
# most 8GiB, and no more than 10% of available disk.
# In both cases, a fudge factor (usually 10% extra) is applied so that there
# is some space for administrative overhead (e.g. 8 GiB swap will allocate
# 8.8GiB on disk in the end).
#
# Default is true.
ensureSuspendToDisk: true

Loading…
Cancel
Save