larger kernel stack (8k->16k) per task (fwd)
Modified the patch to fix smpboot.c and traps.c vmlinux.lds and sched.h need not be fixed. The size of INIT_TASK is still 8K, so that other architectures using 8K stacks are not hurt.
This is a patch specific to i386. Its main use is to debug kernel code which causes an overflow of the kernel stack. It is highly recommended to use the existing stack size of 8KB, increasing the stack size to 16KB with an 200 processes running on an average causes 1.5MB of extra memory to be used.
I have tested this patch on my desktop to my satisfaction. I do not think that this affects an SMP system. Testing on an SMP box and reporting Bugs and/or success of the patch would be highly appreciated.
The patch is included as an attachment along with this email.
Quoted 43 lines
Hi Balbir,
Quoted 2 lines · Balbir Singh
2. I think you missed
getuser.Sinarch/i386/kernel/lib. All the__get_user_xshould change tono, I didn't miss them. If you read the patch again you will see them.
Quoted 3 lines
3. I verified that the instance of
GET_CURRENTinhw-irq.his not being used by anybody and can safely be removed.yes, I also verified and came to the same conclusion but left the change in the patch on purpose (so if anyone does start using it, it is already correct)
Quoted 13 lines
__get_user_1:movl %esp,%edx andl $~(THREAD_SIZE - 1),%edx cmpl addr_limit(%edx),%eaxI have a patch that lets the user select any stack size from 8K to 64K, it can be configured. And yes, it works on my system.
I do not have the /proc entry that u have though in my patch.
Quoted 6 lines
Would you like to merge both the patches or would you like me to do it and send out a new version.
The patch is attached along with this email. It
is againt 2.4.17The serious problem with your patch is that you missed quite a few places (e.g.
smpboot.candtraps.c). Most importantly, you missed the alignment invmlinux.ldsso I guess your machine boots by pure luck :) In the early stages (first hours of writing it) I missed that one too and was puzzled by random panics on boot...
Quoted 8 lines
Actually, the patch I sent is only part of the "complete piece", the other part being changes to kdb to work correctly with large stack. I can separate those from kdb patch that I use and send out if there was enough interest.
Regards,
Tigran
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
arch/i386/config.in +21 -1
@@ -413,6 +413,26 @@ bool ' Magic SysRq key' CONFIG_MAGIC_SYSRQ bool ' Spinlock debugging' CONFIG_DEBUG_SPINLOCK bool ' Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE -fi + choice 'Bigger Stack Size Support' \ + "off CONFIG_NOBIGSTACK \ + 16KB CONFIG_STACK_SIZE_16KB \ + 32KB CONFIG_STACK_SIZE_32KB \ + 64KB CONFIG_STACK_SIZE_64KB" off + if [ "$CONFIG_NOBIGSTACK" = "y" ]; then + define_int CONFIG_STACK_SIZE_SHIFT 1 + else + if [ "$CONFIG_STACK_SIZE_16KB" = "y" ]; then + define_int CONFIG_STACK_SIZE_SHIFT 2 + else + if [ "$CONFIG_STACK_SIZE_32KB" = "y" ]; then + define_int CONFIG_STACK_SIZE_SHIFT 3 + else + if [ "$CONFIG_STACK_SIZE_64KB" = "y" ]; then + define_int CONFIG_STACK_SIZE_SHIF 4 + fi + fi + fi + fi +fi
endmenu
arch/i386/kernel/entry.S +0 -0
@@ -45,6 +45,7 @@
#include <linux/linkage.h>
#include <asm/segment.h>
#include <asm/smp.h>
+#include <asm/current.h>
EBX = 0x00
ECX = 0x04
@@ -128,10 +129,6 @@
.long 3b,6b; \
.previous
-#define GET_CURRENT(reg) \
- movl $-8192, reg; \
- andl %esp, reg
-
ENTRY(lcall7)
pushfl # We get a different stack layout with call gates,
pushl %eax # which has to be cleaned up later..
@@ -144,7 +141,7 @@
movl %ecx,CS(%esp) # movl %esp,%ebx pushl %ebx
- andl $-8192,%ebx # GET_CURRENT
+ andl $-THREAD_SIZE,%ebx # GET_CURRENT
movl exec_domain(%ebx),%edx # Get the execution domain
movl 4(%edx),%edx # Get the lcall7 handler for the domain
pushl $0x7
@@ -165,7 +162,7 @@
movl %ecx,CS(%esp) # movl %esp,%ebx pushl %ebx
- andl $-8192,%ebx # GET_CURRENT
+ andl $-THREAD_SIZE,%ebx # GET_CURRENT
movl exec_domain(%ebx),%edx # Get the execution domain
movl 4(%edx),%edx # Get the lcall7 handler for the domain
pushl $0x27
diff -Naur linux/arch/i386/kernel/init_task.clinux-new/arch/i386/kernel/init_task.c
arch/i386/kernel/init_task.c +0 -0
@@ -14,7 +14,7 @@
/*
* Initial task structure.
*
- * We need to make sure that this is 8192-byte aligned due to the
+ * We need to make sure that this is 16384-byte aligned due to the
* way process stacks are handled. This is done by having a special
* "init_task" linker map entry..
*/
diff -Naur linux/arch/i386/kernel/smpboot.c linux-new/arch/i386/kernel/smpboot.c
arch/i386/kernel/smpboot.c +0 -0
@@ -819,7 +819,7 @@
/* So we see what's up */
printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);- stack_start.esp = (void *) (1024 + PAGE_SIZE + (char *)idle);
+ stack_start.esp = (void *)idle->thread.esp;
/* * This grunge runs the startup process for
arch/i386/kernel/traps.c +0 -0
@@ -158,7 +158,7 @@
unsigned long esp = tsk->thread.esp; /* User space on another CPU? */ - if ((esp ^ (unsigned long)tsk) & (PAGE_MASK<<1)) + if ((esp ^ (unsigned long)tsk) & ~(THREAD_SIZE - 1)) return; show_trace((unsigned long *)esp); }
arch/i386/lib/getuser.S +4 -0
@@ -21,6 +21,10 @@ * as they get called from within inline assembly. */ +/* Duplicated from asm/processor.h */ +#include <asm/current.h> +#include <linux/config.h> +
addr_limit = 12
.text
@@ -28,7 +32,7 @@
.globl __get_user_1__get_user_1:
movl %esp,%edx
- andl $0xffffe000,%edx
+ andl $~(THREAD_SIZE - 1),%edx
cmpl addr_limit(%edx),%eax
jae bad_get_user
1: movzbl (%eax),%edx
@@ -41,7 +45,7 @@
addl $1,%eax movl %esp,%edx jc bad_get_user
- andl $0xffffe000,%edx
+ andl $~(THREAD_SIZE - 1),%edx
cmpl addr_limit(%edx),%eax
jae bad_get_user
2: movzwl -1(%eax),%edx
@@ -54,7 +58,7 @@
addl $3,%eax movl %esp,%edx jc bad_get_user
- andl $0xffffe000,%edx
+ andl $~(THREAD_SIZE - 1),%edx
cmpl addr_limit(%edx),%eax
jae bad_get_user
3: movl -3(%eax),%edx
diff -Naur linux/include/asm-i386/current.hlinux-new/include/asm-i386/current.h
include/asm-i386/current.h +0 -0
@@ -1,15 +1,44 @@
#ifndef _I386_CURRENT_H
#define _I386_CURRENT_H
+#include <asm/page.h>
+
+/*
+ * Configurable page sizes on i386, mainly for debugging purposes.
+ * (c) Balbir Singh
+ */
+
+#ifdef __ASSEMBLY__
+
+#define PAGE_SIZE 4096 /* as cannot handle 1UL << 12 */
+#define THREAD_SIZE ((1 << CONFIG_STACK_SIZE_SHIFT) * PAGE_SIZE) +
+#else /* __ASSEMBLY__ */
+
+#define THREAD_SIZE ((1 << CONFIG_STACK_SIZE_SHIFT) * PAGE_SIZE) +#define alloc_task_struct() \
+ ((struct task_struct *) __get_free_pages(GFP_KERNEL,CONFIG_STACK_SIZE_SHIFT))
+
+#define free_task_struct(p) \
+ free_pages((unsigned long) (p), CONFIG_STACK_SIZE_SHIFT) +
struct task_struct;
static inline struct task_struct * get_current(void)
{
struct task_struct *current;
- __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
+ __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~(THREAD_SIZE - 1)));
return current;- }
-
+}
+
#define current get_current()
+#endif /* __ASSEMBLY__ */
+
+#define GET_CURRENT(reg) \
+ movl $-THREAD_SIZE, (reg); \
+ andl %esp, (reg)
+
+
#endif /* !(_I386_CURRENT_H) */
+#define THREAD_SIZE ((1 << CONFIG_STACK_SIZE_SHIFT) * PAGE_SIZE) diff -Naur linux/include/asm-i386/hw_irq.h linux-new/include/asm-i386/hw_irq.h
include/asm-i386/hw_irq.h +0 -0
@@ -15,6 +15,7 @@
#include <linux/config.h>
#include <asm/atomic.h>
#include <asm/irq.h>
+#include <asm/current.h>
/*
* IDT vectors usable for external interrupt sources start
@@ -113,10 +114,6 @@
#define IRQ_NAME2(nr) nr##_interrupt(void)
#define IRQ_NAME(nr) IRQ_NAME2(IRQ##nr)
-#define GET_CURRENT \
- "movl %esp, %ebx\n\t" \
- "andl $-8192, %ebx\n\t"
-
/*
* SMP has a few special interrupts for IPI messages
*/
diff -Naur linux/include/asm-i386/processor.hlinux-new/include/asm-i386/processor.h
include/asm-i386/processor.h +0 -0
@@ -14,6 +14,7 @@
#include <asm/types.h>
#include <asm/sigcontext.h>
#include <asm/cpufeature.h>
+#include <asm/current.h>
#include <linux/cache.h>
#include <linux/config.h>
#include <linux/threads.h>
@@ -447,9 +448,6 @@
#define KSTK_EIP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1019])
#define KSTK_ESP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1022])
-#define THREAD_SIZE (2*PAGE_SIZE)
-#define alloc_task_struct() ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
-#define free_task_struct(p) free_pages((unsigned long) (p), 1)
#define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
#define init_task (init_task_union.task)
Quoted 4 lines · Balbir Singh
It is highly recommended to use the existing stack size of 8KB, increasing the stack size to 16KB with an 200 processes running on an average causes 1.5MB of extra memory to be used.
This sounds small compared to the costs of struct page. Of course, I would be concerned regardless if this patch were for anything but debugging.
Excellent work!
Cheers,
Bill