Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Twice the reported RAM usage than htop #161

Closed
sukulent opened this issue Nov 18, 2021 · 4 comments
Closed

[BUG] Twice the reported RAM usage than htop #161

sukulent opened this issue Nov 18, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@sukulent
Copy link

I am seeing ~twice the reported used RAM than htop or free reports.

I would expect it to read the same.

Is this expected behavior?

  • btop++ version: 1.0.5
  • Binary: release binary
  • Linux: debian buster 4.19.0-18-amd
  • Terminal used: byobu/tmux in tty
@sukulent sukulent added the bug Something isn't working label Nov 18, 2021
@sukulent sukulent changed the title [BUG] [BUG] Twice the reported RAM usage than htop Nov 18, 2021
@ChUnterberger
Copy link

ChUnterberger commented Nov 21, 2021

It looks like free calculates the used memory differently than btop.

btop calculates
used = total - available
while free calculates
used = total - free - cached - buffers

see https://gitlab.com/procps-ng/procps/-/blob/newlib/proc/meminfo.c#L702

htop and top both seem to follow the free implementation as all three programs report the same value for used.

I wrote a fix which follows the free implementation but it seems to be still off by a few hundred MiB.
I still have to find where the difference comes in.

The question really is which definition of used the code should follow.
@aristocratos Given that free, htop and top follow this definition, is this something which you want to change?

A change would cause Used: and Availabe: not to add up to Total: and 100% anymore.

@aristocratos
Copy link
Owner

#165

@ChUnterberger I'm not convinced the calculation should change without knowing the reasoning for how it's calculated in free, htop etc.
To me it's makes sense that only non available memory is marked as "used". Maybe also free should be subtracted, but was under the assumption that free was included in available.

@ChUnterberger
Copy link

@aristocratos Thank you for your input

According to this https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773 MemAvailable is an estimate of how much memory a process could allocate without swapping. I am sure it includes MemFree.

MemUsed is a really just a question of definition and expectation and likely for this reason not defined in /proc/meminfo at all.

If you are very strict with your definitiion then you would have to say
used = total - free
but this would iritate lots of users.

The free implementation predates MemAvailable and therefore the developers had to come up with a definition of used.
free chose the definition
used = total - free - cached - buffers - SReclaimable

and btop chose
used = total - available

I can live with either of the definitions but i agree that the current implementation best shows to a user how much main memory is used and cannot be reclaimed easily.

The issue is just the expectation other programs like free, htop and top cause when they will be inevitable compared against btop.

@sukulent If you agree with this, then i would suggest to close the issue.

@sukulent
Copy link
Author

Thanks for the explanation, I learned something today!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants