Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Sep 2001 04:35:25 -0700
From:      Julian Elischer <julian@elischer.org>
To:        Peter Wemm <peter@wemm.org>
Cc:        Matt Dillon <dillon@earth.backplane.com>, Ian Dowse <iedowse@maths.tcd.ie>, hackers@FreeBSD.ORG
Subject:   Re: Patch to test kstack usage.
Message-ID:  <3BB06BFD.F1870676@elischer.org>
References:  <20010925051923.6CA2F3808@overcee.netplex.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
Peter Wemm wrote:
> 
> Matt Dillon wrote:
> >     This isn't perfect but it should be a good start in regards to
> >     testing kstack use.  This patch is against -stable.  It reports
> >     kernel stack use on process exit and will generate a 'Kernel stack
> >     underflow' message if it detects an underflow.  It doesn't panic,
> >     so for a fun time you can leave UPAGES at 2 and watch in horror.
> 
> It is checking against the wrong guard value. It should be u_guard2.
> 
> FWIW; the max stack available is 4688 bytes on a standard 4.x system. Yes,
> that is too freaking close.  Also, the maximum usage depends on what sort
> of cards you have in the system.. If you have a heavy tty user (eg: a 32+
> port serial card) then you have lots of tty interrupts nesting as well.
> Having the ppp/sl/plip drivers in the system partly negates the effect of
> this though since it wires the net/tty interrupt masks together.

usb devices allocate 2K on the stack so if you have them too.......
so does openning an atapi cdrom...
so a combination of interrupts and those, might consume 4K


> 
> peter@thunder[10:13pm]~-111> ./tu
> stack base = 3504
> stack size = 4688
> peter@thunder[10:13pm]~-112> cat tu.c
> #include <sys/param.h>
> #include <sys/user.h>
> #include <stdio.h>
> #include <stddef.h>
> 
> int
> main(int ac, char **av)
> {
>         int stack_base = offsetof(struct user, u_kproc);
> 
>         printf("stack base = %d\n", stack_base);
>         printf("stack size = %d\n", UPAGES * PAGE_SIZE - stack_base);
> }
> 
> > --- sys/user.h        1999/12/29 04:24:49     1.24
> > +++ sys/user.h        2001/09/25 03:41:04
> > @@ -109,9 +109,13 @@
> >        * Remaining fields only for core dump and/or ptrace--
> >        * not valid at other times!
> >        */
> > +     u_int32_t u_guard2;             /* guard the base of the kstack */
> >       struct  kinfo_proc u_kproc;     /* proc + eproc */
> >       struct  md_coredump u_md;       /* machine dependent glop */
> > +     u_int32_t u_guard;              /* guard the base of the kstack */
> >  };
> 
> Cheers,
> -Peter
> --
> Peter Wemm - peter@FreeBSD.org; peter@yahoo-inc.com; peter@netplex.com.au
> "All of this is for nothing if we don't go to the stars" - JMS/B5

-- 
+------------------------------------+       ______ _  __
|   __--_|\  Julian Elischer         |       \     U \/ / hard at work in 
|  /       \ julian@elischer.org     +------>x   USA    \ a very strange
| (   OZ    )                                \___   ___ | country !
+- X_.---._/    presently in San Francisco       \_/   \\
          v

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3BB06BFD.F1870676>