Re: free: regression due to a different calculation of Used memory

Craig Small <[email protected]> Sat, 3 Apr 2021 16:26:58 +1100
Newsgroups gmane.linux.procps.devel
Message-ID <CALy8Cw5gipoOnoK3AVN8y442SBs_5mvB9EA4MPdu5K4ne83nRA@mail.gmail.com>
Hi Michal,
  You probably need to follow through several changes to get to where we
are now.  The fact that something else is not reporting the same thing as
procps happens a lot because its both subjective and a lot of things
(including procps) have and are wrong about how to calculate certain memory
values.

I'd suggest reading the links at
https://gitlab.com/procps-ng/procps/-/commit/602b9a02ce2a3ed443b0b79fca457826da44d654
which discusses some of this issue.
It has a link to the freelist thread where this is change was made.

On Thu, 1 Apr 2021 at 18:30, Michal Hocko <[email protected]>
wrote:

> From a semantic point of view it is quite hard to understand what the
> value is actually trying to represent. I assume that reducing the page
>
This is actually the main problem. What does used mean?

I have also noticed that kb_main_cached = kb_page_cache + kb_slab
> which looks problematic as well. kb_slab will include also unreclaimable
> slab so this is not really a cache. If you wanted to consider

reclaimable slabs then I would expect kb_slab_reclaimable but even then
> this looks like potentially problematic for people relying on the
> previous semantic which really denoted the page cache.
>
We use kb_slab_reclaimable, see
https://gitlab.com/procps-ng/procps/-/blob/master/proc/sysinfo.c#L781

The calculation is now (see
https://gitlab.com/procps-ng/procps/-/blob/master/proc/sysinfo.c#L789 )

Memory Used = Memory Total - Memory Free - ( Cache + Slab Reclaimable ) -
Main Buffers

The first two parts are easy enough, total - free = used

So the question is why are we, in effect, ignoring cache, reclaimable slab
and buffers?

Cache includes tmpfs which is file backed not memory
Reclaimable slab, well it's reclaimable so it's not used.
Buffers, I'm not 100% sure why this is removed now but it made sense later.

If you follow the mail archive at
https://www.freelists.org/post/procps/OmegaPhilxxxxxxxxxxxxx-Bug799716-free-considers-cached-to-include-SUnreclaim
you can see how we got to these figures.

If you really want to go down the Memory Used rabbit hole, try
https://github.com/brndnmtthws/conky/issues/130

 - Craig