Commit 7e8a6304 authored by Dennis Zhou (Facebook)'s avatar Dennis Zhou (Facebook) Committed by Linus Torvalds

/proc/meminfo: add percpu populated pages count

Currently, percpu memory only exposes allocation and utilization
information via debugfs.  This more or less is only really useful for
understanding the fragmentation and allocation information at a per-chunk
level with a few global counters.  This is also gated behind a config.
BPF and cgroup, for example, have seen an increase in use causing
increased use of percpu memory.  Let's make it easier for someone to
identify how much memory is being used.

This patch adds the "Percpu" stat to meminfo to more easily look up how
much percpu memory is in use.  This number includes the cost for all
allocated backing pages and not just insight at the per a unit, per chunk
level.  Metadata is excluded.  I think excluding metadata is fair because
the backing memory scales with the numbere of cpus and can quickly
outweigh the metadata.  It also makes this calculation light.

Link: http://lkml.kernel.org/r/20180807184723.74919-1-dennisszhou@gmail.comSigned-off-by: default avatarDennis Zhou <dennisszhou@gmail.com>
Acked-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarRoman Gushchin <guro@fb.com>
Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarDavid Rientjes <rientjes@google.com>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3d8b38eb
...@@ -870,6 +870,7 @@ Committed_AS: 100056 kB ...@@ -870,6 +870,7 @@ Committed_AS: 100056 kB
VmallocTotal: 112216 kB VmallocTotal: 112216 kB
VmallocUsed: 428 kB VmallocUsed: 428 kB
VmallocChunk: 111088 kB VmallocChunk: 111088 kB
Percpu: 62080 kB
HardwareCorrupted: 0 kB HardwareCorrupted: 0 kB
AnonHugePages: 49152 kB AnonHugePages: 49152 kB
ShmemHugePages: 0 kB ShmemHugePages: 0 kB
...@@ -962,6 +963,8 @@ Committed_AS: The amount of memory presently allocated on the system. ...@@ -962,6 +963,8 @@ Committed_AS: The amount of memory presently allocated on the system.
VmallocTotal: total size of vmalloc memory area VmallocTotal: total size of vmalloc memory area
VmallocUsed: amount of vmalloc area which is used VmallocUsed: amount of vmalloc area which is used
VmallocChunk: largest contiguous block of vmalloc area which is free VmallocChunk: largest contiguous block of vmalloc area which is free
Percpu: Memory allocated to the percpu allocator used to back percpu
allocations. This stat excludes the cost of metadata.
.............................................................................. ..............................................................................
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <linux/mman.h> #include <linux/mman.h>
#include <linux/mmzone.h> #include <linux/mmzone.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/percpu.h>
#include <linux/quicklist.h> #include <linux/quicklist.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/swap.h> #include <linux/swap.h>
...@@ -121,6 +122,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) ...@@ -121,6 +122,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
(unsigned long)VMALLOC_TOTAL >> 10); (unsigned long)VMALLOC_TOTAL >> 10);
show_val_kb(m, "VmallocUsed: ", 0ul); show_val_kb(m, "VmallocUsed: ", 0ul);
show_val_kb(m, "VmallocChunk: ", 0ul); show_val_kb(m, "VmallocChunk: ", 0ul);
show_val_kb(m, "Percpu: ", pcpu_nr_pages());
#ifdef CONFIG_MEMORY_FAILURE #ifdef CONFIG_MEMORY_FAILURE
seq_printf(m, "HardwareCorrupted: %5lu kB\n", seq_printf(m, "HardwareCorrupted: %5lu kB\n",
......
...@@ -149,4 +149,6 @@ extern phys_addr_t per_cpu_ptr_to_phys(void *addr); ...@@ -149,4 +149,6 @@ extern phys_addr_t per_cpu_ptr_to_phys(void *addr);
(typeof(type) __percpu *)__alloc_percpu(sizeof(type), \ (typeof(type) __percpu *)__alloc_percpu(sizeof(type), \
__alignof__(type)) __alignof__(type))
extern unsigned long pcpu_nr_pages(void);
#endif /* __LINUX_PERCPU_H */ #endif /* __LINUX_PERCPU_H */
...@@ -169,6 +169,14 @@ static LIST_HEAD(pcpu_map_extend_chunks); ...@@ -169,6 +169,14 @@ static LIST_HEAD(pcpu_map_extend_chunks);
*/ */
int pcpu_nr_empty_pop_pages; int pcpu_nr_empty_pop_pages;
/*
* The number of populated pages in use by the allocator, protected by
* pcpu_lock. This number is kept per a unit per chunk (i.e. when a page gets
* allocated/deallocated, it is allocated/deallocated in all units of a chunk
* and increments/decrements this count by 1).
*/
static unsigned long pcpu_nr_populated;
/* /*
* Balance work is used to populate or destroy chunks asynchronously. We * Balance work is used to populate or destroy chunks asynchronously. We
* try to keep the number of populated free pages between * try to keep the number of populated free pages between
...@@ -1232,6 +1240,7 @@ static void pcpu_chunk_populated(struct pcpu_chunk *chunk, int page_start, ...@@ -1232,6 +1240,7 @@ static void pcpu_chunk_populated(struct pcpu_chunk *chunk, int page_start,
bitmap_set(chunk->populated, page_start, nr); bitmap_set(chunk->populated, page_start, nr);
chunk->nr_populated += nr; chunk->nr_populated += nr;
pcpu_nr_populated += nr;
if (!for_alloc) { if (!for_alloc) {
chunk->nr_empty_pop_pages += nr; chunk->nr_empty_pop_pages += nr;
...@@ -1260,6 +1269,7 @@ static void pcpu_chunk_depopulated(struct pcpu_chunk *chunk, ...@@ -1260,6 +1269,7 @@ static void pcpu_chunk_depopulated(struct pcpu_chunk *chunk,
chunk->nr_populated -= nr; chunk->nr_populated -= nr;
chunk->nr_empty_pop_pages -= nr; chunk->nr_empty_pop_pages -= nr;
pcpu_nr_empty_pop_pages -= nr; pcpu_nr_empty_pop_pages -= nr;
pcpu_nr_populated -= nr;
} }
/* /*
...@@ -2176,6 +2186,9 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, ...@@ -2176,6 +2186,9 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
pcpu_nr_empty_pop_pages = pcpu_first_chunk->nr_empty_pop_pages; pcpu_nr_empty_pop_pages = pcpu_first_chunk->nr_empty_pop_pages;
pcpu_chunk_relocate(pcpu_first_chunk, -1); pcpu_chunk_relocate(pcpu_first_chunk, -1);
/* include all regions of the first chunk */
pcpu_nr_populated += PFN_DOWN(size_sum);
pcpu_stats_chunk_alloc(); pcpu_stats_chunk_alloc();
trace_percpu_create_chunk(base_addr); trace_percpu_create_chunk(base_addr);
...@@ -2745,6 +2758,22 @@ void __init setup_per_cpu_areas(void) ...@@ -2745,6 +2758,22 @@ void __init setup_per_cpu_areas(void)
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
/*
* pcpu_nr_pages - calculate total number of populated backing pages
*
* This reflects the number of pages populated to back chunks. Metadata is
* excluded in the number exposed in meminfo as the number of backing pages
* scales with the number of cpus and can quickly outweigh the memory used for
* metadata. It also keeps this calculation nice and simple.
*
* RETURNS:
* Total number of populated backing pages in use by the allocator.
*/
unsigned long pcpu_nr_pages(void)
{
return pcpu_nr_populated * pcpu_nr_units;
}
/* /*
* Percpu allocator is initialized early during boot when neither slab or * Percpu allocator is initialized early during boot when neither slab or
* workqueue is available. Plug async management until everything is up * workqueue is available. Plug async management until everything is up
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment