linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Update mark_victim tracepoints fields
@ 2024-01-11  0:11 Carlos Galo
  2024-01-11 13:08 ` kernel test robot
  2024-01-11 17:07 ` kernel test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Carlos Galo @ 2024-01-11  0:11 UTC (permalink / raw)
  To: rostedt, akpm, surenb
  Cc: android-mm, kernel-team, Carlos Galo, Masami Hiramatsu,
	Mathieu Desnoyers, linux-kernel, linux-trace-kernel, linux-mm

The current implementation of the mark_victim tracepoint provides only
the process ID (pid) of the victim process. This limitation poses
challenges for userspace tools that need additional information
about the OOM victim. The association between pid and the additional
data may be lost after the kill, making it difficult for userspace to
correlate the OOM event with the specific process.

In order to mitigate this limitation, add the following fields:

- UID
   In Android each installed application has a unique UID. Including
   the `uid` assists in correlating OOM events with specific apps.

- Process Name (comm)
   Enables identification of the affected process.

- OOM Score
   Allows userspace to get additional insights of the relative kill
   priority of the OOM victim.

Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Carlos Galo <carlosgalo@google.com>
---
 include/trace/events/oom.h | 19 +++++++++++++++----
 mm/oom_kill.c              |  6 +++++-
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/include/trace/events/oom.h b/include/trace/events/oom.h
index 26a11e4a2c36..fb8a5d1b8a0a 100644
--- a/include/trace/events/oom.h
+++ b/include/trace/events/oom.h
@@ -72,19 +72,30 @@ TRACE_EVENT(reclaim_retry_zone,
 );
 
 TRACE_EVENT(mark_victim,
-	TP_PROTO(int pid),
+	TP_PROTO(struct task_struct *task, uid_t uid),
 
-	TP_ARGS(pid),
+	TP_ARGS(task, uid),
 
 	TP_STRUCT__entry(
 		__field(int, pid)
+		__field(uid_t, uid)
+		__string(comm, task->comm)
+		__field(short, oom_score_adj)
 	),
 
 	TP_fast_assign(
-		__entry->pid = pid;
+		__entry->pid = task->pid;
+		__entry->uid = uid;
+		__assign_str(comm, task->comm);
+		__entry->oom_score_adj = task->signal->oom_score_adj;
 	),
 
-	TP_printk("pid=%d", __entry->pid)
+	TP_printk("pid=%d uid=%u comm=%s oom_score_adj=%hd",
+		__entry->pid,
+		__entry->uid
+		__get_str(comm),
+		__entry->oom_score_adj,
+	)
 );
 
 TRACE_EVENT(wake_reaper,
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 9e6071fde34a..0698c00c5da6 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -44,6 +44,7 @@
 #include <linux/kthread.h>
 #include <linux/init.h>
 #include <linux/mmu_notifier.h>
+#include <linux/cred.h>
 
 #include <asm/tlb.h>
 #include "internal.h"
@@ -753,6 +754,7 @@ static inline void queue_oom_reaper(struct task_struct *tsk)
  */
 static void mark_oom_victim(struct task_struct *tsk)
 {
+	const struct cred *cred;
 	struct mm_struct *mm = tsk->mm;
 
 	WARN_ON(oom_killer_disabled);
@@ -772,7 +774,9 @@ static void mark_oom_victim(struct task_struct *tsk)
 	 */
 	__thaw_task(tsk);
 	atomic_inc(&oom_victims);
-	trace_mark_victim(tsk->pid);
+	cred = get_task_cred(tsk);
+	trace_mark_victim(tsk, cred->uid.val);
+	put_cred(cred);
 }
 
 /**

base-commit: 0dd3ee31125508cd67f7e7172247f05b7fd1753a
-- 
2.43.0.275.g3460e3d667-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm: Update mark_victim tracepoints fields
  2024-01-11  0:11 [PATCH] mm: Update mark_victim tracepoints fields Carlos Galo
@ 2024-01-11 13:08 ` kernel test robot
  2024-01-11 17:07 ` kernel test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2024-01-11 13:08 UTC (permalink / raw)
  To: Carlos Galo, rostedt, akpm, surenb
  Cc: llvm, oe-kbuild-all, android-mm, kernel-team, Carlos Galo,
	Masami Hiramatsu, Mathieu Desnoyers, linux-kernel,
	linux-trace-kernel, linux-mm

Hi Carlos,

kernel test robot noticed the following build errors:

[auto build test ERROR on 0dd3ee31125508cd67f7e7172247f05b7fd1753a]

url:    https://github.com/intel-lab-lkp/linux/commits/Carlos-Galo/mm-Update-mark_victim-tracepoints-fields/20240111-081635
base:   0dd3ee31125508cd67f7e7172247f05b7fd1753a
patch link:    https://lore.kernel.org/r/20240111001155.746-1-carlosgalo%40google.com
patch subject: [PATCH] mm: Update mark_victim tracepoints fields
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20240111/202401112057.lJYUSJJe-lkp@intel.com/config)
compiler: ClangBuiltLinux clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240111/202401112057.lJYUSJJe-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401112057.lJYUSJJe-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from mm/oom_kill.c:54:
   In file included from include/trace/events/oom.h:206:
   In file included from include/trace/define_trace.h:102:
   In file included from include/trace/trace_events.h:237:
>> include/trace/events/oom.h:96:3: error: called object type 'uid_t' (aka 'unsigned int') is not a function or function pointer
      74 |         ),
         |         ~~
      75 | 
      76 |         TP_fast_assign(
         |         ~~~~~~~~~~~~~~~
      77 |                 __entry->pid = task->pid;
         |                 ~~~~~~~~~~~~~~~~~~~~~~~~~
      78 |                 __entry->uid = uid;
         |                 ~~~~~~~~~~~~~~~~~~~
      79 |                 __assign_str(comm, task->comm);
         |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      80 |                 __entry->oom_score_adj = task->signal->oom_score_adj;
         |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      81 |         ),
         |         ~~
      82 | 
      83 |         TP_printk("pid=%d uid=%u comm=%s oom_score_adj=%hd",
         |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      84 |                 __entry->pid,
         |                 ~~~~~~~~~~~~~
      85 |                 __entry->uid
         |                 ~~~~~~~~~~~~
      86 |                 __get_str(comm),
         |                 ^~~~~~~~~~~~~~~~
      87 |                 __entry->oom_score_adj,
         |                 ~~~~~~~~~~~~~~~~~~~~~~~
      88 |         )
         |         ~
      89 | );
         | ~
   include/trace/stages/stage3_trace_output.h:20:26: note: expanded from macro '__get_str'
      20 | #define __get_str(field) ((char *)__get_dynamic_array(field))
         |                          ^
   include/trace/stages/stage3_trace_output.h:9:43: note: expanded from macro 'TP_printk'
       9 | #define TP_printk(fmt, args...) fmt "\n", args
         |                                           ^
   include/trace/trace_events.h:45:16: note: expanded from macro 'TRACE_EVENT'
      40 |         DECLARE_EVENT_CLASS(name,                              \
         |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      41 |                              PARAMS(proto),                    \
         |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      42 |                              PARAMS(args),                     \
         |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      43 |                              PARAMS(tstruct),                  \
         |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      44 |                              PARAMS(assign),                   \
         |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      45 |                              PARAMS(print));                   \
         |                              ~~~~~~~^~~~~~~
   include/linux/tracepoint.h:107:25: note: expanded from macro 'PARAMS'
     107 | #define PARAMS(args...) args
         |                         ^
   include/trace/trace_events.h:203:27: note: expanded from macro 'DECLARE_EVENT_CLASS'
     203 |         trace_event_printf(iter, print);                                \
         |                                  ^~~~~
   In file included from mm/oom_kill.c:54:
   In file included from include/trace/events/oom.h:206:
   In file included from include/trace/define_trace.h:102:
   In file included from include/trace/trace_events.h:237:
>> include/trace/events/oom.h:74:1: error: expected expression
      74 | TRACE_EVENT(mark_victim,
         | ^
   include/trace/trace_events.h:40:2: note: expanded from macro 'TRACE_EVENT'
      40 |         DECLARE_EVENT_CLASS(name,                              \
         |         ^
   include/trace/trace_events.h:203:32: note: expanded from macro 'DECLARE_EVENT_CLASS'
     203 |         trace_event_printf(iter, print);                                \
         |                                       ^
   2 errors generated.


vim +96 include/trace/events/oom.h

    73	
  > 74	TRACE_EVENT(mark_victim,
    75		TP_PROTO(struct task_struct *task, uid_t uid),
    76	
    77		TP_ARGS(task, uid),
    78	
    79		TP_STRUCT__entry(
    80			__field(int, pid)
    81			__field(uid_t, uid)
    82			__string(comm, task->comm)
    83			__field(short, oom_score_adj)
    84		),
    85	
    86		TP_fast_assign(
    87			__entry->pid = task->pid;
    88			__entry->uid = uid;
    89			__assign_str(comm, task->comm);
    90			__entry->oom_score_adj = task->signal->oom_score_adj;
    91		),
    92	
    93		TP_printk("pid=%d uid=%u comm=%s oom_score_adj=%hd",
    94			__entry->pid,
    95			__entry->uid
  > 96			__get_str(comm),
    97			__entry->oom_score_adj,
    98		)
    99	);
   100	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm: Update mark_victim tracepoints fields
  2024-01-11  0:11 [PATCH] mm: Update mark_victim tracepoints fields Carlos Galo
  2024-01-11 13:08 ` kernel test robot
@ 2024-01-11 17:07 ` kernel test robot
  2024-01-11 21:20   ` Carlos Galo
  1 sibling, 1 reply; 4+ messages in thread
From: kernel test robot @ 2024-01-11 17:07 UTC (permalink / raw)
  To: Carlos Galo, rostedt, akpm, surenb
  Cc: oe-kbuild-all, android-mm, kernel-team, Carlos Galo,
	Masami Hiramatsu, Mathieu Desnoyers, linux-kernel,
	linux-trace-kernel, linux-mm

Hi Carlos,

kernel test robot noticed the following build errors:

[auto build test ERROR on 0dd3ee31125508cd67f7e7172247f05b7fd1753a]

url:    https://github.com/intel-lab-lkp/linux/commits/Carlos-Galo/mm-Update-mark_victim-tracepoints-fields/20240111-081635
base:   0dd3ee31125508cd67f7e7172247f05b7fd1753a
patch link:    https://lore.kernel.org/r/20240111001155.746-1-carlosgalo%40google.com
patch subject: [PATCH] mm: Update mark_victim tracepoints fields
config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20240112/202401120052.rdFjpivG-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240112/202401120052.rdFjpivG-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401120052.rdFjpivG-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/trace/define_trace.h:102,
                    from include/trace/events/oom.h:206,
                    from mm/oom_kill.c:54:
   include/trace/events/oom.h: In function 'trace_raw_output_mark_victim':
>> include/trace/stages/stage3_trace_output.h:6:17: error: called object is not a function or function pointer
       6 | #define __entry field
         |                 ^~~~~
   include/trace/trace_events.h:203:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
     203 |         trace_event_printf(iter, print);                                \
         |                                  ^~~~~
   include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
      45 |                              PARAMS(print));                   \
         |                              ^~~~~~
   include/trace/events/oom.h:74:1: note: in expansion of macro 'TRACE_EVENT'
      74 | TRACE_EVENT(mark_victim,
         | ^~~~~~~~~~~
   include/trace/events/oom.h:93:9: note: in expansion of macro 'TP_printk'
      93 |         TP_printk("pid=%d uid=%u comm=%s oom_score_adj=%hd",
         |         ^~~~~~~~~
   include/trace/events/oom.h:95:17: note: in expansion of macro '__entry'
      95 |                 __entry->uid
         |                 ^~~~~~~
>> include/trace/trace_events.h:203:39: error: expected expression before ')' token
     203 |         trace_event_printf(iter, print);                                \
         |                                       ^
   include/trace/trace_events.h:40:9: note: in expansion of macro 'DECLARE_EVENT_CLASS'
      40 |         DECLARE_EVENT_CLASS(name,                              \
         |         ^~~~~~~~~~~~~~~~~~~
   include/trace/events/oom.h:74:1: note: in expansion of macro 'TRACE_EVENT'
      74 | TRACE_EVENT(mark_victim,
         | ^~~~~~~~~~~


vim +6 include/trace/stages/stage3_trace_output.h

af6b9668e85ffd include/trace/stages/stage3_defines.h Steven Rostedt (Google  2022-03-03  4) 
af6b9668e85ffd include/trace/stages/stage3_defines.h Steven Rostedt (Google  2022-03-03  5) #undef __entry
af6b9668e85ffd include/trace/stages/stage3_defines.h Steven Rostedt (Google  2022-03-03 @6) #define __entry field
af6b9668e85ffd include/trace/stages/stage3_defines.h Steven Rostedt (Google  2022-03-03  7) 

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm: Update mark_victim tracepoints fields
  2024-01-11 17:07 ` kernel test robot
@ 2024-01-11 21:20   ` Carlos Galo
  0 siblings, 0 replies; 4+ messages in thread
From: Carlos Galo @ 2024-01-11 21:20 UTC (permalink / raw)
  To: kernel test robot
  Cc: rostedt, akpm, surenb, oe-kbuild-all, android-mm, kernel-team,
	Masami Hiramatsu, Mathieu Desnoyers, linux-kernel,
	linux-trace-kernel, linux-mm

On Thu, Jan 11, 2024 at 9:08 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi Carlos,
>
> kernel test robot noticed the following build errors:
>
> [auto build test ERROR on 0dd3ee31125508cd67f7e7172247f05b7fd1753a]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Carlos-Galo/mm-Update-mark_victim-tracepoints-fields/20240111-081635
> base:   0dd3ee31125508cd67f7e7172247f05b7fd1753a
> patch link:    https://lore.kernel.org/r/20240111001155.746-1-carlosgalo%40google.com
> patch subject: [PATCH] mm: Update mark_victim tracepoints fields
> config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20240112/202401120052.rdFjpivG-lkp@intel.com/config)
> compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240112/202401120052.rdFjpivG-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202401120052.rdFjpivG-lkp@intel.com/
>

Sorry, I missed a comma in my final editing.
I posted a V2 here:
https://lore.kernel.org/lkml/20240111210539.636607-1-carlosgalo@google.com/

Thanks,
Carlos

> All errors (new ones prefixed by >>):
>
>    In file included from include/trace/define_trace.h:102,
>                     from include/trace/events/oom.h:206,
>                     from mm/oom_kill.c:54:
>    include/trace/events/oom.h: In function 'trace_raw_output_mark_victim':
> >> include/trace/stages/stage3_trace_output.h:6:17: error: called object is not a function or function pointer
>        6 | #define __entry field
>          |                 ^~~~~
>    include/trace/trace_events.h:203:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
>      203 |         trace_event_printf(iter, print);                                \
>          |                                  ^~~~~
>    include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
>       45 |                              PARAMS(print));                   \
>          |                              ^~~~~~
>    include/trace/events/oom.h:74:1: note: in expansion of macro 'TRACE_EVENT'
>       74 | TRACE_EVENT(mark_victim,
>          | ^~~~~~~~~~~
>    include/trace/events/oom.h:93:9: note: in expansion of macro 'TP_printk'
>       93 |         TP_printk("pid=%d uid=%u comm=%s oom_score_adj=%hd",
>          |         ^~~~~~~~~
>    include/trace/events/oom.h:95:17: note: in expansion of macro '__entry'
>       95 |                 __entry->uid
>          |                 ^~~~~~~
> >> include/trace/trace_events.h:203:39: error: expected expression before ')' token
>      203 |         trace_event_printf(iter, print);                                \
>          |                                       ^
>    include/trace/trace_events.h:40:9: note: in expansion of macro 'DECLARE_EVENT_CLASS'
>       40 |         DECLARE_EVENT_CLASS(name,                              \
>          |         ^~~~~~~~~~~~~~~~~~~
>    include/trace/events/oom.h:74:1: note: in expansion of macro 'TRACE_EVENT'
>       74 | TRACE_EVENT(mark_victim,
>          | ^~~~~~~~~~~
>
>
> vim +6 include/trace/stages/stage3_trace_output.h
>
> af6b9668e85ffd include/trace/stages/stage3_defines.h Steven Rostedt (Google  2022-03-03  4)
> af6b9668e85ffd include/trace/stages/stage3_defines.h Steven Rostedt (Google  2022-03-03  5) #undef __entry
> af6b9668e85ffd include/trace/stages/stage3_defines.h Steven Rostedt (Google  2022-03-03 @6) #define __entry field
> af6b9668e85ffd include/trace/stages/stage3_defines.h Steven Rostedt (Google  2022-03-03  7)
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-11 21:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11  0:11 [PATCH] mm: Update mark_victim tracepoints fields Carlos Galo
2024-01-11 13:08 ` kernel test robot
2024-01-11 17:07 ` kernel test robot
2024-01-11 21:20   ` Carlos Galo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).