Replace memory-size detection.
- drop use of dmidecode to determine exact physical memory size - use sysinfo() to find memory size (assumes linux 2.3.48 or later)
This commit is contained in:
parent
57e5e9582f
commit
92fa40b922
@ -26,6 +26,15 @@
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_FREEBSD
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
namespace CalamaresUtils
|
||||
{
|
||||
|
||||
@ -224,47 +233,32 @@ System::targetEnvOutput( const QString& command,
|
||||
qint64
|
||||
System::getPhysicalMemoryB()
|
||||
{
|
||||
QProcess p;
|
||||
p.start( "dmidecode", { "-t", "17" } );
|
||||
p.waitForFinished();
|
||||
QStringList lines = QString::fromLocal8Bit( p.readAllStandardOutput() ).split( '\n' );
|
||||
lines = lines.filter( QRegularExpression( "^\\W*Size:\\W\\d*\\WMB" ) );
|
||||
if ( !lines.isEmpty() )
|
||||
return 0;
|
||||
|
||||
qint64 availableRamMb = 0;
|
||||
foreach( const QString& line, lines )
|
||||
{
|
||||
bool ok = false;
|
||||
availableRamMb += line.simplified()
|
||||
.split( ' ' )
|
||||
.value( 1 )
|
||||
.toInt( &ok );
|
||||
if ( !ok )
|
||||
return 0;
|
||||
}
|
||||
qint64 availableRam = availableRamMb * 1024 * 1024;
|
||||
return availableRam;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
qint64
|
||||
System::getTotalMemoryB()
|
||||
{
|
||||
// A line in meminfo looks like this, with {print $2} we grab the second column.
|
||||
// MemTotal: 8133432 kB
|
||||
#ifdef Q_OS_LINUX
|
||||
struct sysinfo i;
|
||||
int r = sysinfo( &i );
|
||||
|
||||
QProcess p;
|
||||
p.start( "awk", { "/MemTotal/ {print $2}", "/proc/meminfo" } );
|
||||
p.waitForFinished();
|
||||
QString memoryLine = p.readAllStandardOutput().simplified();
|
||||
|
||||
bool ok = false;
|
||||
qint64 availableRam = memoryLine.toLongLong( &ok ) * 1024;
|
||||
if ( !ok )
|
||||
if (r)
|
||||
return 0;
|
||||
|
||||
return availableRam;
|
||||
return qint64( i.mem_unit ) * i.totalram;
|
||||
#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 memsize;
|
||||
#endif
|
||||
return 0; // Unsupported
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user