You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
Linux 3.14 in 2014 added a proper way to determine how much memory is actually in use by adding MemAvailable to /proc/meminfo since it is very complicated to determine what is 'correct' from userspace.
Neofetch also used to support reporting memory using this method on modern kernels, until a patch reverted it on Mar 25, 2016.
Neofetch reverted this support for unknown reasons to 'work on older linux kernel versions' instead of just adding a case statement to support those ancient kernels. By now the support for ancient kernels could probably be dropped altogether although there a few users on CentOS/RHEL 7 (3.10.0) or SLES 11 (3.0.76) that might complain. Note that CentOS 6 (2.6.32) will be EOL at the end of this month (Nov 30, 2020). I don't know of any other supported distribution revisions that still support such an ancient kernel version.
The amount of memory that is not properly reported, by using the old calculations, can end up being many GB in size. I saw the difference between Neofetch and (MemTotal-MemAvailable) vary by over 5GB on my system last week. At the moment on my system it only differs by ~ 1GB, which is still quite a lot. Not only does Neofetch not report the correct amount of memory used on newer kernels but it also does not match conky or screenfetch output so it is especially confusing to new users that don't know why neofetch reports a different amount of used memory. I've seen a number of users ask why the numbers differ between different apps reporting memory used.
commit 5939c27b60deea10e88482489ab1ea90ef2a06f2
Author: Dylan <dyl@tfwno.gf>
Date: Fri Mar 25 21:51:21 2016 +1100
Rewrite memory function to work on older linux kernel versions
diff --git a/neofetch b/neofetch
index 8bac24d..8711c55 100755
--- a/neofetch
+++ b/neofetch
@@ -1112,17 +1112,9 @@ getgpu () {
getmemory () {
case "$os" in
"Linux")
- # Read first 3 lines
- mem=$(awk -F ':' '/MemTotal|MemAvailable/ {printf $2}' /proc/meminfo )
-
- # Do some substitution on each line
- memtotal=${mem/kB*/kB}
- memavail=${mem/${memtotal}}
- memtotal=${memtotal/kB*}
- memavail=${memavail/kB*}
-
- memused=$((memtotal - memavail))
- memory="$((memused / 1024))MB / $((memtotal / 1024))MB"
+ mem=($(awk -F ':| kB' '/MemTotal|MemFree|Buffers|Cached/ {printf $2}' /proc/meminfo ))
+ memused=$((${mem[0]} - ${mem[1]} - ${mem[2]} - ${mem[3]}))
+ memory="$((memused / 1024))MB / $((${mem[0]} / 1024))MB"
;;
"Mac OS X")
The text was updated successfully, but these errors were encountered:
ChrisCheney
changed the title
Use MemTotal: - MemAvailable: for usedMem calculation on Linux 3.14+
Use MemTotal: - MemAvailable: for 'memused' calculation on Linux 3.14+
Nov 2, 2020
Linux 3.14 in 2014 added a proper way to determine how much memory is actually in use by adding MemAvailable to /proc/meminfo since it is very complicated to determine what is 'correct' from userspace.
/proc/meminfo: provide estimated available memory git commit for Linux 3.14-rc1
Neofetch also used to support reporting memory using this method on modern kernels, until a patch reverted it on Mar 25, 2016.
Neofetch reverted this support for unknown reasons to 'work on older linux kernel versions' instead of just adding a case statement to support those ancient kernels. By now the support for ancient kernels could probably be dropped altogether although there a few users on CentOS/RHEL 7 (3.10.0) or SLES 11 (3.0.76) that might complain. Note that CentOS 6 (2.6.32) will be EOL at the end of this month (Nov 30, 2020). I don't know of any other supported distribution revisions that still support such an ancient kernel version.
The amount of memory that is not properly reported, by using the old calculations, can end up being many GB in size. I saw the difference between Neofetch and (MemTotal-MemAvailable) vary by over 5GB on my system last week. At the moment on my system it only differs by ~ 1GB, which is still quite a lot. Not only does Neofetch not report the correct amount of memory used on newer kernels but it also does not match conky or screenfetch output so it is especially confusing to new users that don't know why neofetch reports a different amount of used memory. I've seen a number of users ask why the numbers differ between different apps reporting memory used.
The text was updated successfully, but these errors were encountered: