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

  • From: "Michal Hocko" <dmarc-noreply@xxxxxxxxxxxxx> ("mhocko")
  • To: procps@xxxxxxxxxxxxx
  • Date: Tue, 21 Jun 2022 15:19:22 +0200

On Fri 17-06-22 19:14:41, Craig Small wrote:
[...]

I think we can safely say putting Cached into the Used calculation is
wrong. There is definitely 5 or 10MB of memory that is being used and the
current free won't show this. It's probably a failure of Cached giving the
"right" answer rather than free's fault, but we are beholden to what the
kernel gives us. Cached used to mean cache for files paged/swapped to disk
but it doesn't anymore.

Cached field in /proc/meminfo has always meant the amount of the page
cache. Shmem/tmpfs has always (to my knowledge) used the page cache to
maintain the memory. This turned out to be rather confusing because a
lot of people considered Cached the amount of easily disposable memory
because it can be easily refaulted from the storage. But that is not the
case for shmem/tmpfs because the IO involved is swap based.

The added confusion, and the reason why free(1) chosen to deduct Cached
from the used memory is because a lot of people simply do not like to
see all the memory being used because that might signal a memory
shortage. In general caches do not really create that danger because the
memory is reclaimed should there be a need.

I also explored doing some delta of (Cached-Shmem) but for some systems
they both increased by 5MB which was good, but for others Cached increased
by 6MB and Shmem by 5MB.

We have several options here:

   1. Original: Used = Total - Free - Cached - SReclaimable - Buffers
   2. No Cache: Used = Total - Free - SReclaimable - Buffers
   3. Available: Used = Total - Available
   4. Simple: Used = Total - Free

Of all above I would vote for using Available because that is an
estimate of usable memory. It is not a perfect estimatation but better
than the existing one. It also prevents panic for those who rely on Used
memory to be excluding easily reclaimable page cache.

HTH

-- 
Michal Hocko
SUSE Labs

Other related posts: