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

The memory2 block uses incorrect math to calculate ram usage #481

Open
koshell opened this issue Mar 4, 2023 · 1 comment
Open

The memory2 block uses incorrect math to calculate ram usage #481

koshell opened this issue Mar 4, 2023 · 1 comment

Comments

@koshell
Copy link

koshell commented Mar 4, 2023

Being brief, the memory and memory2 blocks give hilariously different results.

Best I can tell the math used by the memory2 block to calculate free ram is wrong. The block uses an assumption like 'Used Memory = Total Memory - Free Memory' however Linux tries very hard to not actually leave any wasted 'free' memory floating around. Instead the correct way to calculate it would be something like:
'Actual Memory Usage = Total - (Free + Buffers + Cached)' (I got the math from https://scoutapm.com/blog/determining-free-memory-on-linux )

This is why the script (memory) says for example I am only using 30% of my ram but the C program (memory2) says I am using 99%.

@carreter
Copy link

carreter commented Jan 3, 2024

Seems like the sysinfo system call doesn't provide info on cache memory unfortunately... so some direct parsing of /proc/meminfo would have to be done.

https://stackoverflow.com/questions/349889/how-do-you-determine-the-amount-of-linux-system-ram-in-c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants