Prevent OOM from killing init
Quoted 7 lines · Alan Cox
Quoted 6 lines
Quoted 2 lines
How do you return an out of memory error to a C program that is out of memory due to a stack growth fault. There is actually not a language construct for it
SIGSEGV.
Stack overflow for a language like C using standard implementation techniques is the same as a page fault while accessing a page for which there is no backing store. SIGSEGV is the logical choice, and the one I'd expect on other Unices.
Quoted 5 lines
Guess again. You are expanding the stack because you have no room left on it. You take a fault. You want to report a SIGSEGV. Now where are you going to put the stack frame ?
SIGSEGV in combination with a preallocated alternate stack maybe
Oh I know 99% of the processes getting this will die. The behaviour I'd expect from vanilla code in this particular case (stack overflow) is:
- page fault in stack "segment"
- no backing store available
- post SIGSEGV to current
* push sighandler frame on current stack (or altstack, if registered) [+]
* no room? SIG_DFL, i.e kill
My point is that with overcommit removed, there's no question as to which process is actually out of memory. No need for the kernel to guess; since it doesn't guess, it cannot guess wrong.
Concerning the stack: sure, oom makes it problematic to report the error in a useful way. So use sigaltstack() and SA_ONSTACK. [+] Processes that don't do this get killed, but not because oom_kill did some fancy guesswork.
[+] Speaking as a hacker on a runtime system for a concurrent programming language (Erlang), I consider the current Unix/POSIX/Linux default of having the kernel throw up[*] at the user's current stack pointer to be unbelievably broken. sigaltstack() and SA_ONSTACK should not be options but required behaviour.
[*] Signal & trap frames used to be called "stack puke" in old 68k days.
/Mikael
Quoted 7 lines · Mikael Pettersson
[+] Speaking as a hacker on a runtime system for a concurrent programming language (Erlang), I consider the current Unix/POSIX/Linux default of having the kernel throw up[*] at the user's current stack pointer to be unbelievably broken.
sigaltstack()andSA_ONSTACKshould not be options but required behaviour.
Why? What problem does stack puke cause?
Quoted 10 lines · Andrew Morton
Quoted 7 lines · Mikael Pettersson
[+] Speaking as a hacker on a runtime system for a concurrent programming language (Erlang), I consider the current Unix/POSIX/Linux default of having the kernel throw up[*] at the user's current stack pointer to be unbelievably broken.
sigaltstack()andSA_ONSTACKshould not be options but required behaviour.Why? What problem does stack puke cause?
It makes user-space stack management difficult or more costly. You either have to over-estimate the size of each coroutine's [*] stack, or you have to run with all signals blocked, or you have to give up on using the machine's native stack.
The first leads to memory wastage (we're talking thousands of coroutines here, each usually having a quite small stack), the second causes overheads when resuming or suspending a coroutine (sigprocmask), and the third loses performance badly on x86 (you lose one g.p. register to point to your simulated stack, and you lose return-stack branch prediction since you can't use call/ret instructions any more).
I currently work around this on Linux/x86 by overriding sigaction() et al to always assert SA_ONSTACK. Unfortunately, this hack doesn't work on all Unices we'd like to support. (I override sigaction since I also need to trap signal setup calls from libraries linked with our code.)
[*] I use the term "coroutine" here to avoid the connotations associated with term like "thread" and "process".
Quoted 7 lines · Mikael Pettersson
Oh I know 99% of the processes getting this will die. The behaviour I'd expect from vanilla code in this particular case (stack overflow) is:
- page fault in stack "segment"
- no backing store available
- post SIGSEGV to current
* push sighandler frame on current stack (or altstack, if registered) [+]
* no room?SIG_DFL, i.e kill
I.e., kill innocent processes which try to increase their memory usage just at the wrong moment. This is exactly what happened before the OOM-killer...
Quoted 3 lines
My point is that with overcommit removed, there's no question as to which process is actually out of memory. No need for the kernel to guess; since it doesn't guess, it cannot guess wrong.
Just too bad there is no complete accounting for memory usage in the kernel right now (a lot of complex data structures in kernel do consume varying amounts of memory, not always in the name of a specific process; much of the extra flexibility in later kernels is exactly because some structures aren't static anymore). Say good-bye to modules, you could as well have everything under the sun built in (as the memory for each possible module will have to be assumed in use, just in case).
Quoted 4 lines
Concerning the stack: sure, oom makes it problematic to report the error in a useful way. So use
sigaltstack()andSA_ONSTACK. [+] Processes that don't do this get killed, but not becauseoom_killdid some fancy guesswork.
They just get killed for requesting memory at the wrong moment, which is a lot worse.
Quoted 7 lines
[+] Speaking as a hacker on a runtime system for a concurrent programming language (Erlang), I consider the current Unix/POSIX/Linux default of having the kernel throw up[*] at the user's current stack pointer to be unbelievably broken.
sigaltstack()andSA_ONSTACKshould not be options but required behaviour.[*] Signal & trap frames used to be called "stack puke" in old 68k days.
Can we please remember that OOM is *not* in any way a "normal system state" that has to be handled in a civilized, orderly way? This is just an escape route in case everything else has failed.
Signature · 4 lines
Dr. Horst H. von Brand mailto:[email protected] Departamento de Informatica Fono: +56 32 654431 Universidad Tecnica Federico Santa Maria +56 32 654239 Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
Quoted 3 lines · Horst von Brand
Can we please remember that OOM is *not* in any way a "normal system state" that has to be handled in a civilized, orderly way? This is just an escape route in case everything else has failed.
Can we please remember that a Blue Screen Of Death is *not* in any way a "normal system state" that has to be handled in a civilized, orderly way? This is just an escape route in case everything else has failed.
Linux is unreliable.
That is bad.
Quoted 4 lines
This is just an escape route in case everything else has failed.
Linux is unreliable.
That is bad.
Since your definition of reliability is a mathematical abstraction requiring infinite storage why don't you start by inventing infinitely large SDRAM chips, then get back to us ?