x86: implement percpu_alloc kernel parameter

According to Andi, it isn't clear whether lpage allocator is worth the
trouble as there are many processors where PMD TLB is far scarcer than
PTE TLB.  The advantage or disadvantage probably depends on the actual
size of percpu area and specific processor.  As performance
degradation due to TLB pressure tends to be highly workload specific
and subtle, it is difficult to decide which way to go without more
data.

This patch implements percpu_alloc kernel parameter to allow selecting
which first chunk allocator to use to ease debugging and testing.

While at it, make sure all the failure paths report why something
failed to help determining why certain allocator isn't working.  Also,
kill the "Great future plan" comment which had already been realized
quite some time ago.

[ Impact: allow explicit percpu first chunk allocator selection ]

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Jan Beulich <JBeulich@novell.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
Tejun Heo 2009-06-22 11:56:24 +09:00
parent e59a1bb2fd
commit fa8a7094ba
3 changed files with 65 additions and 23 deletions

View file

@ -1882,6 +1882,12 @@ and is between 256 and 4096 characters. It is defined in the file
Format: { 0 | 1 } Format: { 0 | 1 }
See arch/parisc/kernel/pdc_chassis.c See arch/parisc/kernel/pdc_chassis.c
percpu_alloc= [X86] Select which percpu first chunk allocator to use.
Allowed values are one of "lpage", "embed" and "4k".
See comments in arch/x86/kernel/setup_percpu.c for
details on each allocator. This parameter is primarily
for debugging and performance comparison.
pf. [PARIDE] pf. [PARIDE]
See Documentation/blockdev/paride.txt. See Documentation/blockdev/paride.txt.

View file

@ -156,20 +156,23 @@ static struct page * __init pcpul_get_page(unsigned int cpu, int pageno)
return virt_to_page(pcpul_map[cpu].ptr + off); return virt_to_page(pcpul_map[cpu].ptr + off);
} }
static ssize_t __init setup_pcpu_lpage(size_t static_size) static ssize_t __init setup_pcpu_lpage(size_t static_size, bool chosen)
{ {
size_t map_size, dyn_size; size_t map_size, dyn_size;
unsigned int cpu; unsigned int cpu;
int i, j; int i, j;
ssize_t ret; ssize_t ret;
/* /* on non-NUMA, embedding is better */
* If large page isn't supported, there's no benefit in doing if (!chosen && !pcpu_need_numa())
* this. Also, on non-NUMA, embedding is better.
*/
if (!cpu_has_pse || !pcpu_need_numa())
return -EINVAL; return -EINVAL;
/* need PSE */
if (!cpu_has_pse) {
pr_warning("PERCPU: lpage allocator requires PSE\n");
return -EINVAL;
}
/* /*
* Currently supports only single page. Supporting multiple * Currently supports only single page. Supporting multiple
* pages won't be too difficult if it ever becomes necessary. * pages won't be too difficult if it ever becomes necessary.
@ -191,8 +194,11 @@ static ssize_t __init setup_pcpu_lpage(size_t static_size)
pcpul_map[cpu].cpu = cpu; pcpul_map[cpu].cpu = cpu;
pcpul_map[cpu].ptr = pcpu_alloc_bootmem(cpu, PMD_SIZE, pcpul_map[cpu].ptr = pcpu_alloc_bootmem(cpu, PMD_SIZE,
PMD_SIZE); PMD_SIZE);
if (!pcpul_map[cpu].ptr) if (!pcpul_map[cpu].ptr) {
pr_warning("PERCPU: failed to allocate large page "
"for cpu%u\n", cpu);
goto enomem; goto enomem;
}
/* /*
* Only use pcpul_size bytes and give back the rest. * Only use pcpul_size bytes and give back the rest.
@ -297,7 +303,7 @@ void *pcpu_lpage_remapped(void *kaddr)
return NULL; return NULL;
} }
#else #else
static ssize_t __init setup_pcpu_lpage(size_t static_size) static ssize_t __init setup_pcpu_lpage(size_t static_size, bool chosen)
{ {
return -EINVAL; return -EINVAL;
} }
@ -311,7 +317,7 @@ static ssize_t __init setup_pcpu_lpage(size_t static_size)
* mapping so that it can use PMD mapping without additional TLB * mapping so that it can use PMD mapping without additional TLB
* pressure. * pressure.
*/ */
static ssize_t __init setup_pcpu_embed(size_t static_size) static ssize_t __init setup_pcpu_embed(size_t static_size, bool chosen)
{ {
size_t reserve = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE; size_t reserve = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE;
@ -320,7 +326,7 @@ static ssize_t __init setup_pcpu_embed(size_t static_size)
* this. Also, embedding allocation doesn't play well with * this. Also, embedding allocation doesn't play well with
* NUMA. * NUMA.
*/ */
if (!cpu_has_pse || pcpu_need_numa()) if (!chosen && (!cpu_has_pse || pcpu_need_numa()))
return -EINVAL; return -EINVAL;
return pcpu_embed_first_chunk(static_size, PERCPU_FIRST_CHUNK_RESERVE, return pcpu_embed_first_chunk(static_size, PERCPU_FIRST_CHUNK_RESERVE,
@ -370,8 +376,11 @@ static ssize_t __init setup_pcpu_4k(size_t static_size)
void *ptr; void *ptr;
ptr = pcpu_alloc_bootmem(cpu, PAGE_SIZE, PAGE_SIZE); ptr = pcpu_alloc_bootmem(cpu, PAGE_SIZE, PAGE_SIZE);
if (!ptr) if (!ptr) {
pr_warning("PERCPU: failed to allocate "
"4k page for cpu%u\n", cpu);
goto enomem; goto enomem;
}
memcpy(ptr, __per_cpu_load + i * PAGE_SIZE, PAGE_SIZE); memcpy(ptr, __per_cpu_load + i * PAGE_SIZE, PAGE_SIZE);
pcpu4k_pages[j++] = virt_to_page(ptr); pcpu4k_pages[j++] = virt_to_page(ptr);
@ -395,6 +404,16 @@ static ssize_t __init setup_pcpu_4k(size_t static_size)
return ret; return ret;
} }
/* for explicit first chunk allocator selection */
static char pcpu_chosen_alloc[16] __initdata;
static int __init percpu_alloc_setup(char *str)
{
strncpy(pcpu_chosen_alloc, str, sizeof(pcpu_chosen_alloc) - 1);
return 0;
}
early_param("percpu_alloc", percpu_alloc_setup);
static inline void setup_percpu_segment(int cpu) static inline void setup_percpu_segment(int cpu)
{ {
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
@ -408,11 +427,6 @@ static inline void setup_percpu_segment(int cpu)
#endif #endif
} }
/*
* Great future plan:
* Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
* Always point %gs to its beginning
*/
void __init setup_per_cpu_areas(void) void __init setup_per_cpu_areas(void)
{ {
size_t static_size = __per_cpu_end - __per_cpu_start; size_t static_size = __per_cpu_end - __per_cpu_start;
@ -429,9 +443,26 @@ void __init setup_per_cpu_areas(void)
* of large page mappings. Please read comments on top of * of large page mappings. Please read comments on top of
* each allocator for details. * each allocator for details.
*/ */
ret = setup_pcpu_lpage(static_size); ret = -EINVAL;
if (ret < 0) if (strlen(pcpu_chosen_alloc)) {
ret = setup_pcpu_embed(static_size); if (strcmp(pcpu_chosen_alloc, "4k")) {
if (!strcmp(pcpu_chosen_alloc, "lpage"))
ret = setup_pcpu_lpage(static_size, true);
else if (!strcmp(pcpu_chosen_alloc, "embed"))
ret = setup_pcpu_embed(static_size, true);
else
pr_warning("PERCPU: unknown allocator %s "
"specified\n", pcpu_chosen_alloc);
if (ret < 0)
pr_warning("PERCPU: %s allocator failed (%zd), "
"falling back to 4k\n",
pcpu_chosen_alloc, ret);
}
} else {
ret = setup_pcpu_lpage(static_size, false);
if (ret < 0)
ret = setup_pcpu_embed(static_size, false);
}
if (ret < 0) if (ret < 0)
ret = setup_pcpu_4k(static_size); ret = setup_pcpu_4k(static_size);
if (ret < 0) if (ret < 0)

View file

@ -1233,6 +1233,7 @@ static struct page * __init pcpue_get_page(unsigned int cpu, int pageno)
ssize_t __init pcpu_embed_first_chunk(size_t static_size, size_t reserved_size, ssize_t __init pcpu_embed_first_chunk(size_t static_size, size_t reserved_size,
ssize_t dyn_size, ssize_t unit_size) ssize_t dyn_size, ssize_t unit_size)
{ {
size_t chunk_size;
unsigned int cpu; unsigned int cpu;
/* determine parameters and allocate */ /* determine parameters and allocate */
@ -1247,11 +1248,15 @@ ssize_t __init pcpu_embed_first_chunk(size_t static_size, size_t reserved_size,
} else } else
pcpue_unit_size = max_t(size_t, pcpue_size, PCPU_MIN_UNIT_SIZE); pcpue_unit_size = max_t(size_t, pcpue_size, PCPU_MIN_UNIT_SIZE);
pcpue_ptr = __alloc_bootmem_nopanic( chunk_size = pcpue_unit_size * num_possible_cpus();
num_possible_cpus() * pcpue_unit_size,
PAGE_SIZE, __pa(MAX_DMA_ADDRESS)); pcpue_ptr = __alloc_bootmem_nopanic(chunk_size, PAGE_SIZE,
if (!pcpue_ptr) __pa(MAX_DMA_ADDRESS));
if (!pcpue_ptr) {
pr_warning("PERCPU: failed to allocate %zu bytes for "
"embedding\n", chunk_size);
return -ENOMEM; return -ENOMEM;
}
/* return the leftover and copy */ /* return the leftover and copy */
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {