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

  • From: Jan Rybar <jrybar@xxxxxxxxxx>
  • To: procps@xxxxxxxxxxxxx
  • Date: Wed, 1 Jun 2022 11:50:37 +0200

Hi Craig,

On Fri, May 27, 2022 at 11:01 PM Craig Small <csmall@xxxxxxxxxxxx> wrote:

Hi Jan,
 Are you looking at the newlib branch or the master one? For clarity, I'm
talking about newlib. I'm also not really sure what you're suggesting needs
changing.

Yes, this time I checked both versions and in newlib, it's defined the same
way as you said below:

https://gitlab.com/procps-ng/procps/-/blob/newlib/proc/meminfo.h#L92
https://gitlab.com/procps-ng/procps/-/blob/newlib/proc/meminfo.c#L702
https://gitlab.com/procps-ng/procps/-/blob/master/proc/sysinfo.c#L789

(OT: Has it been considered to rename (or tag) master to legacy-ish and
newlib to main since procps switched the primary development branch from
which official builds are made?)


libproc exposes both MEM_CACHED and MEM_CACHED_ALL with the former being
only what the Cached: line has while the second adds SReclaimable:
free and top use the second value for their cached figures.

We currently have the situation where we have:

Used = Total - Free - Cached - SReclaimable - Buffers

This is not a question of SReclaimable being subtracted from Total in
summation with Cached or not. Cached is the issue since it contains Shmem
(which contains tmpfs buffers).
Despite the discussion about whether SReclaimable should be considered
"free" memory and subtracted from Total, the main issue is with Cached as
it cannot be always freed and some portion of it is always used and in that
case it cannot be subtracted from Total.
Like I mentioned in the first paragraph of my previous mail.

What I propose is defining Used as any allocated memory because now it
mystifies the user that there is less used memory than mem_free or
sometimes even mem_avail suggest.
I don't want to go far on thin ice of complicated memory management, but
this can be a huge problem on diskless systems where everything is written
in tmpfs. Giant Cached (because of Shmem) just eating-up memory, but Used
looks still low.


This is the same calculation currently used by the old library.

I suggest you also read:

https://www.freelists.org/post/procps/OmegaPhilxxxxxxxxxxxxx-Bug799716-free-considers-cached-to-include-SUnreclaim
https://github.com/brndnmtthws/conky/issues/130

Jaromir back in 2014  made a change where Cached got Slabs added to it
(commit 6cb75efef85f735b72e6c96f197f358f511f8ed9), that got fixed in 2015
by me to only include SReclaimable (commit
05d751c4f076a2f0118b914c5e51cfbb4762ad8e).
The Jaromir change is the one Michal is talking about.
The email thread is found at
https://www.freelists.org/post/procps/kb-main-available-etc,14

To me saying X gives me a value of A but Y gives me a value of B is saying
one should change but not one.
If you are after a definition, free(1) has one for you. You first need to
say why these need to change first before we change the code. You need to
say why things were wrong in 2014 or perhaps things have changed since
then. Were you talking with the RedHat kernel team like Jaromir? Can they
explain why they think the change is needed as the 2014 change was partly
informed from that group before.

Yes, I mentioned that in the beginning of the first paragraph of my
previous mail. I contacted RH's kernel team and was directed to Jerome
Marchand who owns mm.
His words:
"
You won't see that in meminfo.c or vmstat.c, but Shmem page belong to the
page cache and as such are accounted in cached.
If you write a big file in tmpfs, you'll see that both shmem and cache
entry increase
...
Not all pages in page cache are necessarily reclaimable.
And as far a "used" go, well, that depends on the definition of used.
I'd argue that cache and buffer memory is used, even if easily
reclaimable.
I think the important field here is available
...
"used" memory is rather imaginatively defined instead of just
meaning "not free", which is the natural definition. AFAIK, this was
done because people complained that on linux, all their memory was used
by the page cache. But in the end, it seems to have cause more confusion
than anything else.
"

Thanks.


 - Craig



Other related posts: