Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Nov 2007 18:38:15 +0200
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Alexander Motin <mav@freebsd.org>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: Kernel thread stack usage
Message-ID:  <20071111163815.GJ37471@deviant.kiev.zoral.com.ua>
In-Reply-To: <4736D8AF.7010209@FreeBSD.org>
References:  <1191187393.00807485.1191175801@10.7.7.3> <1191189248.00807488.1191177603@10.7.7.3> <4736D8AF.7010209@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--8O4mmsqCUhOCyWJp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Nov 11, 2007 at 12:25:51PM +0200, Alexander Motin wrote:
> >As known in netgraph susbystem information passing from one node to
> >another by direct function calls without queueing. It gives performance
> >bonuses, but it also gives permanent stack overflow risk on complicated
> >graphs. Netgraph is still have a queues and able to use them when asked,
> >but now queueing is a flag which should be controlled by sending node. I
> >think it would be good to implement some algorithm which could monitor
> >stack usage on each call and enforce queueing when stack usage become
> >critical.
> >
> >The question is: is there correct way to somehow get current kernel
> >thread stack usage or just a stack base address?
>=20
> Digging kernel with a dirty hands I have found the way which looks like=
=20
> working. I have briefly tested it on i386.
>=20
> printf("%p, %p. Used %d of %d.\n", &var,
>   (char *)td->td_kstack + td->td_kstack_pages * PAGE_SIZE,
>   (char *)td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
>     (char *)&var,
>   td->td_kstack_pages * PAGE_SIZE);
>=20
> 'var' here is a name of some local variable.
>=20
> Can anybody comment correctness of this way or propose another one?

Most of the time, you will get the correct value. But, see the
vm_thread_new_altstack() in vm/vm_glue.c.

--8O4mmsqCUhOCyWJp
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFHNy/2C3+MBN1Mb4gRAuh/AJ9MS/VAWnbhZ9Ne63x4ZNe++AWeUgCfcVM+
WYGlKQXjxdPUfRhLxADZqN0=
=I7+7
-----END PGP SIGNATURE-----

--8O4mmsqCUhOCyWJp--



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