News for hackers. Stuff that matters.
Re:Understanding thread stack sizes and how Alpine is different by IshKebab on Saturday June 26, 2021 @09:05AM (#27641499)
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?

Re:Understanding thread stack sizes and how Alpine is different by CodesInChaos on Saturday June 26, 2021 @09:39AM (#27641711)
Since 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.

Re:Understanding thread stack sizes and how Alpine is different by viraptor on Saturday June 26, 2021 @09:16AM (#27641550)
The 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)
Re:Understanding thread stack sizes and how Alpine is different by megous on Saturday June 26, 2021 @01:38PM (#27644001)
Mapping 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.

Re:Understanding thread stack sizes and how Alpine is different by tyingq on Saturday June 26, 2021 @09:23AM (#27641592)
It 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.
Re:Understanding thread stack sizes and how Alpine is different by megous on Saturday June 26, 2021 @01:48PM (#27644111)
Wait until you realize OS kernel thread stack size is 8 KiB or in that range, if you think 128 KiB is small. :))
Re:Understanding thread stack sizes and how Alpine is different by pjmlp on Saturday June 26, 2021 @10:55AM (#27642384)
Enough for a full COM binary plus one overlay section. :)
Re:Understanding thread stack sizes and how Alpine is different by aidenn0 on Saturday June 26, 2021 @09:38AM (#27641701)
A 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.