Kernel Stack Size/Location Selection

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Apophis
Posts: 8
Joined: Wed Nov 03, 2010 2:29 am

Kernel Stack Size/Location Selection

Post 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?
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Kernel Stack Size/Location Selection

Post 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.
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: Kernel Stack Size/Location Selection

Post 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.
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: Kernel Stack Size/Location Selection

Post 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.
Post Reply