docs: proc.rst: meminfo: briefly describe gaps in memory accounting
Subsystems (6)
PATCH v2 1/1 docs: proc.rst: meminfo: briefly describe gaps in memory accounting
From: Mike Rapoport <[email protected]>
Add a paragraph that explains that it may happen that the counters in /proc/meminfo do not add up to the overall memory usage.
---
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/[email protected]
Documentation/filesystems/proc.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Documentation/filesystems/proc.rst +8 -2
@@ -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. ::
Signature · 1 line
2.29.2
Quoted 6 lines · Mike Rapoport
From: Mike Rapoport <[email protected]>
Add a paragraph that explains that it may happen that the counters in
/proc/meminfodo not add up to the overall memory usage.Signed-off-by Mike Rapoport <[email protected]>
Ooops, forgot to add Michal's Ack, sorry.
Quoted 37 lines
---
v2:
* Add brief changelog
* Fix typo
* Update example about network memory usage according to Eric's comment athttps://lore.kernel.org/lkml/CANn89iKprp7WYeZy4RRO5jHykprnSCcVBc7Tk14Ui_MA9OK7Fg@mail.gmail.com
v1: Link: https://lore.kernel.org/lkml/[email protected]
Documentation/filesystems/proc.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)Documentation/filesystems/proc.rst +8
-2@@ -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. ::Signature · 1 line
2.29.2
Signature · 2 lines
Sincerely yours, Mike.
Michal Hocko
Acked-byQuoted 9 lines · Mike Rapoport
Quoted 6 lines · Mike Rapoport
From: Mike Rapoport <[email protected]>
Add a paragraph that explains that it may happen that the counters in
/proc/meminfodo not add up to the overall memory usage.Signed-off-by Mike Rapoport <[email protected]>Ooops, forgot to add Michal's Ack, sorry.
Let's make it more explicit
Thanks!
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 2 lines · Mike Rapoport
Add a paragraph that explains that it may happen that the counters in
/proc/meminfodo 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?
Documentation/filesystems/proc.rst meminfo · line 936
Quoted 8 lines
Provides information about distribution and utilization of memory. This
Documentation/filesystems/proc.rst +5
-2-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
Quoted 6 lines · Matthew Wilcox
Quoted 2 lines · Mike Rapoport
Add a paragraph that explains that it may happen that the counters in
/proc/meminfodo 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.
Quoted 2 lines
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.
Quoted 15 lines
Documentation/filesystems/proc.rst meminfo · line 936
Quoted 8 lines
Provides information about distribution and utilization of memory. This
Documentation/filesystems/proc.rst +5
-2-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:
(quoted diff) +3
-0+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. [...]
Quoted 6 lines
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.
Quoted 6 lines
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.
Signature · 2 lines
Michal Hocko SUSE Labs
On Tue 20-04-21 15:57:08, Michal Hocko wrote:
[...]
Quoted 6 lines
Usual memory consumption is usually something like LRU pages + Slab memory + kernel stack + vmalloc used + pcp.
Quoted 3 lines
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).
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 21 lines · Matthew Wilcox
Quoted 2 lines · Mike Rapoport
Add a paragraph that explains that it may happen that the counters in
/proc/meminfodo 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?
Documentation/filesystems/proc.rst meminfo · line 936
Quoted 8 lines
Provides information about distribution and utilization of memory. This
Documentation/filesystems/proc.rst +5
-2-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:
Review
Quoted 3 lines
(quoted diff) +3
-0+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. [...]
Quoted 11 lines
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.
Signature · 2 lines
Sincerely yours, Mike.
Quoted 10 lines · Michal Hocko
Quoted 6 lines · Matthew Wilcox
Quoted 2 lines · Mike Rapoport
Add a paragraph that explains that it may happen that the counters in
/proc/meminfodo 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...)
Quoted 6 lines · Alexey Dobriyan
Quoted 5 lines · Michal Hocko
Quoted 4 lines · Matthew Wilcox
Quoted 2 lines · Mike Rapoport
Add a paragraph that explains that it may happen that the counters in
/proc/meminfodo not add up to the overall memory usage.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
... 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_balloondereserve special mention?
Yes
Quoted 3 lines
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!
Signature · 2 lines
Michal Hocko SUSE Labs