UML - Monitor stack usage
PATCH 5/6 UML - Monitor stack usage
In preparation for reducing stack size, add a machanism to see how much of a kernel stack is used. This fills a new stack with 0x6b on allocation and sees where the lowest non-0x6b byte is on process exit. It keeps track of the lowest value and logs values as they get lower.
The lowest values I've seen so far are ~1250 bytes remaining on i386 (with order 0 stacks) and ~2650 on x86_64 (order 1).
--
arch/um/Kconfig.debug | 8 ++++++++ arch/um/defconfig | 1 + arch/um/kernel/process.c | 35 +++++++++++++++++++++++++++++++++++ include/asm-um/thread_info.h | 16 ++++++++++++++++ 4 files changed, 60 insertions(+)
arch/um/Kconfig.debug +8 -0
@@ -47,4 +47,12 @@ config GCOV If you're involved in UML kernel development and want to use gcov, say Y. If you're unsure, say N. +config STACK_USAGE + bool "Track kernel stack usage" + default N + help + Track the maximum kernel stack usage - this will look at each + kernel stack at process exit and log it if it's the deepest + stack seen so far. + endmenu
arch/um/kernel/process.c +35 -0
@@ -427,3 +427,38 @@ unsigned long arch_align_stack(unsignedreturn sp & ~0xf ; }#endif + +#ifdef CONFIG_STACK_USAGE + +static int lowest_to_date =THREAD_SIZE ; + +void mark_stack (struct thread_info *stack) +{ +if (stack ==NULL ) +return ; + +memset (stack,0x6b ,THREAD_SIZE ); +} + +void check_stack_usage (struct thread_info *s) +{ +unsigned int *stack; +unsigned int *p, *end; +int left; + + stack = (unsigned int *) (s +1 ); + end = (unsigned int *) ((unsigned long ) stack +THREAD_SIZE ); +for (p = stack; p < end; p++){ +if (*p !=0x6b6b6b6b ){ + left = (p - stack); +if (left < lowest_to_date){ +printk ("Greatest stack depth - %d bytes left\n" , + left *sizeof (*p)); + lowest_to_date = left; + } +return ; + } + } +} + +#endif
include/asm-um/thread_info.h +16 -0
@@ -52,6 +52,20 @@ static inline struct thread_info *currenreturn ti; } +#ifdef CONFIG_STACK_USAGE + +extern void mark_stack (struct thread_info *stack); +extern void check_stack_usage (struct thread_info *stack); + +#define alloc_thread_info (tsk) \ + ({ struct thread_info *stack = kmalloc(THREAD_SIZE, GFP_KERNEL); \ + mark_stack(stack); \ + stack; \ + }) +#define free_thread_info (ti) ({ check_stack_usage(ti) ; kfree(ti); }) + +#else +/* thread information allocation */ #define alloc_thread_info (tsk) \ ((struct thread_info *) kmalloc(THREAD_SIZE, GFP_KERNEL))
@@ -59,6 +73,8 @@ static inline struct thread_info *curren#endif +#endif +#define PREEMPT_ACTIVE 0x10000000#define TIF_SYSCALL_TRACE 0/* syscall trace active */
arch/um/defconfig +1 -0
@@ -527,3 +527,4 @@ CONFIG_FORCED_INLINING=y # CONFIG_RCU_TORTURE_TEST is not set # CONFIG_GPROF is not set # CONFIG_GCOV is not set +# CONFIG_STACK_USAGE is not set
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 5 lines · On Wed, 9 May 2007 16:27:22 -0400 Jeff Dike <[email protected]> wrote:
In preparation for reducing stack size, add a machanism to see how much of a kernel stack is used. This fills a new stack with
0x6bon allocation and sees where the lowest non-0x6b byte is on process exit. It keeps track of the lowest value and logs values as they get lower.
but, but. We already have CONFIG_DEBUG_STACK_USAGE?
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 1 line · Andrew Morton
but, but. We already have
CONFIG_DEBUG_STACK_USAGE?
Whoops, that's not exactly what I want, but it's close enough to let me throw out some code.
Drop that and I'll send a fixed version.
Jeff
Signature · 11 lines
Work email - jdike at linux dot intel dot com ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ User-mode-linux-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel