3 ms·
Sure, but 128 kB is really small even if you do that properly. Seems like it would be more sensible if the stack space could just grow when required. Surely no
by IshKebab 5y ago
Sure, but 128 kB is really small even if you do that properly.
Seems like it would be more sensible if the stack space could just grow when required. Surely not that difficult?
- viraptor 5y agoThe main thread already does that. The thread stack does not. It probably made sense on 32b with relatively limited address space... But I'm curious why we're not applying that to all threads on 64b. Reserving a few 10MB of address space per thread shouldn't be a big issue, right? (Without actually mapping those pages)
- megous 5y agoMapping a lot of pages has some overhead, too. So if you have large stacks per thread you'll take a hit. If you use huge pages to alleviate that, you'll waste a lot of physical memory.
- tyingq 5y agoIt is easy for a single threaded program, but since each thread has it's own part of the stack, it would be non-trivial for a multithreaded program.
- aidenn0 5y agoA typical stack frame is around a couple dozen words. Let's round that up to 32 words (256 bytes). 128K is enough for a 500 deep stack at that size. 128K is huge.
- CodesInChaos 5y agoSince standard OS stacks are contiguous and unmovable, you can't grow them once they run out of space. However while the address space for the maximum stack size gets reserved, each page only requires backing memory once it's first used. So as far as physical memory consumption is concerned, typical stacks act as growable with a fixed maximum size. Since address space is huge on 64-bit systems, choosing a large stack size is cheap on such systems (at least of they allow over-commit). For the main thread, a system can also try to keep other allocations far from the stack without committing to any particular size (heap grows upwards from the bottom of the address space, stack downwards from the top). But this doesn't scale to multiple threads and leads to an unpredictable maximum stack size, so I prefer the fixed reserved space approach.
- pjmlp 5y agoEnough for a full COM binary plus one overlay section. :)
- megous 5y agoWait until you realize OS kernel thread stack size is 8 KiB or in that range, if you think 128 KiB is small. :))