Re: Why is Shmem included in Cached in /proc/meminfo?

From: Matthew Wilcox
Date: Mon Aug 30 2021 - 10:42:19 EST


On Mon, Aug 30, 2021 at 07:34:38AM -0700, Randy Dunlap wrote:
> [add linux-mm mailing list]
>
> On 8/30/21 12:44 AM, Mikko Rantalainen wrote:
> > It's not immediately obvious from fs/proc/meminfo.c function
> > meminfo_proc_show() but the output of Cached: field seems to always
> > include all of Shmem: field, too.
> >
> > Is this intentional? Usually cache is something that can be discarded if
> > needed but shared memory (e.g. used to contain files in tmpfs) cannot be
> > discarded without a data-loss. As such, I'd argue that it shouldn't be
> > included in the Cached: output.

That's a reasonable position to take.

Another point of view is that everything in tmpfs is part of the page
cache and can be written out to swap, so keeping it as part of Cached
is not misleading.

I can see it both ways, and personally, I'd lean towards clarifying
the documentation about how shmem is accounted rather than changing
how the memory usage is reported.