Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 127573
b: refs/heads/master
c: a636b32
h: refs/heads/master
i:
  127571: dda3ef6
v: v3
  • Loading branch information
KAMEZAWA Hiroyuki authored and Linus Torvalds committed Jan 8, 2009
1 parent 0bdda39 commit 96f5a99
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2e4d40915fb85207fe48cfc31201824ec6d7426e
refs/heads/master: a636b327f731143ccc544b966cfd8de6cb6d72c6
7 changes: 7 additions & 0 deletions trunk/include/linux/memcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ static inline bool mem_cgroup_disabled(void)
return false;
}

extern bool mem_cgroup_oom_called(struct task_struct *task);

#else /* CONFIG_CGROUP_MEM_RES_CTLR */
struct mem_cgroup;

Expand Down Expand Up @@ -234,6 +236,11 @@ static inline bool mem_cgroup_disabled(void)
{
return true;
}

static inline bool mem_cgroup_oom_called(struct task_struct *task)
{
return false;
}
#endif /* CONFIG_CGROUP_MEM_CONT */

#endif /* _LINUX_MEMCONTROL_H */
Expand Down
33 changes: 29 additions & 4 deletions trunk/mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct mem_cgroup {
* Should the accounting and control be hierarchical, per subtree?
*/
bool use_hierarchy;

unsigned long last_oom_jiffies;
int obsolete;
atomic_t refcnt;
/*
Expand Down Expand Up @@ -615,6 +615,22 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem,
return ret;
}

bool mem_cgroup_oom_called(struct task_struct *task)
{
bool ret = false;
struct mem_cgroup *mem;
struct mm_struct *mm;

rcu_read_lock();
mm = task->mm;
if (!mm)
mm = &init_mm;
mem = mem_cgroup_from_task(rcu_dereference(mm->owner));
if (mem && time_before(jiffies, mem->last_oom_jiffies + HZ/10))
ret = true;
rcu_read_unlock();
return ret;
}
/*
* Unlike exported interface, "oom" parameter is added. if oom==true,
* oom-killer can be invoked.
Expand All @@ -626,6 +642,13 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
struct mem_cgroup *mem, *mem_over_limit;
int nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
struct res_counter *fail_res;

if (unlikely(test_thread_flag(TIF_MEMDIE))) {
/* Don't account this! */
*memcg = NULL;
return 0;
}

/*
* We always charge the cgroup the mm_struct belongs to.
* The mm_struct's mem_cgroup changes on task migration if the
Expand Down Expand Up @@ -694,8 +717,10 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
continue;

if (!nr_retries--) {
if (oom)
if (oom) {
mem_cgroup_out_of_memory(mem, gfp_mask);
mem->last_oom_jiffies = jiffies;
}
goto nomem;
}
}
Expand Down Expand Up @@ -832,7 +857,7 @@ static int mem_cgroup_move_parent(struct page_cgroup *pc,


ret = __mem_cgroup_try_charge(NULL, gfp_mask, &parent, false);
if (ret)
if (ret || !parent)
return ret;

if (!get_page_unless_zero(page))
Expand Down Expand Up @@ -883,7 +908,7 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,

mem = memcg;
ret = __mem_cgroup_try_charge(mm, gfp_mask, &mem, true);
if (ret)
if (ret || !mem)
return ret;

__mem_cgroup_commit_charge(mem, pc, ctype);
Expand Down
8 changes: 8 additions & 0 deletions trunk/mm/oom_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,13 @@ void pagefault_out_of_memory(void)
/* Got some memory back in the last second. */
return;

/*
* If this is from memcg, oom-killer is already invoked.
* and not worth to go system-wide-oom.
*/
if (mem_cgroup_oom_called(current))
goto rest_and_return;

if (sysctl_panic_on_oom)
panic("out of memory from page fault. panic_on_oom is selected.\n");

Expand All @@ -571,6 +578,7 @@ void pagefault_out_of_memory(void)
* Give "p" a good chance of killing itself before we
* retry to allocate memory.
*/
rest_and_return:
if (!test_thread_flag(TIF_MEMDIE))
schedule_timeout_uninterruptible(1);
}
Expand Down

0 comments on commit 96f5a99

Please sign in to comment.