OOM policy, overcommit control, and soft limits
Hi,
The kernel provides things like ulimit, overcommit_memory, and the OOM killer notifications, so in theory memory management should not be a problem, but from time to time, I have a real need to regain control of my system when it runs away on me.
I like how mode 2 of overcommit_memory uses the ratio as a boundary limit. Ideally I would like something like this as a soft limit, so once the system gets that full, I get a warning.
Here's my ideal OOM flow:
1) set my soft limit to 90% of RAM
2) any malloc that hits this limit first runs through a notification hook, that talks to a userspace daemon if present, or just denies the malloc if not
3) the daemon can decide whether to allow the allocation, going beyond the soft limit
4) the daemon can make these decisions automatically based on policy (i.e. X always gets the green light), or if we want to get fancy it can talk to some pre-allocated GUI to present the decision to the user... (i.e. Allocate / Deny / Stop / Kill)
5) if the user foolishly keeps allocating, then the current OOM killer comes into play
I'm sure someone has thought of this before me. Does anything remotely similar to this already exist? I've googled for OOM policy, but so far all I've seen is Rusty Lynch's patch from 2003, and really, I want this behaviour to happen when there is still a bit of memory left, so things can be dealt with before they are OOM-level dire.
Thanks in advance,
- Chris
Quoted 5 lines
I'm sure someone has thought of this before me. Does anything remotely similar to this already exist? I've googled for OOM policy, but so far all I've seen is Rusty Lynch's patch from 2003, and really, I want this behaviour to happen when there is still a bit of memory left, so things can be dealt with before they are OOM-level dire.
Not that I am aware of. However you can set priorities on OOM killing order and there is a patch from the XO people which seems to have vanished into the darkness which added a nice memory pressure notifier so apps could respond to memory shortages intelligently (eg by cleaning up)
Quoted 5 lines · Chris Frey
I'm sure someone has thought of this before me. Does anything remotely similar to this already exist? I've googled for OOM policy, but so far all I've seen is Rusty Lynch's patch from 2003, and really, I want this behaviour to happen when there is still a bit of memory left, so things can be dealt with before they are OOM-level dire.
Have you seen the OOM killer policy implemented in memory the resource controller?
http://kernelnewbies.org/Linux_2_6_25#head-450b26e12955b8035a05cf07b3f31c501ee4bfab
BTW read the TODO comment in this commit log... ;-)
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=c7ba5c9e8176704bfac0729875fa62798037584d
Maybe a possible solution could be to just run critical and non-critical applications in 2 different cgroups, using different memory policies. Anyway, userspace OOM handling would surely permit to implement more interesting features.
-Andrea