Skip to content

Commit

Permalink
debug: spec.sh: Express memory in MB instead of GB
Browse files Browse the repository at this point in the history
The spec.sh script gets the amount of available memory of the device from
/proc/meminfo, which contains the total amount of installed memory minus
the non-usable memory (reserved areas, etc) in KB. Then, awk is used to
divide the value by 1024^2 and get the final value in GB. However, the
integer division will round down the final value, so if the final value
should be, for instance, 3.7GB, it will be converted to 3GB, missing around
700MB of usable RAM memory.

This commit changes the spec.sh to provide the total amount of available
memory in MB instead of GB in order to increase the granularity and avoid
missing substantial amounts of usable memory.

Signed-off-by: Renê de Souza Pinto <[email protected]>
  • Loading branch information
rene authored and eriknordmark committed Oct 2, 2023
1 parent c21da2d commit 7ef8cd3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/debug/spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ get_modem_atport() {

if [ -e /dev/xen ]; then
CPUS=$(eve exec xen-tools xl info | grep nr_cpus | cut -f2 -d:)
MEM=$(( $(eve exec xen-tools xl info | grep total_memory | cut -f2 -d:) / 1024 ))
MEM=$(( $(eve exec xen-tools xl info | grep total_memory | cut -f2 -d:) ))
else
CPUS=$(grep -c '^processor.*' < /proc/cpuinfo)
MEM=$(awk '/MemTotal:/ { print int($2 / 1048576); }' < /proc/meminfo)
MEM=$(awk '/MemTotal:/ { print int($2 / 1024); }' < /proc/meminfo)
fi

DISK=$(lsblk -b | grep disk | awk '{ total += $4; } END { print int(total/(1024*1024*1024)); }')
Expand All @@ -233,7 +233,7 @@ cat <<__EOT__
"productURL": "$(cat /persist/status/hardwaremodel || cat /config/hardwaremodel)",
"productStatus": "production",
"attr": {
"memory": "${MEM}G",
"memory": "${MEM}M",
"storage": "${DISK}G",
"Cpus": "${CPUS}",
"watchdog": "${WDT}",
Expand Down

0 comments on commit 7ef8cd3

Please sign in to comment.