Memory: clean up interface used to get memory (RAM) size
This commit is contained in:
parent
a2b70ee1d4
commit
2fa9eb603b
@ -230,14 +230,7 @@ System::targetEnvOutput( const QString& command,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
qint64
|
QPair<quint64, float>
|
||||||
System::getPhysicalMemoryB()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
qint64
|
|
||||||
System::getTotalMemoryB()
|
System::getTotalMemoryB()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
@ -245,20 +238,21 @@ System::getTotalMemoryB()
|
|||||||
int r = sysinfo( &i );
|
int r = sysinfo( &i );
|
||||||
|
|
||||||
if (r)
|
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 )
|
#elif defined( Q_OS_FREEBSD )
|
||||||
unsigned long memsize;
|
unsigned long memsize;
|
||||||
size_t s = sizeof(memsize);
|
size_t s = sizeof(memsize);
|
||||||
|
|
||||||
int r = sysctlbyname("vm.kmem_size", &memsize, &s, NULL, 0);
|
int r = sysctlbyname("vm.kmem_size", &memsize, &s, NULL, 0);
|
||||||
if (r)
|
if (r)
|
||||||
return 0;
|
return qMakePair(0, 0.0);
|
||||||
|
|
||||||
return memsize;
|
return qMakePair(memsize, 1.01);
|
||||||
|
#else
|
||||||
|
return qMakePair(0, 0.0); // Unsupported
|
||||||
#endif
|
#endif
|
||||||
return 0; // Unsupported
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,9 +100,19 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief getTotalMemoryB returns the total main memory, in bytes.
|
* @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 QPair<quint64, float> getTotalMemoryB();
|
||||||
DLLEXPORT qint64 getPhysicalMemoryB(); //Better guess, doesn't work in VirualBox
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static System* s_instance;
|
static System* s_instance;
|
||||||
|
@ -59,19 +59,21 @@ constexpr qint64 toGiB( unsigned long long m )
|
|||||||
qint64
|
qint64
|
||||||
swapSuggestion( const qint64 availableSpaceB )
|
swapSuggestion( const qint64 availableSpaceB )
|
||||||
{
|
{
|
||||||
// swap(mem) = max(2, 2 * mem), if mem < 2 GiB
|
/* If suspend-to-disk is demanded, then we always need enough
|
||||||
// = mem, if 2 GiB <= mem < 8 GiB
|
* swap to write the whole memory to disk -- between 2GB and 8GB
|
||||||
// = mem / 2, if 8 GIB <= mem < 64 GiB
|
* RAM give proportionally more swap, and from 8GB RAM keep
|
||||||
// = 4 GiB, if mem >= 64 GiB
|
* 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 suggestedSwapSizeB = 0;
|
||||||
qint64 availableRamB = CalamaresUtils::System::instance()->getPhysicalMemoryB();
|
auto memory = CalamaresUtils::System::instance()->getTotalMemoryB();
|
||||||
qreal overestimationFactor = 1.01;
|
qint64 availableRamB = memory.first;
|
||||||
if ( !availableRamB )
|
qreal overestimationFactor = memory.second;
|
||||||
{
|
|
||||||
availableRamB = CalamaresUtils::System::instance()->getTotalMemoryB();
|
|
||||||
overestimationFactor = 1.10;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ensureSuspendToDisk =
|
bool ensureSuspendToDisk =
|
||||||
Calamares::JobQueue::instance()->globalStorage()->
|
Calamares::JobQueue::instance()->globalStorage()->
|
||||||
@ -94,8 +96,8 @@ swapSuggestion( const qint64 availableSpaceB )
|
|||||||
suggestedSwapSizeB = qMax( 2_GiB, availableRamB * 2 );
|
suggestedSwapSizeB = qMax( 2_GiB, availableRamB * 2 );
|
||||||
else if ( availableRamB >= 2_GiB && availableRamB < 8_GiB )
|
else if ( availableRamB >= 2_GiB && availableRamB < 8_GiB )
|
||||||
suggestedSwapSizeB = availableRamB;
|
suggestedSwapSizeB = availableRamB;
|
||||||
else if ( availableRamB >= 8_GiB && availableRamB < 64_GiB )
|
else if ( availableRamB >= 8_GiB && availableRamB < 16_GiB )
|
||||||
suggestedSwapSizeB = availableRamB / 2;
|
suggestedSwapSizeB = 8_GiB;
|
||||||
else
|
else
|
||||||
suggestedSwapSizeB = 4_GiB;
|
suggestedSwapSizeB = 4_GiB;
|
||||||
|
|
||||||
|
@ -307,9 +307,9 @@ RequirementsChecker::checkEnoughStorage( qint64 requiredSpace )
|
|||||||
bool
|
bool
|
||||||
RequirementsChecker::checkEnoughRam( qint64 requiredRam )
|
RequirementsChecker::checkEnoughRam( qint64 requiredRam )
|
||||||
{
|
{
|
||||||
qint64 availableRam = CalamaresUtils::System::instance()->getPhysicalMemoryB();
|
// Ignore the guesstimate-factor; we get an under-estimate
|
||||||
if ( !availableRam )
|
// which is probably the usable RAM for programs.
|
||||||
availableRam = CalamaresUtils::System::instance()->getTotalMemoryB();
|
quint64 availableRam = CalamaresUtils::System::instance()->getTotalMemoryB().first;
|
||||||
return availableRam >= requiredRam * 0.95; // because MemTotal is variable
|
return availableRam >= requiredRam * 0.95; // because MemTotal is variable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user