Skip to contentSkip to conversation

Prevent OOM from killing init

PATCH Mikael Pettersson 3 participants 3 messages Mar 22, 2001 – Mar 27, 2001

lore
Share & tools
lore
#0 lore raw
Quoted 7 lines · Alan Cox
Quoted 4 lines

Really the whole oom_kill process seems bass-ackwards to me. I can't in my mind logically justify annihilating large-VM processes that have been running for days or weeks instead of just returning ENOMEM to a process that just started up.

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.

oom_kill should simply fail the current allocation which cannot be satisfied, either by having {s,}brk/mmap return error or by posting a SIGSEGV. This would actually also be the correct answer, if Linux didn't overcommit memory ...

Remove the overcommit crap and oom_kill can go away; this entails ensuring that mmap() honors MAP_RESERVE/MAP_NORESERVE.

/Mikael

#1 lore raw
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.

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, but then you still need to recover. C++ you can maybe do it with exception handling but C doesnt really have the structure and longjmp just doesnt cut it.

Alan

#2 lore raw
Quoted 8 lines · Alan Cox
Quoted 7 lines
Quoted 3 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 7 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, but then you still need to recover. C++ you can maybe do it with exception handling but C doesnt really have the structure and longjmp just doesnt cut it.

Seems to me a guard page would do the trick. Make the last page of the stack
non-overcommitable and marked not present. Maybe non-swappable too in case
nothing else can be swapped out for some reason.
(Yes, that wastes a page per process)
Whenever we hit the guard page, try expanding the stack.
If it works - fine. If not - make the guard page present _and_ deliver the SIGSEGV using this last page of stack. No complicated alternate stack construct, just report OOM one page in advance.

OOM is still possible if the program don't handle SIGSEGV well. But a smart program now have the option of doing emergency deallocations and/or dump its precious intermediate results to file.

Helge Hafting