linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting
@ 2021-04-20 12:13 Mike Rapoport
  2021-04-20 12:21 ` Mike Rapoport
  2021-04-20 13:24 ` Matthew Wilcox
  0 siblings, 2 replies; 9+ messages in thread
From: Mike Rapoport @ 2021-04-20 12:13 UTC (permalink / raw)
  To: Jonathan Corbet
  Cc: Alexey Dobriyan, Andrew Morton, Eric Dumazet, Michal Hocko,
	Mike Rapoport, Mike Rapoport, linux-doc, linux-fsdevel,
	linux-kernel, linux-mm, netdev

From: Mike Rapoport <rppt@linux.ibm.com>

Add a paragraph that explains that it may happen that the counters in
/proc/meminfo do not add up to the overall memory usage.

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
---
v2:
* Add brief changelog
* Fix typo
* Update example about network memory usage according to Eric's comment at

https://lore.kernel.org/lkml/CANn89iKprp7WYeZy4RRO5jHykprnSCcVBc7Tk14Ui_MA9OK7Fg@mail.gmail.com

v1: Link: https://lore.kernel.org/lkml/20210420085105.1156640-1-rppt@kernel.org

 Documentation/filesystems/proc.rst | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
index 48fbfc336ebf..8c77a491c436 100644
--- a/Documentation/filesystems/proc.rst
+++ b/Documentation/filesystems/proc.rst
@@ -929,8 +929,14 @@ meminfo
 ~~~~~~~
 
 Provides information about distribution and utilization of memory.  This
-varies by architecture and compile options.  The following is from a
-16GB PIII, which has highmem enabled.  You may not have all of these fields.
+varies by architecture and compile options. Please note that it may happen
+that the memory accounted here does not add up to the overall memory usage
+and the difference for some workloads can be substantial. In many cases there
+are other means to find out additional memory using subsystem specific
+interfaces, for instance /proc/net/sockstat for TCP memory allocations.
+
+The following is from a 16GB PIII, which has highmem enabled.
+You may not have all of these fields.
 
 ::
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting
  2021-04-20 12:13 [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting Mike Rapoport
@ 2021-04-20 12:21 ` Mike Rapoport
  2021-04-20 13:12   ` Michal Hocko
  2021-04-20 13:24 ` Matthew Wilcox
  1 sibling, 1 reply; 9+ messages in thread
From: Mike Rapoport @ 2021-04-20 12:21 UTC (permalink / raw)
  To: Jonathan Corbet
  Cc: Alexey Dobriyan, Andrew Morton, Eric Dumazet, Michal Hocko,
	Mike Rapoport, linux-doc, linux-fsdevel, linux-kernel, linux-mm,
	netdev

On Tue, Apr 20, 2021 at 03:13:54PM +0300, Mike Rapoport wrote:
> From: Mike Rapoport <rppt@linux.ibm.com>
> 
> Add a paragraph that explains that it may happen that the counters in
> /proc/meminfo do not add up to the overall memory usage.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>

Ooops, forgot to add Michal's Ack, sorry.

> ---
> v2:
> * Add brief changelog
> * Fix typo
> * Update example about network memory usage according to Eric's comment at
> 
> https://lore.kernel.org/lkml/CANn89iKprp7WYeZy4RRO5jHykprnSCcVBc7Tk14Ui_MA9OK7Fg@mail.gmail.com
> 
> v1: Link: https://lore.kernel.org/lkml/20210420085105.1156640-1-rppt@kernel.org
> 
>  Documentation/filesystems/proc.rst | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
> index 48fbfc336ebf..8c77a491c436 100644
> --- a/Documentation/filesystems/proc.rst
> +++ b/Documentation/filesystems/proc.rst
> @@ -929,8 +929,14 @@ meminfo
>  ~~~~~~~
>  
>  Provides information about distribution and utilization of memory.  This
> -varies by architecture and compile options.  The following is from a
> -16GB PIII, which has highmem enabled.  You may not have all of these fields.
> +varies by architecture and compile options. Please note that it may happen
> +that the memory accounted here does not add up to the overall memory usage
> +and the difference for some workloads can be substantial. In many cases there
> +are other means to find out additional memory using subsystem specific
> +interfaces, for instance /proc/net/sockstat for TCP memory allocations.
> +
> +The following is from a 16GB PIII, which has highmem enabled.
> +You may not have all of these fields.
>  
>  ::
>  
> -- 
> 2.29.2
> 

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting
  2021-04-20 12:21 ` Mike Rapoport
@ 2021-04-20 13:12   ` Michal Hocko
  0 siblings, 0 replies; 9+ messages in thread
From: Michal Hocko @ 2021-04-20 13:12 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Jonathan Corbet, Alexey Dobriyan, Andrew Morton, Eric Dumazet,
	Mike Rapoport, linux-doc, linux-fsdevel, linux-kernel, linux-mm,
	netdev

On Tue 20-04-21 15:21:08, Mike Rapoport wrote:
> On Tue, Apr 20, 2021 at 03:13:54PM +0300, Mike Rapoport wrote:
> > From: Mike Rapoport <rppt@linux.ibm.com>
> > 
> > Add a paragraph that explains that it may happen that the counters in
> > /proc/meminfo do not add up to the overall memory usage.
> > 
> > Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
> 
> Ooops, forgot to add Michal's Ack, sorry.

Let's make it more explicit
Acked-by: Michal Hocko <mhocko@suse.com>

Thanks!
-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting
  2021-04-20 12:13 [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting Mike Rapoport
  2021-04-20 12:21 ` Mike Rapoport
@ 2021-04-20 13:24 ` Matthew Wilcox
  2021-04-20 13:57   ` Michal Hocko
  2021-04-20 14:51   ` Mike Rapoport
  1 sibling, 2 replies; 9+ messages in thread
From: Matthew Wilcox @ 2021-04-20 13:24 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Jonathan Corbet, Alexey Dobriyan, Andrew Morton, Eric Dumazet,
	Michal Hocko, Mike Rapoport, linux-doc, linux-fsdevel,
	linux-kernel, linux-mm, netdev

On Tue, Apr 20, 2021 at 03:13:54PM +0300, Mike Rapoport wrote:
> Add a paragraph that explains that it may happen that the counters in
> /proc/meminfo do not add up to the overall memory usage.

... that is, the sum may be lower because memory is allocated for other
purposes that is not reported here, right?

Is it ever possible for it to be higher?  Maybe due to a race when
sampling the counters?

>  Provides information about distribution and utilization of memory.  This
> -varies by architecture and compile options.  The following is from a
> -16GB PIII, which has highmem enabled.  You may not have all of these fields.
> +varies by architecture and compile options. Please note that it may happen
> +that the memory accounted here does not add up to the overall memory usage
> +and the difference for some workloads can be substantial. In many cases there
> +are other means to find out additional memory using subsystem specific
> +interfaces, for instance /proc/net/sockstat for TCP memory allocations.

How about just:

+varies by architecture and compile options.  The memory reported here
+may not add up to the overall memory usage and the difference for some
+workloads can be substantial. [...]

But I'd like to be a bit more explicit about the reason, hence my question
above to be sure I understand.


It's also not entirely clear which of the fields in meminfo can be
usefully summed.  VmallocTotal is larger than MemTotal, for example.
But I know that KernelStack is allocated through vmalloc these days,
and I don't know whether VmallocUsed includes KernelStack or whether I
can sum them.  Similarly, is Mlocked a subset of Unevictable?

There is some attempt at explaining how these numbers fit together, but
it's outdated, and doesn't include Mlocked, Unevictable or KernelStack

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting
  2021-04-20 13:24 ` Matthew Wilcox
@ 2021-04-20 13:57   ` Michal Hocko
  2021-04-20 14:05     ` Michal Hocko
  2021-04-20 17:58     ` Alexey Dobriyan
  2021-04-20 14:51   ` Mike Rapoport
  1 sibling, 2 replies; 9+ messages in thread
From: Michal Hocko @ 2021-04-20 13:57 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Mike Rapoport, Jonathan Corbet, Alexey Dobriyan, Andrew Morton,
	Eric Dumazet, Mike Rapoport, linux-doc, linux-fsdevel,
	linux-kernel, linux-mm, netdev

On Tue 20-04-21 14:24:30, Matthew Wilcox wrote:
> On Tue, Apr 20, 2021 at 03:13:54PM +0300, Mike Rapoport wrote:
> > Add a paragraph that explains that it may happen that the counters in
> > /proc/meminfo do not add up to the overall memory usage.
> 
> ... that is, the sum may be lower because memory is allocated for other
> purposes that is not reported here, right?

yes. Many direct page allocator users are not accounted in any of the
existing counters.

> Is it ever possible for it to be higher?  Maybe due to a race when
> sampling the counters?

Yes likely possible. You will never get an atomic snapshot of all
counters.

> >  Provides information about distribution and utilization of memory.  This
> > -varies by architecture and compile options.  The following is from a
> > -16GB PIII, which has highmem enabled.  You may not have all of these fields.
> > +varies by architecture and compile options. Please note that it may happen
> > +that the memory accounted here does not add up to the overall memory usage
> > +and the difference for some workloads can be substantial. In many cases there
> > +are other means to find out additional memory using subsystem specific
> > +interfaces, for instance /proc/net/sockstat for TCP memory allocations.
> 
> How about just:
> 
> +varies by architecture and compile options.  The memory reported here
> +may not add up to the overall memory usage and the difference for some
> +workloads can be substantial. [...]
> 
> But I'd like to be a bit more explicit about the reason, hence my question
> above to be sure I understand.
> 
> 
> It's also not entirely clear which of the fields in meminfo can be
> usefully summed.  VmallocTotal is larger than MemTotal, for example.

Yes. Many/Most counters cannot be simply sumed up. A trivial example would be
Active/Inactive is a sum of both anona and file. Mlocked will be
accounted in LRU pages and Unevictable. MemAvailable is not really a
counter... 

Usual memory consumption is usually something like LRU pages + Slab
memory + kernel stack + vmalloc used + pcp.

> But I know that KernelStack is allocated through vmalloc these days,
> and I don't know whether VmallocUsed includes KernelStack or whether I
> can sum them.  Similarly, is Mlocked a subset of Unevictable?
> 
> There is some attempt at explaining how these numbers fit together, but
> it's outdated, and doesn't include Mlocked, Unevictable or KernelStack

Agreed there is a lot of tribal knowledge or even misconceptions flying
around and it will take much more work to put everything into shape.
This is only one tiny step forward.
-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting
  2021-04-20 13:57   ` Michal Hocko
@ 2021-04-20 14:05     ` Michal Hocko
  2021-04-20 17:58     ` Alexey Dobriyan
  1 sibling, 0 replies; 9+ messages in thread
From: Michal Hocko @ 2021-04-20 14:05 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Mike Rapoport, Jonathan Corbet, Alexey Dobriyan, Andrew Morton,
	Eric Dumazet, Mike Rapoport, linux-doc, linux-fsdevel,
	linux-kernel, linux-mm, netdev

On Tue 20-04-21 15:57:08, Michal Hocko wrote:
[...]
> Usual memory consumption is usually something like LRU pages + Slab
> memory + kernel stack + vmalloc used + pcp.
> 
> > But I know that KernelStack is allocated through vmalloc these days,
> > and I don't know whether VmallocUsed includes KernelStack or whether I
> > can sum them.  Similarly, is Mlocked a subset of Unevictable?

Forgot to reply to these two. Yes they do. So if we want to be precise
then you have to check the stack allocation configuration. There are
just so many traps lurking here. Something you get used to over time
but this is certainly far far away from an ideal state. What else we can
expect from an ad hoc approach to providing data to userspace that was
historically applied to this and many other proc interfaces. We are
trying to be strict for some time but some mistakes are simply hard to
fix up (e.g. accounting shmem as a page cache to name some more).

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting
  2021-04-20 13:24 ` Matthew Wilcox
  2021-04-20 13:57   ` Michal Hocko
@ 2021-04-20 14:51   ` Mike Rapoport
  1 sibling, 0 replies; 9+ messages in thread
From: Mike Rapoport @ 2021-04-20 14:51 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Jonathan Corbet, Alexey Dobriyan, Andrew Morton, Eric Dumazet,
	Michal Hocko, Mike Rapoport, linux-doc, linux-fsdevel,
	linux-kernel, linux-mm, netdev

On Tue, Apr 20, 2021 at 02:24:30PM +0100, Matthew Wilcox wrote:
> On Tue, Apr 20, 2021 at 03:13:54PM +0300, Mike Rapoport wrote:
> > Add a paragraph that explains that it may happen that the counters in
> > /proc/meminfo do not add up to the overall memory usage.
> 
> ... that is, the sum may be lower because memory is allocated for other
> purposes that is not reported here, right?
> 
> Is it ever possible for it to be higher?  Maybe due to a race when
> sampling the counters?
> 
> >  Provides information about distribution and utilization of memory.  This
> > -varies by architecture and compile options.  The following is from a
> > -16GB PIII, which has highmem enabled.  You may not have all of these fields.
> > +varies by architecture and compile options. Please note that it may happen
> > +that the memory accounted here does not add up to the overall memory usage
> > +and the difference for some workloads can be substantial. In many cases there
> > +are other means to find out additional memory using subsystem specific
> > +interfaces, for instance /proc/net/sockstat for TCP memory allocations.
> 
> How about just:
> 
> +varies by architecture and compile options.  The memory reported here
> +may not add up to the overall memory usage and the difference for some
> +workloads can be substantial. [...]

I like this. I also for adding a sentence about overlap in the counters:

+varies by architecture and compile options.  Some of the counters reported
+here overlap.  The memory reported by the non overlapping counters may not
+add up to the overall memory usage and the difference for some workloads
can be substantial. [...]
 
> But I'd like to be a bit more explicit about the reason, hence my question
> above to be sure I understand.
> 
> It's also not entirely clear which of the fields in meminfo can be
> usefully summed.  VmallocTotal is larger than MemTotal, for example.
> But I know that KernelStack is allocated through vmalloc these days,
> and I don't know whether VmallocUsed includes KernelStack or whether I
> can sum them.  Similarly, is Mlocked a subset of Unevictable?
> 
> There is some attempt at explaining how these numbers fit together, but
> it's outdated, and doesn't include Mlocked, Unevictable or KernelStack

Fixing the outdated docs and adding more detailed explanation is obviously
welcome, but it's beyond the scope of the current patch.

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting
  2021-04-20 13:57   ` Michal Hocko
  2021-04-20 14:05     ` Michal Hocko
@ 2021-04-20 17:58     ` Alexey Dobriyan
  2021-04-21  6:35       ` Michal Hocko
  1 sibling, 1 reply; 9+ messages in thread
From: Alexey Dobriyan @ 2021-04-20 17:58 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Matthew Wilcox, Mike Rapoport, Jonathan Corbet, Andrew Morton,
	Eric Dumazet, Mike Rapoport, linux-doc, linux-fsdevel,
	linux-kernel, linux-mm, netdev

On Tue, Apr 20, 2021 at 03:57:07PM +0200, Michal Hocko wrote:
> On Tue 20-04-21 14:24:30, Matthew Wilcox wrote:
> > On Tue, Apr 20, 2021 at 03:13:54PM +0300, Mike Rapoport wrote:
> > > Add a paragraph that explains that it may happen that the counters in
> > > /proc/meminfo do not add up to the overall memory usage.
> > 
> > ... that is, the sum may be lower because memory is allocated for other
> > purposes that is not reported here, right?
> 
> yes. Many direct page allocator users are not accounted in any of the
> existing counters.

Does virtio_balloon dereserve special mention?

From inside VM memory borrowing looks like one giant memory leak resulting
in support tickets (not that people who file them read internal kernel
documentation...)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting
  2021-04-20 17:58     ` Alexey Dobriyan
@ 2021-04-21  6:35       ` Michal Hocko
  0 siblings, 0 replies; 9+ messages in thread
From: Michal Hocko @ 2021-04-21  6:35 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Matthew Wilcox, Mike Rapoport, Jonathan Corbet, Andrew Morton,
	Eric Dumazet, Mike Rapoport, linux-doc, linux-fsdevel,
	linux-kernel, linux-mm, netdev

On Tue 20-04-21 20:58:56, Alexey Dobriyan wrote:
> On Tue, Apr 20, 2021 at 03:57:07PM +0200, Michal Hocko wrote:
> > On Tue 20-04-21 14:24:30, Matthew Wilcox wrote:
> > > On Tue, Apr 20, 2021 at 03:13:54PM +0300, Mike Rapoport wrote:
> > > > Add a paragraph that explains that it may happen that the counters in
> > > > /proc/meminfo do not add up to the overall memory usage.
> > > 
> > > ... that is, the sum may be lower because memory is allocated for other
> > > purposes that is not reported here, right?
> > 
> > yes. Many direct page allocator users are not accounted in any of the
> > existing counters.
> 
> Does virtio_balloon dereserve special mention?

Yes

> From inside VM memory borrowing looks like one giant memory leak resulting
> in support tickets (not that people who file them read internal kernel
> documentation...)

Even if people do not read that documentation it is really good to have
a reference you can send when you are dealing with bug reports.

Thanks!

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-04-21  6:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 12:13 [PATCH v2] docs: proc.rst: meminfo: briefly describe gaps in memory accounting Mike Rapoport
2021-04-20 12:21 ` Mike Rapoport
2021-04-20 13:12   ` Michal Hocko
2021-04-20 13:24 ` Matthew Wilcox
2021-04-20 13:57   ` Michal Hocko
2021-04-20 14:05     ` Michal Hocko
2021-04-20 17:58     ` Alexey Dobriyan
2021-04-21  6:35       ` Michal Hocko
2021-04-20 14:51   ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).