Score:0

Memory usage: big difference in `free -m` and htop as well calculation of used memory in htop compared from /proc/meminfo

in flag

I'm aware of this question https://stackoverflow.com/questions/41224738/how-to-calculate-system-memory-usage-from-proc-meminfo-like-htop Answer seems outdated regarding memory usage and this question seems more complex.

htop definitely now doesn't calculate total memory via MemTotal - MemFree anymore. There https://access.redhat.com/solutions/406773 I found a soluation that could fit. According to that it would be calculated via MemTotal - MemFree - Buffers - Cached - Slab but that leads to a too low memory usage compared to htop.

Memory usage in htop seems to be quite related as free -m shows in cell Mem: used

But if you create a ramdisk, things change a lot:

mkdir mnt
sudo mount -t tmpfs none mnt
cd mnt 
sudo dd if=/dev/urandom of=test bs=32M status=progress

Above will create a RAM disk 50 % size of installed memory and fill this ramdisk.

htop now shows a bit more than half of the physical RAM used, in test case 3.82 GB of 7.44 GB used. However free -m shows still only 104 MB used compared to 102 MB before creating and filling the RAM disk. So 104 MB used is definitely wrong, because half of the physical system memory can't be available anymore since it is used by RAM disk.

In /proc/meminfo size of RAM disk seems to be included in Cached, so for calculating used memory cached shouldn't be substracted.

So why does free -m report such a wrong free memory value? By default there are various tmpfs on distributions like Debian or Ubuntu which then means free -m gives wrong impression of free memory.

Memory calculation of htop seems quite reasonable. So how can the htop value be calculated from /proc/meminfo?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.