Reputation: 2159
From the author of htops answer How to calculate system memory usage from /proc/meminfo (like htop)
I got to know that the total memory in htop is calculated from /proc/meminfo. I think I could crosscheck this in code as well and it checks out. However compared to memory bar in htop. I see a major difference in the memory values shown in /proc/meminfo.
In my /proc/meminfo the memory consumption reads
MemTotal: 4144807288 kB
MemFree: 3513532764 kB
MemAvailable: 3936769368 kB
Buffers: 1119392 kB
So the Total used memory , which I think represented by the memory bar should be MemTotal-MemFree in GBs which should be (4144807288-3513532764)/1024^2=602Gb as far as I understand. However for me this value shows almost 180Gb. Could anyone explain how the values in /proc/meminfo and one in htop would become different.
Upvotes: 0
Views: 357
Reputation: 30575
Let me first say holy moley that's an insane amount of RAM.
Anyway, there's something not being understood here:
"Memory free" is totally unused memory.
"Memory available" is "Memory free" plus memory that could be freed in an instant if the kernel dropped its file system caches.† Generally, available memory is the stat you should look at / care about.
Using the "Memory available" stat in our calculations instead, let's calculate:
numfmt --to=iec $(((4144807288-3936769368)*1024))
> 199G
Much closer to the 180G htop
displays as the amount of "used" RAM.
Try also running free -h
and look under the "available" column.
† Linux uses your RAM in an interesting way. When a file system block is read, it transparently allocates some unused system RAM so subsequent reads go to RAM instead of the file system. This is because of the traditional notion that disks are slow and RAM is fast. When a program demands some RAM, it immediately drops some or all of this cache to fulfill the request for RAM.
Upvotes: 1