4 ms·
While possible, sprinkling code with madvise syscalls to release memory doesn't seems like a very realistic proposition. Information on how much stack is actual
by labawi 6y ago
While possible, sprinkling code with madvise syscalls to release memory doesn't seems like a very realistic proposition. Information on how much stack is actually mapped is not readily (or cheaply) available.
The article says:
> The workload is representative for measuring absolute memory overhead, but is not representative for time overhead.
The workload is definitely not representative of real memory overhead. What's worse, it almost can be, but it is very dependent on the pattern of stack usage and it may not be obvious that you are holding on to large amounts of stack.
Default stack size on linux is 8MB. If you don't use much stack, 10k threads might only need 200M of RAM. Or your threads might touch 2M of stack early in their lifetime, parsing recursive data structures or whatever, and you need 20G of RAM, because you're stacks don't get freed.
Realistically, when using green threading, I wouldn't give much thought before using 10K waiting threads.
With native threading, I would look for other reasonable solutions, because it's not worth the headaches, but in case they do turn out to be the most reasonable solution, I would be sure to appropriately lower the stack size to avoid OOM, budget at least a week for solving gotchas, and forever need to be vigilant about stack usage.