What data structure is the stack using in Linux?
2
votes
1
answer
1607
views
I have looked in several places such as [here](https://www.cs.columbia.edu/~junfeng/10sp-w4118/lectures/l07-proc-linux.pdf) but none explain in detail the structs used for implementing the stack itself (the place where "tasks" (processes/threads) store their nested call information and such). Is it a linked list, or is it an array, or something else? I can't seem to find this information, but diagrammatically they always show it as a large memory block (virtual memory) where the beginning is the heap and the end is the stack. But this is virtual memory we're dealing with, which has all kinds of data structures around it such as pagination. So the question is what exactly is the implementation of the stack on top of all this? I can't help but think it must be a linked list.
The reason is, if you have multiple processes each with their own stack, how is this implemented?
[Here](https://lwn.net/Articles/692208/) we seem to be getting somewhere:
> Each process has its own stack for use when it is running in the kernel; in current kernels, that stack is sized at either 8KB or (on 64-bit systems) 16KB of memory. The stack lives in directly-mapped kernel memory, so it must be physically contiguous.
Asked by Lance Pollard
(477 rep)
Dec 3, 2019, 03:34 AM
Last activity: Dec 5, 2019, 01:15 AM
Last activity: Dec 5, 2019, 01:15 AM