Skip to content

feat(system): add MemAvailable field to MemInfo struct#963

Open
gastoner wants to merge 4 commits into
podman-container-tools:mainfrom
gastoner:add-memavailable-to-meminfo
Open

feat(system): add MemAvailable field to MemInfo struct#963
gastoner wants to merge 4 commits into
podman-container-tools:mainfrom
gastoner:add-memavailable-to-meminfo

Conversation

@gastoner

@gastoner gastoner commented Jul 7, 2026

Copy link
Copy Markdown

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

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>
@github-actions github-actions Bot added the storage Related to "storage" package label Jul 7, 2026
Comment thread storage/pkg/system/meminfo_freebsd.go Outdated
// Total memory is total physical memory less than memory locked by kernel
meminfo.MemTotal = MemTotal
meminfo.MemFree = MemFree
meminfo.MemAvailable = MemFree

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danishprakash I've removed the MemAvailable from unsupported platforms

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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>
@gastoner gastoner requested a review from danishprakash July 7, 2026 08:18

@mtrmac mtrmac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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>
@gastoner gastoner requested review from Luap99 and mtrmac July 7, 2026 18:42

@mtrmac mtrmac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. Eventually please squash.

case "MemFree:":
meminfo.MemFree = bytes
case "MemAvailable:":
meminfo.MemAvailable = bytes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

@mtrmac mtrmac self-requested a review July 7, 2026 19:15
Signed-off-by: Evzen Gasta <evzen.ml@seznam.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage Related to "storage" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add MemAvailable field to MemInfo struct

4 participants