Re: Kernel thread stack usage



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.

Attachment: pgpavmYNLTOqt.pgp
Description: PGP signature



Relevant Pages

  • Re: Kernel thread stack usage
    ... but it also gives permanent stack overflow risk on complicated ... but now queueing is a flag which should be controlled by sending node. ... stack usage on each call and enforce queueing when stack usage become ... Digging kernel with a dirty hands I have found the way which looks like working. ...
    (freebsd-arch)
  • Re: Kernel thread stack usage
    ... but it also gives permanent stack overflow risk on complicated ... but now queueing is a flag which should be controlled by sending node. ... stack usage on each call and enforce queueing when stack usage become ... It has happened in the distant past but it has been growing less likely in the recent past. ...
    (freebsd-arch)
  • Re: [PATCH] x86: unify x86 Makefile(s)
    ... max(stack usage foo(), stack usage bar). ... But gcc 3 didn't do that. ...
    (Linux-Kernel)
  • Re: Stack Overflow Detection
    ... may not need to account for the stack usage in the interrupts. ... Check the SP in the interrupt which happens at random time instants. ... percentage of CPU cycles to catch the stack value as used in short ...
    (comp.arch.embedded)
  • Re: Problem with mlockall() and Threads: memory usage
    ... based on observed stack usage during running. ... It seems inconsistant that when using mlockallnewly malloced memory will ... >>stack would be a good compromise between latency and memory usage. ...
    (Linux-Kernel)