Commit 43d2b113 authored by KAMEZAWA Hiroyuki's avatar KAMEZAWA Hiroyuki Committed by Linus Torvalds

tracepoint: add tracepoints for debugging oom_score_adj

oom_score_adj is used for guarding processes from OOM-Killer.  One of
problem is that it's inherited at fork().  When a daemon set oom_score_adj
and make children, it's hard to know where the value is set.

This patch adds some tracepoints useful for debugging. This patch adds
3 trace points.
  - creating new task
  - renaming a task (exec)
  - set oom_score_adj

To debug, users need to enable some trace pointer. Maybe filtering is useful as

# EVENT=/sys/kernel/debug/tracing/events/task/
# echo "oom_score_adj != 0" > $EVENT/task_newtask/filter
# echo "oom_score_adj != 0" > $EVENT/task_rename/filter
# echo 1 > $EVENT/enable
# EVENT=/sys/kernel/debug/tracing/events/oom/
# echo 1 > $EVENT/enable

output will be like this.
# grep oom /sys/kernel/debug/tracing/trace
bash-7699  [007] d..3  5140.744510: oom_score_adj_update: pid=7699 comm=bash oom_score_adj=-1000
bash-7699  [007] ...1  5151.818022: task_newtask: pid=7729 comm=bash clone_flags=1200011 oom_score_adj=-1000
ls-7729  [003] ...2  5151.818504: task_rename: pid=7729 oldcomm=bash newcomm=ls oom_score_adj=-1000
bash-7699  [002] ...1  5175.701468: task_newtask: pid=7730 comm=bash clone_flags=1200011 oom_score_adj=-1000
grep-7730  [007] ...2  5175.701993: task_rename: pid=7730 oldcomm=bash newcomm=grep oom_score_adj=-1000
Signed-off-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Acked-by: default avatarDavid Rientjes <rientjes@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6bd4837d
...@@ -59,6 +59,8 @@ ...@@ -59,6 +59,8 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/mmu_context.h> #include <asm/mmu_context.h>
#include <asm/tlb.h> #include <asm/tlb.h>
#include <trace/events/task.h>
#include "internal.h" #include "internal.h"
int core_uses_pid; int core_uses_pid;
...@@ -1054,6 +1056,8 @@ void set_task_comm(struct task_struct *tsk, char *buf) ...@@ -1054,6 +1056,8 @@ void set_task_comm(struct task_struct *tsk, char *buf)
{ {
task_lock(tsk); task_lock(tsk);
trace_task_rename(tsk, buf);
/* /*
* Threads may access current->comm without holding * Threads may access current->comm without holding
* the task lock, so write the string carefully. * the task lock, so write the string carefully.
......
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
#ifdef CONFIG_HARDWALL #ifdef CONFIG_HARDWALL
#include <asm/hardwall.h> #include <asm/hardwall.h>
#endif #endif
#include <trace/events/oom.h>
#include "internal.h" #include "internal.h"
/* NOTE: /* NOTE:
...@@ -1010,6 +1011,7 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf, ...@@ -1010,6 +1011,7 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
else else
task->signal->oom_score_adj = (oom_adjust * OOM_SCORE_ADJ_MAX) / task->signal->oom_score_adj = (oom_adjust * OOM_SCORE_ADJ_MAX) /
-OOM_DISABLE; -OOM_DISABLE;
trace_oom_score_adj_update(task);
err_sighand: err_sighand:
unlock_task_sighand(task, &flags); unlock_task_sighand(task, &flags);
err_task_lock: err_task_lock:
...@@ -1097,6 +1099,7 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf, ...@@ -1097,6 +1099,7 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
task->signal->oom_score_adj = oom_score_adj; task->signal->oom_score_adj = oom_score_adj;
if (has_capability_noaudit(current, CAP_SYS_RESOURCE)) if (has_capability_noaudit(current, CAP_SYS_RESOURCE))
task->signal->oom_score_adj_min = oom_score_adj; task->signal->oom_score_adj_min = oom_score_adj;
trace_oom_score_adj_update(task);
/* /*
* Scale /proc/pid/oom_adj appropriately ensuring that OOM_DISABLE is * Scale /proc/pid/oom_adj appropriately ensuring that OOM_DISABLE is
* always attainable. * always attainable.
......
#undef TRACE_SYSTEM
#define TRACE_SYSTEM oom
#if !defined(_TRACE_OOM_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_OOM_H
#include <linux/tracepoint.h>
TRACE_EVENT(oom_score_adj_update,
TP_PROTO(struct task_struct *task),
TP_ARGS(task),
TP_STRUCT__entry(
__field( pid_t, pid)
__array( char, comm, TASK_COMM_LEN )
__field( int, oom_score_adj)
),
TP_fast_assign(
__entry->pid = task->pid;
memcpy(__entry->comm, task->comm, TASK_COMM_LEN);
__entry->oom_score_adj = task->signal->oom_score_adj;
),
TP_printk("pid=%d comm=%s oom_score_adj=%d",
__entry->pid, __entry->comm, __entry->oom_score_adj)
);
#endif
/* This part must be outside protection */
#include <trace/define_trace.h>
#undef TRACE_SYSTEM
#define TRACE_SYSTEM task
#if !defined(_TRACE_TASK_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_TASK_H
#include <linux/tracepoint.h>
TRACE_EVENT(task_newtask,
TP_PROTO(struct task_struct *task, unsigned long clone_flags),
TP_ARGS(task, clone_flags),
TP_STRUCT__entry(
__field( pid_t, pid)
__array( char, comm, TASK_COMM_LEN)
__field( unsigned long, clone_flags)
__field( int, oom_score_adj)
),
TP_fast_assign(
__entry->pid = task->pid;
memcpy(__entry->comm, task->comm, TASK_COMM_LEN);
__entry->clone_flags = clone_flags;
__entry->oom_score_adj = task->signal->oom_score_adj;
),
TP_printk("pid=%d comm=%s clone_flags=%lx oom_score_adj=%d",
__entry->pid, __entry->comm,
__entry->clone_flags, __entry->oom_score_adj)
);
TRACE_EVENT(task_rename,
TP_PROTO(struct task_struct *task, char *comm),
TP_ARGS(task, comm),
TP_STRUCT__entry(
__field( pid_t, pid)
__array( char, oldcomm, TASK_COMM_LEN)
__array( char, newcomm, TASK_COMM_LEN)
__field( int, oom_score_adj)
),
TP_fast_assign(
__entry->pid = task->pid;
memcpy(entry->oldcomm, task->comm, TASK_COMM_LEN);
memcpy(entry->newcomm, comm, TASK_COMM_LEN);
__entry->oom_score_adj = task->signal->oom_score_adj;
),
TP_printk("pid=%d oldcomm=%s newcomm=%s oom_score_adj=%d",
__entry->pid, __entry->oldcomm,
__entry->newcomm, __entry->oom_score_adj)
);
#endif
/* This part must be outside protection */
#include <trace/define_trace.h>
...@@ -76,6 +76,9 @@ ...@@ -76,6 +76,9 @@
#include <trace/events/sched.h> #include <trace/events/sched.h>
#define CREATE_TRACE_POINTS
#include <trace/events/task.h>
/* /*
* Protected counters by write_lock_irq(&tasklist_lock) * Protected counters by write_lock_irq(&tasklist_lock)
*/ */
...@@ -1370,6 +1373,9 @@ static struct task_struct *copy_process(unsigned long clone_flags, ...@@ -1370,6 +1373,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
if (clone_flags & CLONE_THREAD) if (clone_flags & CLONE_THREAD)
threadgroup_change_end(current); threadgroup_change_end(current);
perf_event_fork(p); perf_event_fork(p);
trace_task_newtask(p, clone_flags);
return p; return p;
bad_fork_free_pid: bad_fork_free_pid:
......
...@@ -33,6 +33,10 @@ ...@@ -33,6 +33,10 @@
#include <linux/security.h> #include <linux/security.h>
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <linux/freezer.h> #include <linux/freezer.h>
#include <linux/ftrace.h>
#define CREATE_TRACE_POINTS
#include <trace/events/oom.h>
int sysctl_panic_on_oom; int sysctl_panic_on_oom;
int sysctl_oom_kill_allocating_task; int sysctl_oom_kill_allocating_task;
...@@ -55,6 +59,7 @@ void compare_swap_oom_score_adj(int old_val, int new_val) ...@@ -55,6 +59,7 @@ void compare_swap_oom_score_adj(int old_val, int new_val)
spin_lock_irq(&sighand->siglock); spin_lock_irq(&sighand->siglock);
if (current->signal->oom_score_adj == old_val) if (current->signal->oom_score_adj == old_val)
current->signal->oom_score_adj = new_val; current->signal->oom_score_adj = new_val;
trace_oom_score_adj_update(current);
spin_unlock_irq(&sighand->siglock); spin_unlock_irq(&sighand->siglock);
} }
...@@ -74,6 +79,7 @@ int test_set_oom_score_adj(int new_val) ...@@ -74,6 +79,7 @@ int test_set_oom_score_adj(int new_val)
spin_lock_irq(&sighand->siglock); spin_lock_irq(&sighand->siglock);
old_val = current->signal->oom_score_adj; old_val = current->signal->oom_score_adj;
current->signal->oom_score_adj = new_val; current->signal->oom_score_adj = new_val;
trace_oom_score_adj_update(current);
spin_unlock_irq(&sighand->siglock); spin_unlock_irq(&sighand->siglock);
return old_val; return old_val;
......
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