Skip to content

Treat buffers and cache as free memory in memory free calculation - #111

Open
ckuethe wants to merge 5 commits into
HarvsG:masterfrom
ckuethe:master
Open

Treat buffers and cache as free memory in memory free calculation#111
ckuethe wants to merge 5 commits into
HarvsG:masterfrom
ckuethe:master

Conversation

@ckuethe

@ckuethe ckuethe commented Feb 19, 2026

Copy link
Copy Markdown

Treat memory_buff_cache as free memory rather than used memory. It's not totally wrong to do this, since you can evict a lot of that with echo 3 > /proc/sys/vm/drop_caches and see an immediate drop in top, but the RPC API really should be more detailed.

Tested on Slate AXT-1800... guess when I restarted HomeAssistant to pick up the change.

Screenshot_2026-02-19_11-00-52

Fixes #85

Treat memory_buff_cache as free memory rather than used memory. It's not totally wrong to do this, since you can evict a lot of that with `echo 3 > /proc/sys/vm/drop_caches` and see an immediate drop in `top`, but the RPC API really should be more detailed.

Fixes HarvsG#85
@ckuethe ckuethe changed the title Treat buffers and cache in memory free calculation Treat buffers and cache as free memory in memory free calculation Feb 19, 2026

@HarvsG HarvsG left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

See suggestions

or None,
extra_attributes_fn=lambda system_status: {
"memory_total": system_status.get("memory_total"),
"memory_free": system_status.get("memory_free"),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

do we want to correct this as well, or is it helpful to have?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Maybe we could report

"memory_free": system_status.get("memory_free"),
"memory_buffer_and_cache": system_status.get("memory_buff_cache"),

@ckuethe ckuethe Feb 20, 2026

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.

I'd support reporting memory_buffer_and_cache separately, for those who care. It's not something I'd use. I'm not sure that I'd use the actual values; percentages are more useful to me, but it wouldn't hurt to expose.

What do you think about:

  • memory_total -> memory_total
  • memory_free -> memory_free
  • memory_buff_cache -> memory_buffer_and_cache
  • memory_buf_cache + memory_free -> memory_available
  • memory_total - memory_available -> memory_used

The first 3 are reported unchanged because that's what the API says. The next two are computed, but feel more meaningful to me. If I had a less capable router, I might care more about exactly how many KB of memory are free/used, but on the Slate AXT-1800 percentage is more useful.

Yes, I could compute this in homeassistant, but I think it's nicer to expose the numeric values and percentages.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes, I think all of that is fair. Keep them as extra_attributes, that means that they are not stored and those that are interested can turn them into sensors with templates.

@HarvsG

HarvsG commented Mar 9, 2026

Copy link
Copy Markdown
Owner

@ckuethe
I have some time on my hands - happy to review if you can make the above changes

@ckuethe

ckuethe commented Mar 9, 2026

Copy link
Copy Markdown
Author

Now that my HA instance with this integration is behaving better I'll have another look at it. Instead of using templates which adds extra work for the user, I'd rather send the values - perhaps as diagnostics - which can be easily enabled or disabled in the UI.

@HarvsG

HarvsG commented Mar 9, 2026

Copy link
Copy Markdown
Owner

Good idea, please make some disabled by default

@ckuethe

ckuethe commented Mar 9, 2026

Copy link
Copy Markdown
Author

I think the diagnostic category is disabled by default, but it's easy to enable at runtime. If not, there are other examples of that behavior I can reference.

@ckuethe

ckuethe commented Mar 9, 2026

Copy link
Copy Markdown
Author
glinet2 glinet

@ckuethe

ckuethe commented Mar 14, 2026

Copy link
Copy Markdown
Author

updated to latest

shauneccles added a commit to shauneccles/ha-glinet4-integration that referenced this pull request Jun 26, 2026
- Load averages of exactly 0 made the sensor go unavailable: the old
  `... and la[i]` short-circuits on the falsy 0. Use an explicit conditional so
  a genuine 0.0 is reported (HarvsG#152).
- Treat buffer/cache memory as available when computing memory usage, matching
  how Linux reports free memory, and expose memory_buff_cache / memory_available
  / memory_used attributes (HarvsG#111).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong value of memory usage being reported

2 participants