feat(system): add MemAvailable field to MemInfo struct#963
Conversation
Add MemAvailable to provide a more accurate estimate of memory available for new applications without swapping. On Linux, this is parsed from /proc/meminfo. On FreeBSD, Solaris, and Windows, it falls back to MemFree. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Evzen Gasta <evzen.ml@seznam.cz>
| // Total memory is total physical memory less than memory locked by kernel | ||
| meminfo.MemTotal = MemTotal | ||
| meminfo.MemFree = MemFree | ||
| meminfo.MemAvailable = MemFree |
There was a problem hiding this comment.
I'm a bit unsure about the ambiguity due to this aliasing; consumers are under the incorrect assumption that MemAvailable is indeed present and when that yields incorrect results, it's much more confusing than the current issue. Even if we don't intend to really extract MemAvailable on these platforms, I believe it'd be easier to leave it as nil and let the consumer handle it.
There was a problem hiding this comment.
@danishprakash I've removed the MemAvailable from unsupported platforms
There was a problem hiding this comment.
@dfr Might be able to get advice here how to query MemAvailable on freebsd
The field is not a pointer so returning 0 on other platforms seem unexpected for callers, if podman into would always report 0 on freebsd that could confuse users.
Signed-off-by: Evzen Gasta <evzen.ml@seznam.cz>
mtrmac
left a comment
There was a problem hiding this comment.
- The code exists for several other platforms. We can’t very well just ignore that and leave that for someone else to clean up in the future. At the very least, there should be a defined “unknown” value, as already discussed for FreeBSD.
- Probably use -1 for “unknown”, not 0
- Either way for that special case must be documented in the type
Signed-off-by: Evzen Gasta <evzen.ml@seznam.cz>
mtrmac
left a comment
There was a problem hiding this comment.
ACK. Eventually please squash.
| case "MemFree:": | ||
| meminfo.MemFree = bytes | ||
| case "MemAvailable:": | ||
| meminfo.MemAvailable = bytes |
There was a problem hiding this comment.
I suppose initialize to -1 before starting to parse, in case the field were missing. (Yes, we don’t do that for the other fields, but those don’t have the -1 case defined.)
Signed-off-by: Evzen Gasta <evzen.ml@seznam.cz>
Add MemAvailable to provide a more accurate estimate of memory available for new applications without swapping. On Linux, this is parsed from /proc/meminfo. On FreeBSD, Solaris, and Windows, it falls back to MemFree.
Closes #962
Related to: podman-container-tools/podman#29116