From patchwork Thu Jan 11 21:05:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Galo X-Patchwork-Id: 13517784 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 224CC58116 for ; Thu, 11 Jan 2024 21:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--carlosgalo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rJkMoIHU" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbcdf587bd6so8320610276.0 for ; Thu, 11 Jan 2024 13:07:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705007229; x=1705612029; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=KM0MFQzzx6R4T/x1ke0xM5cbA+ktwKoGNKfrBNfIEbw=; b=rJkMoIHU1V3WgSD4PFu0QlTOrFsIIZDwJV2idEB8J+WDJ6FXBiZaodwUO54tO6eo2A UsvZHwFbVEkPPN1XF64Rb+5Of/FiqnkD3sGeDbm0co6ax0+mNT7Jgfi+0h4R7ePyyQ29 +AJMkFKODYzRxc+AWOGYz5i2m254rEkkSpqNfzrqjp7COMAZGk2KQjSpT1rnJ8tXGvaQ bRXfU49AgN1acJmps4D/7H+cJ74n8RXkx6KlGwC7p77x+n9m31/6/tQWNkSOfRssJ8HZ FeGuQwGHCotKVWHcD/6aToor4BA8ttMyDltABkGmf0DfJd9mvaxtzNnyKDsNNC85MPfq l/QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705007229; x=1705612029; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=KM0MFQzzx6R4T/x1ke0xM5cbA+ktwKoGNKfrBNfIEbw=; b=WTyFiH+DQ15te/ju2/l5g8iItaS+5lyV9olX3yfnfZv9EEzE87l3i9QUR1BChtckZk Fw64PtXDa5KVcR0YekPOzB6TfOAyK4tBSrgTFum6OHpP+EsIfuofmEONm2/ozx6xzJth 5bKq+OJlR3ZhchyelJW4HpvSS2XUYYeCSP8lZaRmDSL6OFmFzDYOUMF9DJxvrlpqvvKl sQFf/swmc0gYkXDVhRYxATu75TNNc5yQRXsxrhX4pWGfN5Fp2rYfa1DdTx/9XerreN2+ E8CYZ1KOvGDZm0iSUCBpuHwqffg8Y6tDkfoI5JLv2QJbad3YPIIqe8dDlN9IHQ84/nQ8 VfvQ== X-Gm-Message-State: AOJu0YzacDYNObhRsGpvTSGM19kZdNbIP0g306/tPcu7q6XEN9F2xJyU q8mz5P1YwpFFIzX6idTJAsbOHjEBtkCNXZJKF9h3p6k= X-Google-Smtp-Source: AGHT+IEJ8iQ7jU52uMbF/0q9HwIfSP4Ahy2tz5KzGup8oQAgmmJWR0r54OCM5+C/bHTx4p7UxPx+zjBAxjB5XiRg X-Received: from cgalo-android-cuttlefish.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:24f8]) (user=carlosgalo job=sendgmr) by 2002:a05:6902:1788:b0:dbd:b6cd:92cf with SMTP id ca8-20020a056902178800b00dbdb6cd92cfmr94760ybb.11.1705007229176; Thu, 11 Jan 2024 13:07:09 -0800 (PST) Date: Thu, 11 Jan 2024 21:05:30 +0000 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog Message-ID: <20240111210539.636607-1-carlosgalo@google.com> Subject: [PATCH v2] mm: Update mark_victim tracepoints fields From: Carlos Galo To: rostedt@goodmis.org, akpm@linux-foundation.org, surenb@google.com Cc: android-mm@google.com, kernel-team@android.com, Carlos Galo , Masami Hiramatsu , Mathieu Desnoyers , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-mm@kvack.org 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 Cc: Andrew Morton Cc: Suren Baghdasaryan Signed-off-by: Carlos Galo Reviewed-by: Steven Rostedt (Google) --- v2: Fixed build error. Added missing comma when printing `__entry->uid`. include/trace/events/oom.h | 19 +++++++++++++++---- mm/oom_kill.c | 6 +++++- 2 files changed, 20 insertions(+), 5 deletions(-) base-commit: 0dd3ee31125508cd67f7e7172247f05b7fd1753a 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 #include #include +#include #include #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); } /**