summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Terjan <pterjan@gmail.com>2023-05-05 19:58:15 +0000
committerPascal Terjan <pterjan@gmail.com>2023-05-05 20:11:21 +0000
commitbc1b6ee565efced5ce23ad68a1e302f61bcc8b09 (patch)
tree49b028c1dde18fe9bbd6473fb9e58923b15aa224
parent439e249b3e8696c8eac136a846d5d5bdffc071a1 (diff)
downloaddrakx-bc1b6ee565efced5ce23ad68a1e302f61bcc8b09.tar
drakx-bc1b6ee565efced5ce23ad68a1e302f61bcc8b09.tar.gz
drakx-bc1b6ee565efced5ce23ad68a1e302f61bcc8b09.tar.bz2
drakx-bc1b6ee565efced5ce23ad68a1e302f61bcc8b09.tar.xz
drakx-bc1b6ee565efced5ce23ad68a1e302f61bcc8b09.zip
Fix total_memory()
It was using the size of /proc/kcore which is 128T on x86_64 regardless of available memory, and does not exist on aarch64. Instead use sysinfo().
-rw-r--r--mdk-stage1/utils.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/mdk-stage1/utils.c b/mdk-stage1/utils.c
index d861877e4..6ad3a8f6f 100644
--- a/mdk-stage1/utils.c
+++ b/mdk-stage1/utils.c
@@ -21,6 +21,7 @@
#include <unistd.h>
#include <ctype.h>
#include <dirent.h>
+#include <sys/sysinfo.h>
#include <sys/utsname.h>
#include "utils.h"
@@ -83,9 +84,12 @@ int line_counts(const char * buf) {
int total_memory(void)
{
int value;
-
- /* drakx powered: use /proc/kcore and rounds every 4 Mbytes */
- value = 4 * ((int)((float)file_size("/proc/kcore") / 1024 / 1024 / 4 + 0.5));
+ struct sysinfo sys_info;
+ if (sysinfo(&sys_info) < 0) {
+ log_perror("sysinfo");
+ return 0;
+ }
+ value = sys_info.totalram * sys_info.mem_unit / 1024 / 1024;
log_message("Total Memory: %d Mbytes", value);
return value;