heim
heim copied to clipboard
heim fails to report total memory usage on WSL1
I've been having issues with using the memory library within a WSL1 instance on Ubuntu 18.04.
I tried to run the "free" example on a WSL1 instance using Ubuntu 18.04, and it fails with this error:
Error: Error { source: Kind(InvalidData), context: Some(File { path: "/proc/meminfo" }) }
It works fine on the WSL2, though.
Taking a look at the /proc/meminfo files of both of these, I think the issue is that the "MemAvailable" field doesn't exist on WSL1:
MemTotal: 33483712 kB
MemFree: 22743224 kB
Buffers: 34032 kB
Cached: 188576 kB
...
On the WSL2, it looks like:
MemTotal: 26220580 kB
MemFree: 26108576 kB
MemAvailable: 25898488 kB
Buffers: 4716 kB
Cached: 8320 kB
...
Guessing that since one field is missing, it's tripping up the number of lines check in memory.rs?
Tested a bit more, seems like I initially messed up the comparison and the issue just seems to be on WSL1.
Awesome investigation, thanks for doing it!
Based on this one function from psutil, we can't expect to have MemAvailable: line for kernels < 3.14 and should calculate it manually.