check_nmi_watchdog() excessive stack usage
PATCH 1/1 check_nmi_watchdog() excessive stack usage
Marcelo,
This patch fixes a problem with excessive stack usage in arch/i386/kernel/nmi.c:check_nmi_watchdog(). It's a backport of a fix that has been in the 2.5 kernel for quite a while. There are no behavioural changes.
The problem is that the code copies NR_CPUS irq_cpustat_t values to the stack, even though only NR_CPUS ints actually are needed. irq_cpustat_t values are 24 bytes large, but they are also ____cacheline_aligned, which makes them blow up to 128 bytes on P4s. That's 128*32 == 4 kilobytes of stack on a P4 SMP kernel, when 4*32 == 128 bytes suffices.
/Mikael
arch/i386/kernel/nmi.c +6 -3
@@ -72,18 +72,21 @@int __init check_nmi_watchdog (void ) { -irq_cpustat_t tmp[NR_CPUS ]; +unsigned int prev_nmi_count[NR_CPUS ];int j, cpu;printk (KERN_INFO "testing NMI watchdog ... " ); -memcpy (tmp, irq_stat,sizeof (tmp)); +for (j =0 ; j < smp_num_cpus; j++) { + cpu =cpu_logical_map (j); + prev_nmi_count[cpu] = irq_stat[cpu].__nmi_count; + }sti ();mdelay ((10 *1000 )/nmi_hz);// wait 10 ticks for (j =0 ; j < smp_num_cpus; j++) { cpu =cpu_logical_map (j); -if (nmi_count (cpu) - tmp[cpu].__nmi_count <=5 ) { +if (nmi_count (cpu) - prev_nmi_count[cpu] <=5 ) {printk ("CPU#%d: NMI appears to be stuck!\n" , cpu);return -1 ; }