提交 97105f0a 编写于 作者: R Roman Gushchin 提交者: Linus Torvalds

mm: vmalloc: show number of vmalloc pages in /proc/meminfo

Vmalloc() is getting more and more used these days (kernel stacks, bpf and
percpu allocator are new top users), and the total % of memory consumed by
vmalloc() can be pretty significant and changes dynamically.

/proc/meminfo is the best place to display this information: its top goal
is to show top consumers of the memory.

Since the VmallocUsed field in /proc/meminfo is not in use for quite a
long time (it has been defined to 0 by a5ad88ce ("mm: get rid of
'vmalloc_info' from /proc/meminfo")), let's reuse it for showing the
actual physical memory consumption of vmalloc().

Link: http://lkml.kernel.org/r/20190417194002.12369-3-guro@fb.comSigned-off-by: NRoman Gushchin <guro@fb.com>
Acked-by: NJohannes Weiner <hannes@cmpxchg.org>
Acked-by: NVlastimil Babka <vbabka@suse.cz>
Reviewed-by: NAndrew Morton <akpm@linux-foundation.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Minchan Kim <minchan@kernel.org>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 ee2ad71b
...@@ -120,7 +120,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) ...@@ -120,7 +120,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
show_val_kb(m, "Committed_AS: ", committed); show_val_kb(m, "Committed_AS: ", committed);
seq_printf(m, "VmallocTotal: %8lu kB\n", seq_printf(m, "VmallocTotal: %8lu kB\n",
(unsigned long)VMALLOC_TOTAL >> 10); (unsigned long)VMALLOC_TOTAL >> 10);
show_val_kb(m, "VmallocUsed: ", 0ul); show_val_kb(m, "VmallocUsed: ", vmalloc_nr_pages());
show_val_kb(m, "VmallocChunk: ", 0ul); show_val_kb(m, "VmallocChunk: ", 0ul);
show_val_kb(m, "Percpu: ", pcpu_nr_pages()); show_val_kb(m, "Percpu: ", pcpu_nr_pages());
......
...@@ -72,10 +72,12 @@ extern void vm_unmap_aliases(void); ...@@ -72,10 +72,12 @@ extern void vm_unmap_aliases(void);
#ifdef CONFIG_MMU #ifdef CONFIG_MMU
extern void __init vmalloc_init(void); extern void __init vmalloc_init(void);
extern unsigned long vmalloc_nr_pages(void);
#else #else
static inline void vmalloc_init(void) static inline void vmalloc_init(void)
{ {
} }
static inline unsigned long vmalloc_nr_pages(void) { return 0; }
#endif #endif
extern void *vmalloc(unsigned long size); extern void *vmalloc(unsigned long size);
......
...@@ -406,6 +406,13 @@ static void purge_vmap_area_lazy(void); ...@@ -406,6 +406,13 @@ static void purge_vmap_area_lazy(void);
static BLOCKING_NOTIFIER_HEAD(vmap_notify_list); static BLOCKING_NOTIFIER_HEAD(vmap_notify_list);
static unsigned long lazy_max_pages(void); static unsigned long lazy_max_pages(void);
static atomic_long_t nr_vmalloc_pages;
unsigned long vmalloc_nr_pages(void)
{
return atomic_long_read(&nr_vmalloc_pages);
}
static struct vmap_area *__find_vmap_area(unsigned long addr) static struct vmap_area *__find_vmap_area(unsigned long addr)
{ {
struct rb_node *n = vmap_area_root.rb_node; struct rb_node *n = vmap_area_root.rb_node;
...@@ -2237,6 +2244,7 @@ static void __vunmap(const void *addr, int deallocate_pages) ...@@ -2237,6 +2244,7 @@ static void __vunmap(const void *addr, int deallocate_pages)
BUG_ON(!page); BUG_ON(!page);
__free_pages(page, 0); __free_pages(page, 0);
} }
atomic_long_sub(area->nr_pages, &nr_vmalloc_pages);
kvfree(area->pages); kvfree(area->pages);
} }
...@@ -2414,12 +2422,14 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, ...@@ -2414,12 +2422,14 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
if (unlikely(!page)) { if (unlikely(!page)) {
/* Successfully allocated i pages, free them in __vunmap() */ /* Successfully allocated i pages, free them in __vunmap() */
area->nr_pages = i; area->nr_pages = i;
atomic_long_add(area->nr_pages, &nr_vmalloc_pages);
goto fail; goto fail;
} }
area->pages[i] = page; area->pages[i] = page;
if (gfpflags_allow_blocking(gfp_mask|highmem_mask)) if (gfpflags_allow_blocking(gfp_mask|highmem_mask))
cond_resched(); cond_resched();
} }
atomic_long_add(area->nr_pages, &nr_vmalloc_pages);
if (map_vm_area(area, prot, pages)) if (map_vm_area(area, prot, pages))
goto fail; goto fail;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册