20 #include <linux/oom.h>
24 #include <linux/sched.h>
26 #include <linux/timex.h>
29 #include <linux/export.h>
32 #include <linux/mempolicy.h>
34 #include <linux/ptrace.h>
39 #define CREATE_TRACE_POINTS
60 spin_lock_irq(&sighand->
siglock);
61 if (
current->signal->oom_score_adj == old_val)
62 current->signal->oom_score_adj = new_val;
63 trace_oom_score_adj_update(
current);
64 spin_unlock_irq(&sighand->
siglock);
80 spin_lock_irq(&sighand->
siglock);
81 old_val =
current->signal->oom_score_adj;
82 current->signal->oom_score_adj = new_val;
83 trace_oom_score_adj_update(
current);
84 spin_unlock_irq(&sighand->
siglock);
99 static bool has_intersects_mems_allowed(
struct task_struct *tsk,
127 static bool has_intersects_mems_allowed(
struct task_struct *tsk,
158 if (is_global_init(p))
168 if (!has_intersects_mems_allowed(p, nodemask))
184 const nodemask_t *nodemask,
unsigned long totalpages)
189 if (oom_unkillable_task(p, memcg, nodemask))
196 adj = p->
signal->oom_score_adj;
206 points = get_mm_rss(p->
mm) + p->
mm->nr_ptes +
218 adj *= totalpages / 1000;
225 return points > 0 ? points : 1;
234 unsigned long *totalpages)
238 enum zone_type high_zoneidx = gfp_zone(gfp_mask);
239 bool cpuset_limited =
false;
269 high_zoneidx, nodemask)
270 if (!cpuset_zone_allowed_softwall(zone, gfp_mask))
271 cpuset_limited =
true;
273 if (cpuset_limited) {
282 static enum oom_constraint constrained_alloc(
struct zonelist *zonelist,
284 unsigned long *totalpages)
292 unsigned long totalpages,
const nodemask_t *nodemask,
297 if (oom_unkillable_task(task,
NULL, nodemask))
324 else if (!force_kill) {
343 static struct task_struct *select_bad_process(
unsigned int *ppoints,
344 unsigned long totalpages,
const nodemask_t *nodemask,
349 unsigned long chosen_points = 0;
365 return ERR_PTR(-1
UL);
370 if (points > chosen_points) {
372 chosen_points = points;
379 *ppoints = chosen_points * 1000 / totalpages;
399 pr_info(
"[ pid ] uid tgid total_vm rss nr_ptes swapents oom_score_adj name\n");
402 if (oom_unkillable_task(p, memcg, nodemask))
415 pr_info(
"[%5d] %5d %5d %8lu %8lu %7lu %8lu %5d %s\n",
417 task->
tgid, task->
mm->total_vm, get_mm_rss(task->
mm),
430 pr_warning(
"%s invoked oom-killer: gfp_mask=0x%x, order=%d, "
431 "oom_score_adj=%d\n",
432 current->comm, gfp_mask, order,
433 current->signal->oom_score_adj);
440 dump_tasks(memcg, nodemask);
443 #define K(x) ((x) << (PAGE_SHIFT-10))
449 unsigned int points,
unsigned long totalpages,
457 unsigned int victim_points = 0;
475 pr_err(
"%s: Kill process %d (%s) score %d or sacrifice child\n",
476 message, task_pid_nr(p), p->
comm, points);
488 unsigned int child_points;
490 if (child->
mm == p->
mm)
497 if (child_points > victim_points) {
498 put_task_struct(victim);
500 victim_points = child_points;
511 put_task_struct(victim);
513 }
else if (victim != p) {
515 put_task_struct(victim);
521 pr_err(
"Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
522 task_pid_nr(victim), victim->
comm,
K(victim->
mm->total_vm),
537 if (p->
mm == mm && !same_thread_group(p, victim) &&
543 pr_err(
"Kill process %d (%s) sharing same memory\n",
544 task_pid_nr(p), p->
comm);
552 put_task_struct(victim);
574 panic(
"Out of memory: %s panic_on_oom is enabled\n",
603 spin_lock(&zone_scan_lock);
605 if (zone_is_oom_locked(zone)) {
621 spin_unlock(&zone_scan_lock);
635 spin_lock(&zone_scan_lock);
639 spin_unlock(&zone_scan_lock);
647 static int try_set_system_oom(
void)
652 spin_lock(&zone_scan_lock);
654 if (zone_is_oom_locked(zone)) {
661 spin_unlock(&zone_scan_lock);
669 static
void clear_system_oom(
void)
673 spin_lock(&zone_scan_lock);
675 zone_clear_flag(zone, ZONE_OOM_LOCKED);
676 spin_unlock(&zone_scan_lock);
693 int order,
nodemask_t *nodemask,
bool force_kill)
697 unsigned long totalpages;
698 unsigned long freed = 0;
713 if (fatal_signal_pending(
current)) {
722 constraint = constrained_alloc(zonelist, gfp_mask, nodemask,
733 "Out of memory (oom_kill_allocating_task)");
737 p = select_bad_process(&points, totalpages, mpol_mask, force_kill);
741 panic(
"Out of memory and no killable processes...\n");
743 if (PTR_ERR(p) != -1
UL) {
745 nodemask,
"Out of memory");
765 if (try_set_system_oom()) {