Memory: clean up interface used to get memory (RAM) size

main
Adriaan de Groot 7 years ago
parent 0c129f2460
commit 9693d7a5bd

@ -231,14 +231,7 @@ System::targetEnvOutput( const QString& command,
}
qint64
System::getPhysicalMemoryB()
{
return 0;
}
qint64
QPair<quint64, float>
System::getTotalMemoryB()
{
#ifdef Q_OS_LINUX
@ -246,20 +239,21 @@ System::getTotalMemoryB()
int r = sysinfo( &i );
if (r)
return 0;
return qMakePair(0, 0.0);
return qint64( i.mem_unit ) * i.totalram;
return qMakePair(quint64( i.mem_unit ) * quint64( i.totalram ), 1.1);
#elif defined( Q_OS_FREEBSD )
unsigned long memsize;
size_t s = sizeof(memsize);
int r = sysctlbyname("vm.kmem_size", &memsize, &s, NULL, 0);
if (r)
return 0;
return qMakePair(0, 0.0);
return memsize;
return qMakePair(memsize, 1.01);
#else
return qMakePair(0, 0.0); // Unsupported
#endif
return 0; // Unsupported
}

@ -100,9 +100,19 @@ public:
/**
* @brief getTotalMemoryB returns the total main memory, in bytes.
*
* Since it is difficult to get the RAM memory size exactly -- either
* by reading information from the DIMMs, which may fail on virtual hosts
* or from asking the kernel, which doesn't report some memory areas --
* this returns a pair of guessed-size (in bytes) and a "guesstimate factor"
* which says how good the guess is. Generally, assume the *real* memory
* available is size * guesstimate.
*
* If nothing can be found, returns a 0 size and 0 guesstimate.
*
* @return size, guesstimate-factor
*/
DLLEXPORT qint64 getTotalMemoryB(); //Always underguessed, but always works on Linux
DLLEXPORT qint64 getPhysicalMemoryB(); //Better guess, doesn't work in VirualBox
DLLEXPORT QPair<quint64, float> getTotalMemoryB();
private:
static System* s_instance;

@ -45,19 +45,21 @@ using CalamaresUtils::operator""_MiB;
qint64
swapSuggestion( const qint64 availableSpaceB )
{
// 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
/* 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).
*/
qint64 suggestedSwapSizeB = 0;
qint64 availableRamB = CalamaresUtils::System::instance()->getPhysicalMemoryB();
qreal overestimationFactor = 1.01;
if ( !availableRamB )
{
availableRamB = CalamaresUtils::System::instance()->getTotalMemoryB();
overestimationFactor = 1.10;
}
auto memory = CalamaresUtils::System::instance()->getTotalMemoryB();
qint64 availableRamB = memory.first;
qreal overestimationFactor = memory.second;
bool ensureSuspendToDisk =
Calamares::JobQueue::instance()->globalStorage()->
@ -80,8 +82,8 @@ swapSuggestion( const qint64 availableSpaceB )
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 if ( availableRamB >= 8_GiB && availableRamB < 16_GiB )
suggestedSwapSizeB = 8_GiB;
else
suggestedSwapSizeB = 4_GiB;

@ -310,9 +310,9 @@ RequirementsChecker::checkEnoughStorage( qint64 requiredSpace )
bool
RequirementsChecker::checkEnoughRam( qint64 requiredRam )
{
qint64 availableRam = CalamaresUtils::System::instance()->getPhysicalMemoryB();
if ( !availableRam )
availableRam = CalamaresUtils::System::instance()->getTotalMemoryB();
// Ignore the guesstimate-factor; we get an under-estimate
// which is probably the usable RAM for programs.
quint64 availableRam = CalamaresUtils::System::instance()->getTotalMemoryB().first;
return availableRam >= requiredRam * 0.95; // because MemTotal is variable
}

Loading…
Cancel
Save