vivien / i3blocks-contrib

Official repository for community contributed blocklets
https://github.com/vivien/i3blocks
Other
1.31k stars 488 forks source link

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

Open koshell opened 1 year ago

koshell commented 1 year ago

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 commented 10 months ago

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