Page 1 of 1
Kernel Stack Size/Location Selection
Posted: Thu Nov 04, 2010 12:56 pm
by Apophis
I've been looking around for information about setting up the kernel stack. I can find a lot of information on how to set up the stack but very little on how to choose where to put the stack.
I'm wondering: what are some guidelines and recommendations for where and how big to make the kernel stack?
Re: Kernel Stack Size/Location Selection
Posted: Thu Nov 04, 2010 3:34 pm
by NickJohnson
Just put it along with the other global data: either somewhere in the binary if you're using flat binary, or in the .bss section if you're using ELF (I don't know about PE or other formats). The kernel stack doesn't need to be that big, unless you're going to be using a lot of recursion. 4KB should be plenty to start: I think I currently use 2KB with no problems, although threads are not saved on it.
Re: Kernel Stack Size/Location Selection
Posted: Fri Nov 05, 2010 9:12 am
by skyking
You have to first decide on how big the stack need to be, as a comparision linux uses 8KiB IIRC. It may be possible to calculate the theoretical maximally needed stackspace unless you use recursion (in which case you ought to put in checks so you don't run over the stack limit).
You can pretty much place the stack wherever you want and what's the best choice depends on the platform. If you use one kernel stack per user space thread you would probably want to dynamically allocate the stack space.
Re: Kernel Stack Size/Location Selection
Posted: Fri Nov 05, 2010 3:02 pm
by TylerH
Linux has an option for 4 or 8 KiB stack sizes. IIRC, it's 8 by default, or at least, it was. I remember reading an article a few months ago about the argument for/against switching to 4Kib as the default, but I don't know what resulted from it. I'd say use 4 KiB since it's the allocation block size for your pmm(assumption) and it's probably as big as you'll ever need.