From owner-freebsd-arch@FreeBSD.ORG Sun Nov 11 17:31:21 2007 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 25EA716A475 for ; Sun, 11 Nov 2007 17:31:21 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outS.internet-mail-service.net (outS.internet-mail-service.net [216.240.47.242]) by mx1.freebsd.org (Postfix) with ESMTP id 0AAB113C4B5 for ; Sun, 11 Nov 2007 17:31:21 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Sun, 11 Nov 2007 09:31:09 -0800 X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e Received: from julian-mac.elischer.org (home.elischer.org [216.240.48.38]) by idiom.com (Postfix) with ESMTP id E7FBA1269B4; Sun, 11 Nov 2007 09:31:08 -0800 (PST) Message-ID: <47373C5E.2080800@elischer.org> Date: Sun, 11 Nov 2007 09:31:10 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: Kostik Belousov References: <1191187393.00807485.1191175801@10.7.7.3> <1191189248.00807488.1191177603@10.7.7.3> <4736D8AF.7010209@FreeBSD.org> <20071111163815.GJ37471@deviant.kiev.zoral.com.ua> In-Reply-To: <20071111163815.GJ37471@deviant.kiev.zoral.com.ua> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Alexander Motin , freebsd-arch@freebsd.org Subject: Re: Kernel thread stack usage X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Nov 2007 17:31:21 -0000 Kostik Belousov wrote: > 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? >> Digging kernel with a dirty hands I have found the way which looks like >> working. I have briefly tested it on i386. >> >> 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); >> >> 'var' here is a name of some local variable. >> >> 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. Also, and others may want to pipe in on this, it might go in machine dependent code because it is *theoretically* we could port one day to a machine with an upward growing stack. It has happened in the distant past but it has been growing less likely in the recent past. With the advent of truely HUGE address spaces, it becomes feasible again. (which of course doesn't mean someone will do it). I guess that if someone ports to such a machine, this would be the least of his problems, so I guess it's not a factor.