Commit 432b1de0 authored by Yafang Shao's avatar Yafang Shao Committed by Linus Torvalds

mm/oom_kill.c: fix uninitialized oc->constraint

In dump_oom_summary() oc->constraint is used to show oom_constraint_text,
but it hasn't been set before.  So the value of it is always the default
value 0.  We should inititialize it before.

Bellow is the output when memcg oom occurs,

before this patch:
  oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null), cpuset=/,mems_allowed=0,oom_memcg=/foo,task_memcg=/foo,task=bash,pid=7997,uid=0

after this patch:
  oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null), cpuset=/,mems_allowed=0,oom_memcg=/foo,task_memcg=/foo,task=bash,pid=13681,uid=0

Link: http://lkml.kernel.org/r/1560522038-15879-1-git-send-email-laoar.shao@gmail.com
Fixes: ef8444ea ("mm, oom: reorganize the oom report in dump_header")
Signed-off-by: default avatarYafang Shao <laoar.shao@gmail.com>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Cc: Wind Yu <yuzhoujian@didichuxing.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent faf53def
...@@ -987,8 +987,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message) ...@@ -987,8 +987,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
/* /*
* Determines whether the kernel must panic because of the panic_on_oom sysctl. * Determines whether the kernel must panic because of the panic_on_oom sysctl.
*/ */
static void check_panic_on_oom(struct oom_control *oc, static void check_panic_on_oom(struct oom_control *oc)
enum oom_constraint constraint)
{ {
if (likely(!sysctl_panic_on_oom)) if (likely(!sysctl_panic_on_oom))
return; return;
...@@ -998,7 +997,7 @@ static void check_panic_on_oom(struct oom_control *oc, ...@@ -998,7 +997,7 @@ static void check_panic_on_oom(struct oom_control *oc,
* does not panic for cpuset, mempolicy, or memcg allocation * does not panic for cpuset, mempolicy, or memcg allocation
* failures. * failures.
*/ */
if (constraint != CONSTRAINT_NONE) if (oc->constraint != CONSTRAINT_NONE)
return; return;
} }
/* Do not panic for oom kills triggered by sysrq */ /* Do not panic for oom kills triggered by sysrq */
...@@ -1035,7 +1034,6 @@ EXPORT_SYMBOL_GPL(unregister_oom_notifier); ...@@ -1035,7 +1034,6 @@ EXPORT_SYMBOL_GPL(unregister_oom_notifier);
bool out_of_memory(struct oom_control *oc) bool out_of_memory(struct oom_control *oc)
{ {
unsigned long freed = 0; unsigned long freed = 0;
enum oom_constraint constraint = CONSTRAINT_NONE;
if (oom_killer_disabled) if (oom_killer_disabled)
return false; return false;
...@@ -1071,10 +1069,10 @@ bool out_of_memory(struct oom_control *oc) ...@@ -1071,10 +1069,10 @@ bool out_of_memory(struct oom_control *oc)
* Check if there were limitations on the allocation (only relevant for * Check if there were limitations on the allocation (only relevant for
* NUMA and memcg) that may require different handling. * NUMA and memcg) that may require different handling.
*/ */
constraint = constrained_alloc(oc); oc->constraint = constrained_alloc(oc);
if (constraint != CONSTRAINT_MEMORY_POLICY) if (oc->constraint != CONSTRAINT_MEMORY_POLICY)
oc->nodemask = NULL; oc->nodemask = NULL;
check_panic_on_oom(oc, constraint); check_panic_on_oom(oc);
if (!is_memcg_oom(oc) && sysctl_oom_kill_allocating_task && if (!is_memcg_oom(oc) && sysctl_oom_kill_allocating_task &&
current->mm && !oom_unkillable_task(current, NULL, oc->nodemask) && current->mm && !oom_unkillable_task(current, NULL, oc->nodemask) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment