mm: serialize OOM kill operations
Subsystems (6)
PATCH 1/2 mm: serialize OOM kill operations
The patch below modifies the behavior of the OOM killer so that only one OOM kill operation can be in progress at a time. When running a test program that eats lots of memory, I was observing behavior where the OOM killer gets impatient and shoots one or more system daemons in addition to the program that is eating lots of memory. This fixes the problematic behavior.
---
This patch applies to kernel 2.6.17-rc2-git7.
include/linux/sched.h +2 -0
@@ -350,6 +350,8 @@ struct mm_struct {/* aio bits */ rwlock_t ioctx_list_lock;struct kioctx *ioctx_list; + +int oom_notify; };struct sighand_struct {
include/linux/swap.h +1 -0
@@ -147,6 +147,7 @@ struct swap_list_t {#define vm_swap_full () (nr_swap_pages*2 < total_swap_pages)/* linux/mm/oom_kill.c */ +extern void oom_kill_finish (void );extern void out_of_memory (struct zonelist *zonelist,gfp_t gfp_mask,int order);/* linux/mm/memory.c */
kernel/fork.c +5 -0
@@ -328,6 +328,7 @@ static struct mm_struct * mm_init(struct mm->ioctx_list =NULL ; mm->free_area_cache =TASK_UNMAPPED_BASE ; mm->cached_hole_size = ~0UL ; + mm->oom_notify =0 ;if (likely (!mm_alloc_pgd (mm))) { mm->def_flags =0 ;
@@ -379,6 +380,10 @@ void mmput(struct mm_struct *mm)spin_unlock (&mmlist_lock); }put_swap_token (mm); + +if (unlikely (mm->oom_notify)) +oom_kill_finish (); +mmdrop (mm); } }
mm/oom_kill.c +55 -20
130 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Dave Peterson
The patch below modifies the behavior of the OOM killer so that only one OOM kill operation can be in progress at a time. When running a test program that eats lots of memory, I was observing behavior where the OOM killer gets impatient and shoots one or more system daemons in addition to the program that is eating lots of memory. This fixes the problematic behavior.
Hi Dave,
Firstly why not use a semaphore and trylocks instead of your homebrew lock?
Second, can you arrange it without using the extra field in mm_struct and operation in the mmput fast path?
--
Send instant messages to your online friends http://au.messenger.yahoo.com
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · Nick Piggin
Firstly why not use a semaphore and trylocks instead of your homebrew lock?
Are you suggesting something like this?
spinlock_t oom_kill_lock = SPIN_LOCK_UNLOCKED;
static inline int oom_kill_start(void)
{
return !spin_trylock(&oom_kill_lock);
}
static inline void oom_kill_finish()
{
spin_unlock(&oom_kill_lock);
}If you prefer the above implementation, I can rework the patch as above.
Quoted 2 lines
Second, can you arrange it without using the extra field in
mm_structand operation in the mmput fast path?
I'm open to suggestions on other ways of implementing this. However I think the performance impact of the proposed implementation should be miniscule. The code added to mmput() executes only when the referece count has reached 0; not on every decrement of the reference count. Once the reference count has reached 0, the common-case behavior is still only testing a boolean flag followed by a not-taken branch. The use of unlikely() should help the compiler and CPU branch prediction hardware minimize overhead in the typical case where oom_kill_finish() is not called.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 20 lines · Dave Peterson
Quoted 3 lines · Nick Piggin
Firstly why not use a semaphore and trylocks instead of your homebrew lock?
Are you suggesting something like this?
spinlock_t oom_kill_lock = SPIN_LOCK_UNLOCKED; static inline int oom_kill_start(void) { return !spin_trylock(&oom_kill_lock); } static inline void oom_kill_finish() { spin_unlock(&oom_kill_lock); }
Quoted 3 lines
If you prefer the above implementation, I can rework the patch as above.
I think you need a semaphore? Either way, drop the trivial wrappers.
Quoted 5 lines
Quoted 4 lines
Second, can you arrange it without using the extra field in
mm_structand operation in the mmput fast path?
Quoted 10 lines
I'm open to suggestions on other ways of implementing this. However I think the performance impact of the proposed implementation should be miniscule. The code added to
mmput()executes only when the referece count has reached 0; not on every decrement of the reference count. Once the reference count has reached 0, the common-case behavior is still only testing a boolean flag followed by a not-taken branch. The use ofunlikely()should help the compiler and CPU branch prediction hardware minimize overhead in the typical case whereoom_kill_finish()is not called.
Mainly the cost of increasing cacheline footprint. I think someone suggested using a flag bit somewhere... that'd be preferable.
--
Send instant messages to your online friends http://au.messenger.yahoo.com
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Nick Piggin
Quoted 2 lines · Dave Peterson
If you prefer the above implementation, I can rework the patch as above.
I think you need a semaphore?
In this particular case, I think a semaphore is unnecessary because we just want out_of_memory() to return to its caller if an OOM kill is already in progress (as opposed to waiting in out_of_memory() and then starting a new OOM kill operation). What I want to avoid is the the following type of behavior:
1. Two processes (A and B) call out_of_memory() at roughly the same time and race for oom_kill_lock. Let's say A wins and B is delayed.
2. Process A shoots some process and releases oom_kill_lock.
3. Process B now acquires oom_kill_lock and shoots another process. However this isn't really what we want to do if the OOM kill done by A above freed enough memory to resolve the OOM condition.
Quoted 1 line
Either way, drop the trivial wrappers.
Ok, I'll drop the wrappers.
Quoted 13 lines
Quoted 12 lines
Quoted 2 lines
Second, can you arrange it without using the extra field in
mm_structand operation in the mmput fast path?I'm open to suggestions on other ways of implementing this. However I think the performance impact of the proposed implementation should be miniscule. The code added to
mmput()executes only when the referece count has reached 0; not on every decrement of the reference count. Once the reference count has reached 0, the common-case behavior is still only testing a boolean flag followed by a not-taken branch. The use ofunlikely()should help the compiler and CPU branch prediction hardware minimize overhead in the typical case whereoom_kill_finish()is not called.
Quoted 2 lines
Mainly the cost of increasing cacheline footprint. I think someone suggested using a flag bit somewhere... that'd be preferable.
Ok, I'll add a ->flags member to mm_struct and just use one bit for the oom_notify value. Then if other users of mm_struct need flag bits for other things in the future they can all share ->flags. I'll rework my patches and repost shortly...
Dave
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Dave Peterson
Quoted 5 lines · Nick Piggin
Quoted 2 lines · Dave Peterson
If you prefer the above implementation, I can rework the patch as above.
Quoted 7 lines
Quoted 1 line
I think you need a semaphore?
In this particular case, I think a semaphore is unnecessary because we just want
out_of_memory()to return to its caller if an OOM kill is already in progress (as opposed to waiting inout_of_memory()and then starting a new OOM kill operation). What I want to avoid is the
When you are holding the spinlock, you can't schedule and the lock really should be released by the same process that took it. Are you OK with that?
Quoted 9 lines
Quoted 3 lines
Mainly the cost of increasing cacheline footprint. I think someone suggested using a flag bit somewhere... that'd be preferable.
Ok, I'll add a ->flags member to
mm_structand just use one bit for theoom_notifyvalue. Then if other users ofmm_structneed flag bits for other things in the future they can all share ->flags. I'll rework my patches and repost shortly...
mm_struct already has what you want -- dumpable:2 -- if you just put your bit in an adjacent bitfield, you'll be right.
Signature · 8 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · Nick Piggin
mm_structalready has what you want -- dumpable:2 -- if you just put your bit in an adjacent bitfield, you'll be right.
I should have read all my email first. Ignore me ;)
Signature · 8 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
include/linux/sched.h struct mm_struct { · line 354
Quoted 11 lines · Dave Peterson
Index:
git7-oom/include/linux/sched.h
===================================================================include/linux/sched.h +2
-0@@ -350,6 +350,8 @@ struct mm_struct {/* aio bits */ rwlock_t ioctx_list_lock;struct kioctx *ioctx_list; + +int oom_notify;
That wastes 4 bytes for a single bit. Please put a flag into some of the existing flag bitmaps instead.
-Andi
Quoted 14 lines · Andi Kleen
include/linux/sched.h struct mm_struct { · line 354
Quoted 10 lines · Dave Peterson
Index:
git7-oom/include/linux/sched.h
===================================================================
---git7-oom.orig/include/linux/sched.h2006-04-25 16:19:40.000000000
-0700 +++git7-oom/include/linux/sched.h2006-04-25 16:21:48.000000000
-0700 @@ -350,6 +350,8 @@ structmm_struct{include/linux/sched.h +2
-0/* aio bits */ rwlock_t ioctx_list_lock;struct kioctx *ioctx_list; + +int oom_notify;That wastes 4 bytes for a single bit. Please put a flag into some of the existing flag bitmaps instead.
Any suggestions for a location?
Quoted 2 lines
Any suggestions for a location?
->flags
-Andi
Quoted 3 lines · Andi Kleen
Quoted 1 line
Any suggestions for a location?
->flags
What struct are you looking in? I don't see a ->flags member in mm_struct. Perhaps I should create a ->flags member and use one of the bits?