提交 4797417e 编写于 作者: J Joerg Roedel 提交者: Joseph Qi

x86/mm: Split vmalloc_sync_all()

commit 1a0a610d5f056c6195ae9808962477a94d1d72c8 upstream.

Commit 3f8fd02b1bf1 ("mm/vmalloc: Sync unmappings in
__purge_vmap_area_lazy()") introduced a call to vmalloc_sync_all() in the
vunmap() code-path.  While this change was necessary to maintain
correctness on x86-32-pae kernels, it also adds additional cycles for
architectures that don't need it.

Specifically on x86-64 with CONFIG_VMAP_STACK=y some people reported
severe performance regressions in micro-benchmarks because it now also
calls the x86-64 implementation of vmalloc_sync_all() on vunmap().  But
the vmalloc_sync_all() implementation on x86-64 is only needed for newly
created mappings.

To avoid the unnecessary work on x86-64 and to gain the performance back,
split up vmalloc_sync_all() into two functions:

	* vmalloc_sync_mappings(), and
	* vmalloc_sync_unmappings()

Most call-sites to vmalloc_sync_all() only care about new mappings being
synchronized.  The only exception is the new call-site added in the above
mentioned commit.

Shile Zhang directed us to a report of an 80% regression in reaim
throughput.

Link: http://lkml.kernel.org/r/20191009124418.8286-1-joro@8bytes.org
Link: https://lists.01.org/hyperkitty/list/lkp@lists.01.org/thread/4D3JPPHBNOSPFK2KEPC6KGKS6J25AIDB/
Link: http://lkml.kernel.org/r/20191113095530.228959-1-shile.zhang@linux.alibaba.com
Fixes: 3f8fd02b1bf1 ("mm/vmalloc: Sync unmappings in __purge_vmap_area_lazy()")
Signed-off-by: NJoerg Roedel <jroedel@suse.de>
Reported-by: Nkernel test robot <oliver.sang@intel.com>
Reported-by: NShile Zhang <shile.zhang@linux.alibaba.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>	[GHES]
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NStephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: NShile Zhang <shile.zhang@linux.alibaba.com>
Acked-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
上级 00dfef9f
...@@ -273,7 +273,7 @@ static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address) ...@@ -273,7 +273,7 @@ static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
return pmd_k; return pmd_k;
} }
void vmalloc_sync_all(void) static void vmalloc_sync(void)
{ {
unsigned long address; unsigned long address;
...@@ -300,6 +300,16 @@ void vmalloc_sync_all(void) ...@@ -300,6 +300,16 @@ void vmalloc_sync_all(void)
} }
} }
void vmalloc_sync_mappings(void)
{
vmalloc_sync();
}
void vmalloc_sync_unmappings(void)
{
vmalloc_sync();
}
/* /*
* 32-bit: * 32-bit:
* *
...@@ -402,11 +412,23 @@ static void dump_pagetable(unsigned long address) ...@@ -402,11 +412,23 @@ static void dump_pagetable(unsigned long address)
#else /* CONFIG_X86_64: */ #else /* CONFIG_X86_64: */
void vmalloc_sync_all(void) void vmalloc_sync_mappings(void)
{ {
/*
* 64-bit mappings might allocate new p4d/pud pages
* that need to be propagated to all tasks' PGDs.
*/
sync_global_pgds(VMALLOC_START & PGDIR_MASK, VMALLOC_END); sync_global_pgds(VMALLOC_START & PGDIR_MASK, VMALLOC_END);
} }
void vmalloc_sync_unmappings(void)
{
/*
* Unmappings never allocate or free p4d/pud pages.
* No work is required here.
*/
}
/* /*
* 64-bit: * 64-bit:
* *
......
...@@ -201,7 +201,7 @@ static int ghes_estatus_pool_expand(unsigned long len) ...@@ -201,7 +201,7 @@ static int ghes_estatus_pool_expand(unsigned long len)
* New allocation must be visible in all pgd before it can be found by * New allocation must be visible in all pgd before it can be found by
* an NMI allocating from the pool. * an NMI allocating from the pool.
*/ */
vmalloc_sync_all(); vmalloc_sync_mappings();
return gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1); return gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
} }
......
...@@ -107,8 +107,9 @@ extern int remap_vmalloc_range_partial(struct vm_area_struct *vma, ...@@ -107,8 +107,9 @@ extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
extern int remap_vmalloc_range(struct vm_area_struct *vma, void *addr, extern int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
unsigned long pgoff); unsigned long pgoff);
void vmalloc_sync_all(void); void vmalloc_sync_mappings(void);
void vmalloc_sync_unmappings(void);
/* /*
* Lowlevel-APIs (not for driver use!) * Lowlevel-APIs (not for driver use!)
*/ */
......
...@@ -552,7 +552,7 @@ NOKPROBE_SYMBOL(notify_die); ...@@ -552,7 +552,7 @@ NOKPROBE_SYMBOL(notify_die);
int register_die_notifier(struct notifier_block *nb) int register_die_notifier(struct notifier_block *nb)
{ {
vmalloc_sync_all(); vmalloc_sync_mappings();
return atomic_notifier_chain_register(&die_chain, nb); return atomic_notifier_chain_register(&die_chain, nb);
} }
EXPORT_SYMBOL_GPL(register_die_notifier); EXPORT_SYMBOL_GPL(register_die_notifier);
......
...@@ -446,10 +446,14 @@ void vm_unmap_aliases(void) ...@@ -446,10 +446,14 @@ void vm_unmap_aliases(void)
EXPORT_SYMBOL_GPL(vm_unmap_aliases); EXPORT_SYMBOL_GPL(vm_unmap_aliases);
/* /*
* Implement a stub for vmalloc_sync_all() if the architecture chose not to * Implement a stub for vmalloc_sync_[un]mapping() if the architecture
* have one. * chose not to have one.
*/ */
void __weak vmalloc_sync_all(void) void __weak vmalloc_sync_mappings(void)
{
}
void __weak vmalloc_sync_unmappings(void)
{ {
} }
......
...@@ -1755,7 +1755,7 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, ...@@ -1755,7 +1755,7 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
* First make sure the mappings are removed from all page-tables * First make sure the mappings are removed from all page-tables
* before they are freed. * before they are freed.
*/ */
vmalloc_sync_all(); vmalloc_sync_unmappings();
/* /*
* In this function, newly allocated vm_struct has VM_UNINITIALIZED * In this function, newly allocated vm_struct has VM_UNINITIALIZED
...@@ -2300,16 +2300,19 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr, ...@@ -2300,16 +2300,19 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
EXPORT_SYMBOL(remap_vmalloc_range); EXPORT_SYMBOL(remap_vmalloc_range);
/* /*
* Implement a stub for vmalloc_sync_all() if the architecture chose not to * Implement stubs for vmalloc_sync_[un]mappings () if the architecture chose
* have one. * not to have one.
* *
* The purpose of this function is to make sure the vmalloc area * The purpose of this function is to make sure the vmalloc area
* mappings are identical in all page-tables in the system. * mappings are identical in all page-tables in the system.
*/ */
void __weak vmalloc_sync_all(void) void __weak vmalloc_sync_mappings(void)
{ {
} }
void __weak vmalloc_sync_unmappings(void)
{
}
static int f(pte_t *pte, pgtable_t table, unsigned long addr, void *data) static int f(pte_t *pte, pgtable_t table, unsigned long addr, void *data)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册