Skip to contentSkip to conversation

mm/oom: Add killed process selection information

PATCH In review Edward Chron 2 participants 2 messages Aug 15, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/oom: Add killed process selection information

For an OOM event: print oom_score_adj value for the OOM Killed process to document what the oom score adjust value was at the time the process at the time of the OOM event. The value can be set by the user and it effects the resulting oom_score so useful to document this value.

Sample message output:

Aug 14 23:00:02 testserver kernel: Out of memory: Killed process 2692
 (oomprocs) total-vm:1056800kB, anon-rss:1052760kB, file-rss:4kB,i
 shmem-rss:0kB oom_score_adj:1000
---
 mm/oom_kill.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
mm/oom_kill.c +5 -2
index eda2e2a0bdc6..6b1674cac377 100644
@@ -858,6 +858,7 @@ static void __oom_kill_process(struct task_struct *victim, const char *message)
 	struct task_struct *p;
 	struct mm_struct *mm;
 	bool can_oom_reap = true;
+	long adj;
 
 	p = find_lock_task_mm(victim);
 	if (!p) {
@@ -877,6 +878,8 @@ static void __oom_kill_process(struct task_struct *victim, const char *message)
 	count_vm_event(OOM_KILL);
 	memcg_memory_event_mm(mm, MEMCG_OOM_KILL);
 
+	adj = (long)victim->signal->oom_score_adj;
+
 	/*
 	 * We should send SIGKILL before granting access to memory reserves
 	 * in order to prevent the OOM victim from depleting the memory
@@ -884,12 +887,12 @@ static void __oom_kill_process(struct task_struct *victim, const char *message)
 	 */
 	do_send_sig_info(SIGKILL, SEND_SIG_PRIV, victim, PIDTYPE_TGID);
 	mark_oom_victim(victim);
-	pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB\n",
+	pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB oom_score_adj:%ld\n",
 		message, task_pid_nr(victim), victim->comm,
 		K(victim->mm->total_vm),
 		K(get_mm_counter(victim->mm, MM_ANONPAGES)),
 		K(get_mm_counter(victim->mm, MM_FILEPAGES)),
-		K(get_mm_counter(victim->mm, MM_SHMEMPAGES)));
+		K(get_mm_counter(victim->mm, MM_SHMEMPAGES)), adj);
 	task_unlock(victim);
 
 	/*
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Edward Chron

For an OOM event: print oom_score_adj value for the OOM Killed process to document what the oom score adjust value was at the time the process at the time of the OOM event. The value can be set by the user and it effects the resulting oom_score so useful to document this value.

This value is interesting especially for setups which do not print eligible tasks (sysctl oom_dump_tasks = 0) and helps to notice a misconfiguration <YOUR UDEV EXAMPLE GOES HERE> or to confirm that oom_score_adj configuration applies as expected.

Quoted 6 lines

Sample message output:

Aug 14 23:00:02 testserver kernel: Out of memory: Killed process 2692
 (oomprocs) total-vm:1056800kB, anon-rss:1052760kB, file-rss:4kB,i
 shmem-rss:0kB oom_score_adj:1000

With that feel free to add

and post as a stand alone patch. Btw. the patch could be simplified by not using a helper variable and using victim->signal->oom_score_adj right in the pr_err.

Thanks!

Quoted 42 lines
---
 mm/oom_kill.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
mm/oom_kill.c +5 -2
index eda2e2a0bdc6..6b1674cac377 100644
@@ -858,6 +858,7 @@ static void __oom_kill_process(struct task_struct *victim, const char *message)
 	struct task_struct *p;
 	struct mm_struct *mm;
 	bool can_oom_reap = true;
+	long adj;
 
 	p = find_lock_task_mm(victim);
 	if (!p) {
@@ -877,6 +878,8 @@ static void __oom_kill_process(struct task_struct *victim, const char *message)
 	count_vm_event(OOM_KILL);
 	memcg_memory_event_mm(mm, MEMCG_OOM_KILL);
 
+	adj = (long)victim->signal->oom_score_adj;
+
 	/*
 	 * We should send SIGKILL before granting access to memory reserves
 	 * in order to prevent the OOM victim from depleting the memory
@@ -884,12 +887,12 @@ static void __oom_kill_process(struct task_struct *victim, const char *message)
 	 */
 	do_send_sig_info(SIGKILL, SEND_SIG_PRIV, victim, PIDTYPE_TGID);
 	mark_oom_victim(victim);
-	pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB\n",
+	pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB oom_score_adj:%ld\n",
 		message, task_pid_nr(victim), victim->comm,
 		K(victim->mm->total_vm),
 		K(get_mm_counter(victim->mm, MM_ANONPAGES)),
 		K(get_mm_counter(victim->mm, MM_FILEPAGES)),
-		K(get_mm_counter(victim->mm, MM_SHMEMPAGES)));
+		K(get_mm_counter(victim->mm, MM_SHMEMPAGES)), adj);
 	task_unlock(victim);
 
 	/*
Signature · 1 line
2.20.1
Signature · 2 lines
Michal Hocko
SUSE Labs