mem: populate Cached from bcachestats on OpenBSD#2029
Merged
shirou merged 2 commits intoshirou:masterfrom Mar 21, 2026
Merged
Conversation
On OpenBSD, Cached was hardcoded to 0 with the comment "not available", while Buffers was populated from bcachestats.Numbufpages (buffer cache pages). Since the buffer cache is the closest OpenBSD equivalent to Linux cached memory, populate Cached from the same source. This fixes the Available memory calculation which includes Cached: Available = Inactive + Cached + Free Previously, Available was understated because Cached was always 0. Ref: influxdata/telegraf#18469
shirou
approved these changes
Mar 20, 2026
Owner
shirou
left a comment
There was a problem hiding this comment.
LGTM! Clean and well-motivated fix.
The reordering so that the bcachestats syscall happens before constructing ret is a nice improvement — no more partially-populated struct on error paths.
One minor suggestion: it might be worth adding a brief comment explaining why Cached and Buffers share the same value, to help future maintainers understand this is intentional and not a copy-paste mistake. Something like:
// On OpenBSD, the buffer cache is the closest equivalent to both
// Linux's Buffers and Cached memory.
bcache := uint64(bcs.Numbufpages) * p
Not a blocker though. But if you have time, it'd be great if you could update the PR to add that comment. Thanks for the fix and the clear PR description!
Owner
|
Thank you for the update! |
This was referenced Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On OpenBSD,
VirtualMemoryStat.Cachedwas hardcoded to0whileBufferswas populated frombcachestats.Numbufpages. Since the buffer cache is the closest OpenBSD equivalent to Linux cached memory, this change populatesCachedfrom the same source.This fixes the
Availablememory calculation:Previously,
Availablewas understated on OpenBSD becauseCachedwas always0, affecting downstream consumers (e.g. influxdata/telegraf#18469).