Skip to content

fix(inputs.mem): Use vm.Cached as vm.Buffers on OpenBSD#18469

Merged
srebhan merged 1 commit intoinfluxdata:masterfrom
atanas-vladimirov:openbsd-mem
Mar 16, 2026
Merged

fix(inputs.mem): Use vm.Cached as vm.Buffers on OpenBSD#18469
srebhan merged 1 commit intoinfluxdata:masterfrom
atanas-vladimirov:openbsd-mem

Conversation

@atanas-vladimirov
Copy link
Copy Markdown
Contributor

@atanas-vladimirov atanas-vladimirov commented Mar 9, 2026

Summary

The problem is that vm.Cached is unavailable on OpenBSD and the nearest equivalent to Linux cache memory is vm.Buffers.

I've been testing the change on my OpenBSD server for the last month and here is how it looks like:

image

Checklist

Related issues

resolves #18382

The problem is that vm.Cached is unavailable on OpenBSD and the
nearest equivalent to Linux cache memory is vm.Buffers.

Signed-off-by: Atanas Vladimirov <vladimirov.atanas@gmail.com>
@atanas-vladimirov
Copy link
Copy Markdown
Contributor Author

atanas-vladimirov commented Mar 9, 2026

I made a mistake in the commit message - used bug instead of fix.
I have tried to update it but the Semantic PR and Commit Messages still fails - not sure how to make it happy.

Any help will be appreciated.

Update: Not enough coffee - I have edited the PR title :)))

@atanas-vladimirov atanas-vladimirov changed the title bug(inputs.mem): OpenBSD lacks vm.Cached so use vm.Buffers instead fix(inputs.mem): OpenBSD lacks vm.Cached so use vm.Buffers instead Mar 9, 2026
@telegraf-tiger telegraf-tiger Bot added fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Mar 9, 2026
@telegraf-tiger
Copy link
Copy Markdown
Contributor

telegraf-tiger Bot commented Mar 9, 2026

@skartikey
Copy link
Copy Markdown
Contributor

skartikey commented Mar 13, 2026

@srebhan Verified the fix against the actual gopsutil v4.26.2 source (mem/mem_openbsd.go):

  • Line 46: Cached: 0, // not available - confirms vm.Cached is hardcoded to 0 on OpenBSD
  • Line 67: ret.Buffers = uint64(bcs.Numbufpages) * p - confirms vm.Buffers is populated from the OpenBSD bcache stats syscall

The change correctly maps vm.Buffers to the "cached" field, which is the closest equivalent to Linux cache memory on OpenBSD. Keeping the field name as "cached" avoids breaking existing user dashboards/queries.

No test added, but the existing test file only covers the Linux platform case - the lack of OpenBSD/Darwin/FreeBSD test coverage is a pre-existing gap.

@skartikey skartikey self-assigned this Mar 13, 2026
@skartikey skartikey added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Mar 13, 2026
Copy link
Copy Markdown
Contributor

@skartikey skartikey left a comment

Choose a reason for hiding this comment

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

@atanas-vladimirov Thanks for the contribution!

@skartikey skartikey removed their assignment Mar 13, 2026
@atanas-vladimirov
Copy link
Copy Markdown
Contributor Author

Thanks, @skartikey.
I wish you a wonderful weekend!

@srebhan srebhan changed the title fix(inputs.mem): OpenBSD lacks vm.Cached so use vm.Buffers instead fix(inputs.mem): Use vm.Cached as vm.Buffers on OpenBSD Mar 16, 2026
Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

@srebhan srebhan merged commit 249fe86 into influxdata:master Mar 16, 2026
31 of 33 checks passed
@github-actions github-actions Bot added this to the v1.38.1 milestone Mar 16, 2026
srebhan pushed a commit that referenced this pull request Mar 16, 2026
Signed-off-by: Atanas Vladimirov <vladimirov.atanas@gmail.com>
(cherry picked from commit 249fe86)
skartikey added a commit to skartikey/gopsutil that referenced this pull request Mar 17, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegraf mem plugin and OpenBSD Cache memory

3 participants