API memory discrepancy

There is a discrepancy between the web GUI and the API, I think.

The web shows this

API shows this

How are buffer and cache calculated on the web then?

Hi mickey, thanks for the detailed screenshots.

Good news first: nothing is wrong with your device. Both the web page and the API pull their numbers from the same place (psutil, which reads /proc/meminfo), and both report in MiB. The mismatch comes down to what the “buffers/cache” figure means in each spot.

On the web System Info page, the “Buffers / cache” row is a combined figure. We calculate it as total minus used minus free, so it includes the kernel buffers AND the page cache AND shared memory all rolled into one slice. We do it that way so the pie chart adds up cleanly to your total RAM. That is why it tends to be a large number.

The API’s buff field is narrower. It only reports the raw “Buffers” value from the kernel, which is
usually small, and it does not currently include the page cache at all. So you are not looking at the same quantity in the two places, which is why they don’t line up.

In short, the web “Buffers / cache” is roughly buffers + page cache + shared, while the API buff is
just buffers on its own. Both are accurate for what they are measuring.

I agree this is confusing, and the API arguably should expose a cached value (and/or a combined field) so you can reconstruct what the web shows. I’m going to raise this internally so we can make the two consistent, and I’ll link the fix back here once there’s a PR.

Out of interest, what are you using the API memory figures for? That’ll help me make sure whatever we change actually fits your use case.

This is perfect thanks. I assumed it was just the way I was summing the values up but also thought it looked off. Glad to hear you agree haha.

Use case it’s pretty straightforward. In a previous thread here I was having some memory leak issues so I’ve got a Python script that pulls these values on a rolling basis just so I can keep tabs on it to make sure it doesn’t crop back up again.

Coming back to this later than I should have, but the fix is now written.

You were right that the numbers looked off, and it was not your maths. The “Buffers / cache” row on the System Info page and the buff field in the API were never measuring the same thing. buff is only the small kernel buffers figure. The web row is that plus the page cache plus shared memory, and the page cache is nearly all of it.

Here is one of our test machines, read at the same moment:

Where Field Value
System Info page Buffers / cache 3,129 MiB
API buff 878 MiB

So not a rounding difference. A different quantity. And there was nothing else in the API response you could add up to get back to the page figure, which is exactly why your script could not make the two agree.

What changes: the API now returns a cache field alongside buff, holding the same number the page shows. buff keeps its current meaning, so nothing you already read changes under you. Both figures now come from one shared piece of code, so they cannot drift apart again.

The report: issue 3432
The fix: PR 3433

For your rolling memory script, cache is the one to graph once this lands. It will be in the next release.