diff options
author | Hugh Dickins <hugh.dickins@tiscali.co.uk> | 2009-09-21 20:02:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-22 10:17:33 -0400 |
commit | 35451beecbd7c86ce3249d543594517a5fe9a0cd (patch) | |
tree | e72759e6e6fcd142ab85c607a9b3dd3e1c016eed /mm | |
parent | a913e182ab9484308e870af37a14d372742d53b0 (diff) |
ksm: unmerge is an origin of OOMs
Just as the swapoff system call allocates many pages of RAM to various
processes, perhaps triggering OOM, so "echo 2 >/sys/kernel/mm/ksm/run"
(unmerge) is liable to allocate many pages of RAM to various processes,
perhaps triggering OOM; and each is normally run from a modest admin
process (swapoff or shell), easily repeated until it succeeds.
So treat unmerge_and_remove_all_rmap_items() in the same way that we treat
try_to_unuse(): generalize PF_SWAPOFF to PF_OOM_ORIGIN, and bracket both
with that, to ask the OOM killer to kill them first, to prevent them from
spawning more and more OOM kills.
Signed-off-by: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Acked-by: Izik Eidus <ieidus@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/ksm.c | 2 | ||||
-rw-r--r-- | mm/oom_kill.c | 2 | ||||
-rw-r--r-- | mm/swapfile.c | 4 |
3 files changed, 5 insertions, 3 deletions
@@ -1557,7 +1557,9 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr, | |||
1557 | if (ksm_run != flags) { | 1557 | if (ksm_run != flags) { |
1558 | ksm_run = flags; | 1558 | ksm_run = flags; |
1559 | if (flags & KSM_RUN_UNMERGE) { | 1559 | if (flags & KSM_RUN_UNMERGE) { |
1560 | current->flags |= PF_OOM_ORIGIN; | ||
1560 | err = unmerge_and_remove_all_rmap_items(); | 1561 | err = unmerge_and_remove_all_rmap_items(); |
1562 | current->flags &= ~PF_OOM_ORIGIN; | ||
1561 | if (err) { | 1563 | if (err) { |
1562 | ksm_run = KSM_RUN_STOP; | 1564 | ksm_run = KSM_RUN_STOP; |
1563 | count = err; | 1565 | count = err; |
diff --git a/mm/oom_kill.c b/mm/oom_kill.c index a7b2460e922b..da4c342f2641 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c | |||
@@ -79,7 +79,7 @@ unsigned long badness(struct task_struct *p, unsigned long uptime) | |||
79 | /* | 79 | /* |
80 | * swapoff can easily use up all memory, so kill those first. | 80 | * swapoff can easily use up all memory, so kill those first. |
81 | */ | 81 | */ |
82 | if (p->flags & PF_SWAPOFF) | 82 | if (p->flags & PF_OOM_ORIGIN) |
83 | return ULONG_MAX; | 83 | return ULONG_MAX; |
84 | 84 | ||
85 | /* | 85 | /* |
diff --git a/mm/swapfile.c b/mm/swapfile.c index 74f1102e8749..f1bf19daadc6 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c | |||
@@ -1575,9 +1575,9 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) | |||
1575 | p->flags &= ~SWP_WRITEOK; | 1575 | p->flags &= ~SWP_WRITEOK; |
1576 | spin_unlock(&swap_lock); | 1576 | spin_unlock(&swap_lock); |
1577 | 1577 | ||
1578 | current->flags |= PF_SWAPOFF; | 1578 | current->flags |= PF_OOM_ORIGIN; |
1579 | err = try_to_unuse(type); | 1579 | err = try_to_unuse(type); |
1580 | current->flags &= ~PF_SWAPOFF; | 1580 | current->flags &= ~PF_OOM_ORIGIN; |
1581 | 1581 | ||
1582 | if (err) { | 1582 | if (err) { |
1583 | /* re-insert swap space back into swap_list */ | 1583 | /* re-insert swap space back into swap_list */ |