return false;
}
+extern bool mem_cgroup_oom_called(struct task_struct *task);
+
#else /* CONFIG_CGROUP_MEM_RES_CTLR */
struct mem_cgroup;
{
return true;
}
+
+static inline bool mem_cgroup_oom_called(struct task_struct *task)
+{
+ return false;
+}
#endif /* CONFIG_CGROUP_MEM_CONT */
#endif /* _LINUX_MEMCONTROL_H */
* Should the accounting and control be hierarchical, per subtree?
*/
bool use_hierarchy;
-
+ unsigned long last_oom_jiffies;
int obsolete;
atomic_t refcnt;
/*
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.
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
continue;
if (!nr_retries--) {
- if (oom)
+ if (oom) {
mem_cgroup_out_of_memory(mem, gfp_mask);
+ mem->last_oom_jiffies = jiffies;
+ }
goto nomem;
}
}
ret = __mem_cgroup_try_charge(NULL, gfp_mask, &parent, false);
- if (ret)
+ if (ret || !parent)
return ret;
if (!get_page_unless_zero(page))
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);
/* 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");
* 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);
}