0

Why bother, really?

On 64-bit architectures OS can assign ludicrously large address space to each stack, then map new pages to the virtual memory on demand.

So why do we have limited stack sizes?

Is it just to be able to better identify segfaults?

Or is it just to keep backward compatibility with architectures with no virtual memory?

This is especially interesting in the context of split stacks: If the stacks were unlimited, split stacks would be a solution to a non-existent problem. Or am I wrong?

Martin Sustrik
  • 783
  • 10
  • 22
  • Finite size memory can provide only finite size stacks. – dlask Jun 21 '15 at 10:38
  • 1
    possible duplicate of [why is stack memory size so limited?](http://stackoverflow.com/questions/10482974/why-is-stack-memory-size-so-limited) – Marcus Müller Jun 21 '15 at 10:38
  • The linked answers don't say anything I haven't figured out myself. Let's keep this open for few more days. – Martin Sustrik Jun 21 '15 at 12:01
  • do you need several GB of local variables? – phuclv Jun 21 '15 at 15:52
  • No, I've been rather thinking about very small stacks that extend on demand. Exactly like gcc split stacks. But split stacks, in turn, look like a workaround for a bad OS design... Maybe I am wrong. But if so, why? – Martin Sustrik Jun 21 '15 at 16:12
  • In many paged-memory systems, making address space available for use has a cost. In a typical system, an access to logical address X will generate an address to physical address `PhysicalBlockAddresses[x / pagesize] + (x % pagesize)`. If on a particular system each block address entry takes 64 bytes, and pagesize is 65536 bytes, then allocating an extra 1GB of address space for a stack would require the physical use and initialization of 1MB of actual RAM to hold the associated page-table entries. Not a huge amount for one or two long-lived threads, but those costs could easily add up. – supercat Apr 26 '17 at 17:45

1 Answers1

0

Windows does grow the amount of initialized Stack space, i would assume that Linux too . You can provide "ludicrously large" size limit for a Stack . And unless that will grow actual memory use, by storing correlated amount of metadata . You should be just fine .

Is it just to be able to better identify segfaults?

Or is it just to keep backward compatibility with architectures with no virtual memory?

Pretty much the both, yeah .

irvnriir
  • 673
  • 5
  • 14