Commit cc57165874e938ef684d71ba7d36e7088b551489
Committed by
Linus Torvalds
1 parent
8240941157
Exists in
master
and in
7 other branches
[PATCH] kdump: dynamic per cpu allocation of memory for saving cpu registers
- In case of system crash, current state of cpu registers is saved in memory in elf note format. So far memory for storing elf notes was being allocated statically for NR_CPUS. - This patch introduces dynamic allocation of memory for storing elf notes. It uses alloc_percpu() interface. This should lead to better memory usage. - Introduced based on Andi Kleen's and Eric W. Biederman's suggestions. - This patch also moves memory allocation for elf notes from architecture dependent portion to architecture independent portion. Now crash_notes is architecture independent. The whole idea is that size of memory to be allocated per cpu (MAX_NOTE_BYTES) can be architecture dependent and allocation of this memory can be architecture independent. Signed-off-by: Vivek Goyal <vgoyal@in.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Showing 10 changed files with 21 additions and 24 deletions Side-by-side Diff
arch/i386/kernel/crash.c
... | ... | @@ -25,7 +25,6 @@ |
25 | 25 | #include <mach_ipi.h> |
26 | 26 | |
27 | 27 | |
28 | -note_buf_t crash_notes[NR_CPUS]; | |
29 | 28 | /* This keeps a track of which one is crashing cpu. */ |
30 | 29 | static int crashing_cpu; |
31 | 30 | |
... | ... | @@ -72,7 +71,9 @@ |
72 | 71 | * squirrelled away. ELF notes happen to provide |
73 | 72 | * all of that that no need to invent something new. |
74 | 73 | */ |
75 | - buf = &crash_notes[cpu][0]; | |
74 | + buf = (u32*)per_cpu_ptr(crash_notes, cpu); | |
75 | + if (!buf) | |
76 | + return; | |
76 | 77 | memset(&prstatus, 0, sizeof(prstatus)); |
77 | 78 | prstatus.pr_pid = current->pid; |
78 | 79 | elf_core_copy_regs(&prstatus.pr_reg, regs); |
arch/ppc/kernel/machine_kexec.c
... | ... | @@ -28,12 +28,6 @@ |
28 | 28 | const extern unsigned char relocate_new_kernel[]; |
29 | 29 | const extern unsigned int relocate_new_kernel_size; |
30 | 30 | |
31 | -/* | |
32 | - * Provide a dummy crash_notes definition while crash dump arrives to ppc. | |
33 | - * This prevents breakage of crash_notes attribute in kernel/ksysfs.c. | |
34 | - */ | |
35 | -note_buf_t crash_notes[NR_CPUS]; | |
36 | - | |
37 | 31 | void machine_shutdown(void) |
38 | 32 | { |
39 | 33 | if (ppc_md.machine_shutdown) |
arch/s390/kernel/crash.c
arch/x86_64/kernel/crash.c
include/asm-i386/kexec.h
include/asm-powerpc/kexec.h
... | ... | @@ -38,9 +38,6 @@ |
38 | 38 | #ifdef CONFIG_KEXEC |
39 | 39 | |
40 | 40 | #define MAX_NOTE_BYTES 1024 |
41 | -typedef u32 note_buf_t[MAX_NOTE_BYTES / sizeof(u32)]; | |
42 | - | |
43 | -extern note_buf_t crash_notes[]; | |
44 | 41 | |
45 | 42 | #ifdef __powerpc64__ |
46 | 43 | extern void kexec_smp_wait(void); /* get and clear naca physid, wait for |
include/asm-s390/kexec.h
include/asm-x86_64/kexec.h
include/linux/kexec.h
kernel/kexec.c
... | ... | @@ -26,6 +26,9 @@ |
26 | 26 | #include <asm/system.h> |
27 | 27 | #include <asm/semaphore.h> |
28 | 28 | |
29 | +/* Per cpu memory for storing cpu states in case of system crash. */ | |
30 | +note_buf_t* crash_notes; | |
31 | + | |
29 | 32 | /* Location of the reserved area for the crash kernel */ |
30 | 33 | struct resource crashk_res = { |
31 | 34 | .name = "Crash kernel", |
... | ... | @@ -1060,4 +1063,17 @@ |
1060 | 1063 | xchg(&kexec_lock, 0); |
1061 | 1064 | } |
1062 | 1065 | } |
1066 | + | |
1067 | +static int __init crash_notes_memory_init(void) | |
1068 | +{ | |
1069 | + /* Allocate memory for saving cpu registers. */ | |
1070 | + crash_notes = alloc_percpu(note_buf_t); | |
1071 | + if (!crash_notes) { | |
1072 | + printk("Kexec: Memory allocation for saving cpu register" | |
1073 | + " states failed\n"); | |
1074 | + return -ENOMEM; | |
1075 | + } | |
1076 | + return 0; | |
1077 | +} | |
1078 | +module_init(crash_notes_memory_init) |