mm/oom: add oom_score_adj and pgtables to Killed process message
authorEdward Chron <echron@arista.com>
Mon, 23 Sep 2019 22:37:11 +0000 (15:37 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 24 Sep 2019 22:54:10 +0000 (15:54 -0700)
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 was
OOM Killed.  The adjustment value can be set by user code and it affects
the resulting oom_score so it is used to influence kill process selection.

When eligible tasks are not printed (sysctl oom_dump_tasks = 0) printing
this value is the only documentation of the value for the process being
killed.  Having this value on the Killed process message is useful to
document if a miscconfiguration occurred or to confirm that the
oom_score_adj configuration applies as expected.

An example which illustates both misconfiguration and validation that the
oom_score_adj was applied as expected is:

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

The systemd-udevd is a critical system application that should have an
oom_score_adj of -1000.  It was miconfigured to have a adjustment of 1000
making it a highly favored OOM kill target process.  The output documents
both the misconfiguration and the fact that the process was correctly
targeted by OOM due to the miconfiguration.  This can be quite helpful for
triage and problem determination.

The addition of the pgtables_bytes shows page table usage by the process
and is a useful measure of the memory size of the process.

Link: http://lkml.kernel.org/r/20190822173157.1569-1-echron@arista.com
Signed-off-by: Edward Chron <echron@arista.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/oom_kill.c

index a6b76624f5b89cfc1c002fdb1eed59a5a68ef74a..76000feb07946d2b8ed01d91b5c71f200d3f33c8 100644 (file)
@@ -884,13 +884,13 @@ 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, UID:%u\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)),
-               from_kuid(&init_user_ns, task_uid(victim)));
+       pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%hd\n",
+               message, task_pid_nr(victim), victim->comm, K(mm->total_vm),
+               K(get_mm_counter(mm, MM_ANONPAGES)),
+               K(get_mm_counter(mm, MM_FILEPAGES)),
+               K(get_mm_counter(mm, MM_SHMEMPAGES)),
+               from_kuid(&init_user_ns, task_uid(victim)),
+               mm_pgtables_bytes(mm), victim->signal->oom_score_adj);
        task_unlock(victim);
 
        /*