From: Kalesh Singh <kaleshsingh@google.com>
To: akpm@linux-foundation.org, minchan@kernel.org,
lorenzo.stoakes@oracle.com, david@redhat.com,
Liam.Howlett@oracle.com, rppt@kernel.org, pfalcato@suse.de
Cc: kernel-team@android.com, android-mm@google.com,
Kalesh Singh <kaleshsingh@google.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Kees Cook <kees@kernel.org>, Vlastimil Babka <vbabka@suse.cz>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
Jann Horn <jannh@google.com>, Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH v2 7/7] mm/tracing: introduce max_vma_count_exceeded trace event
Date: Mon, 15 Sep 2025 09:36:38 -0700 [thread overview]
Message-ID: <20250915163838.631445-8-kaleshsingh@google.com> (raw)
In-Reply-To: <20250915163838.631445-1-kaleshsingh@google.com>
Needed observability on in field devices can be collected with minimal
overhead and can be toggled on and off. Event driven telemetry can be
done with tracepoint BPF programs.
The process comm is provided for aggregation across devices and tgid is
to enable per-process aggregation per device.
This allows for observing the distribution of such problems in the
field, to deduce if there are legitimate bugs or if a bump to the limit is
warranted.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Pedro Falcato <pfalcato@suse.de>
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Chnages in v2:
- Add needed observability for operations failing due to the vma count limit,
per Minchan
(Since there isn't a common point for debug logging due checks being
external to the capacity based vma_count_remaining() helper. I used a
trace event for low overhead and to facilitate event driven telemetry
for in field devices)
include/trace/events/vma.h | 32 ++++++++++++++++++++++++++++++++
mm/mmap.c | 5 ++++-
mm/mremap.c | 10 ++++++++--
mm/vma.c | 11 +++++++++--
4 files changed, 53 insertions(+), 5 deletions(-)
create mode 100644 include/trace/events/vma.h
diff --git a/include/trace/events/vma.h b/include/trace/events/vma.h
new file mode 100644
index 000000000000..2fed63b0d0a6
--- /dev/null
+++ b/include/trace/events/vma.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM vma
+
+#if !defined(_TRACE_VMA_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_VMA_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(max_vma_count_exceeded,
+
+ TP_PROTO(struct task_struct *task),
+
+ TP_ARGS(task),
+
+ TP_STRUCT__entry(
+ __string(comm, task->comm)
+ __field(pid_t, tgid)
+ ),
+
+ TP_fast_assign(
+ __assign_str(comm);
+ __entry->tgid = task->tgid;
+ ),
+
+ TP_printk("comm=%s tgid=%d", __get_str(comm), __entry->tgid)
+);
+
+#endif /* _TRACE_VMA_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
diff --git a/mm/mmap.c b/mm/mmap.c
index 30ddd550197e..0bb311bf48f3 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -56,6 +56,7 @@
#define CREATE_TRACE_POINTS
#include <trace/events/mmap.h>
+#include <trace/events/vma.h>
#include "internal.h"
@@ -374,8 +375,10 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
return -EOVERFLOW;
/* Too many mappings? */
- if (!vma_count_remaining(mm))
+ if (!vma_count_remaining(mm)) {
+ trace_max_vma_count_exceeded(current);
return -ENOMEM;
+ }
/*
* addr is returned from get_unmapped_area,
diff --git a/mm/mremap.c b/mm/mremap.c
index 14d35d87e89b..f42ac05f0069 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -30,6 +30,8 @@
#include <asm/tlb.h>
#include <asm/pgalloc.h>
+#include <trace/events/vma.h>
+
#include "internal.h"
/* Classify the kind of remap operation being performed. */
@@ -1040,8 +1042,10 @@ static unsigned long prep_move_vma(struct vma_remap_struct *vrm)
* We'd prefer to avoid failure later on in do_munmap:
* which may split one vma into three before unmapping.
*/
- if (vma_count_remaining(current->mm) < 4)
+ if (vma_count_remaining(current->mm) < 4) {
+ trace_max_vma_count_exceeded(current);
return -ENOMEM;
+ }
if (vma->vm_ops && vma->vm_ops->may_split) {
if (vma->vm_start != old_addr)
@@ -1817,8 +1821,10 @@ static unsigned long check_mremap_params(struct vma_remap_struct *vrm)
* the threshold. In other words, is the current map count + 6 at or
* below the threshold? Otherwise return -ENOMEM here to be more safe.
*/
- if (vma_count_remaining(current->mm) < 6)
+ if (vma_count_remaining(current->mm) < 6) {
+ trace_max_vma_count_exceeded(current);
return -ENOMEM;
+ }
return 0;
}
diff --git a/mm/vma.c b/mm/vma.c
index 0e4fcaebe209..692c33c3e84d 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -7,6 +7,8 @@
#include "vma_internal.h"
#include "vma.h"
+#include <trace/events/vma.h>
+
struct mmap_state {
struct mm_struct *mm;
struct vma_iterator *vmi;
@@ -621,8 +623,10 @@ __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
static int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
unsigned long addr, int new_below)
{
- if (!vma_count_remaining(vma->vm_mm))
+ if (!vma_count_remaining(vma->vm_mm)) {
+ trace_max_vma_count_exceeded(current);
return -ENOMEM;
+ }
return __split_vma(vmi, vma, addr, new_below);
}
@@ -1375,6 +1379,7 @@ static int vms_gather_munmap_vmas(struct vma_munmap_struct *vms,
*/
if (vms->end < vms->vma->vm_end &&
!vma_count_remaining(vms->vma->vm_mm)) {
+ trace_max_vma_count_exceeded(current);
error = -ENOMEM;
goto vma_count_exceeded;
}
@@ -2801,8 +2806,10 @@ int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma,
if (!may_expand_vm(mm, vm_flags, len >> PAGE_SHIFT))
return -ENOMEM;
- if (!vma_count_remaining(mm))
+ if (!vma_count_remaining(mm)) {
+ trace_max_vma_count_exceeded(current);
return -ENOMEM;
+ }
if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
return -ENOMEM;
--
2.51.0.384.g4c02a37b29-goog
next prev parent reply other threads:[~2025-09-15 16:47 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-15 16:36 [PATCH v2 0/7] vma count: fixes, test and improvements Kalesh Singh
2025-09-15 16:36 ` [PATCH v2 1/7] mm: fix off-by-one error in VMA count limit checks Kalesh Singh
2025-09-15 22:36 ` Andrew Morton
2025-09-16 14:20 ` Jonathan Corbet
2025-09-17 1:16 ` Andrew Morton
2025-09-16 9:45 ` Pedro Falcato
2025-09-17 7:44 ` SeongJae Park
2025-09-17 10:52 ` David Hildenbrand
2025-09-18 11:31 ` Pedro Falcato
2025-09-18 13:53 ` Lorenzo Stoakes
2025-09-15 16:36 ` [PATCH v2 2/7] mm/selftests: add max_vma_count tests Kalesh Singh
2025-09-17 10:58 ` David Hildenbrand
2025-09-17 16:49 ` Kalesh Singh
2025-09-18 14:42 ` Lorenzo Stoakes
2025-09-18 16:21 ` Kalesh Singh
2025-09-15 16:36 ` [PATCH v2 3/7] mm: introduce vma_count_remaining() Kalesh Singh
2025-09-17 13:38 ` David Hildenbrand
2025-09-17 17:10 ` Kalesh Singh
2025-09-18 13:20 ` Lorenzo Stoakes
2025-09-18 13:26 ` Lorenzo Stoakes
2025-09-18 14:31 ` Lorenzo Stoakes
2025-09-18 15:52 ` Kalesh Singh
2025-09-15 16:36 ` [PATCH v2 4/7] mm: rename mm_struct::map_count to vma_count Kalesh Singh
2025-09-17 13:41 ` David Hildenbrand
2025-09-18 11:46 ` Pedro Falcato
2025-09-18 14:48 ` Lorenzo Stoakes
2025-09-15 16:36 ` [PATCH v2 5/7] mm: harden vma_count against direct modification Kalesh Singh
2025-09-18 14:52 ` Lorenzo Stoakes
2025-09-18 15:43 ` Kalesh Singh
2025-09-15 16:36 ` [PATCH v2 6/7] mm: add assertion for VMA count limit Kalesh Singh
2025-09-17 13:44 ` David Hildenbrand
2025-09-17 17:22 ` Kalesh Singh
2025-09-17 18:34 ` David Hildenbrand
2025-09-17 20:31 ` Kalesh Singh
2025-09-18 11:48 ` Pedro Falcato
2025-09-18 13:30 ` Lorenzo Stoakes
2025-09-15 16:36 ` Kalesh Singh [this message]
2025-09-15 23:41 ` [PATCH v2 7/7] mm/tracing: introduce max_vma_count_exceeded trace event Steven Rostedt
2025-09-16 1:19 ` Kalesh Singh
2025-09-16 15:52 ` Steven Rostedt
2025-09-16 17:36 ` Kalesh Singh
2025-09-16 17:48 ` Steven Rostedt
2025-09-16 17:57 ` Kalesh Singh
2025-09-16 18:02 ` Steven Rostedt
2025-09-16 18:23 ` Kalesh Singh
2025-09-16 18:51 ` Steven Rostedt
2025-09-16 20:08 ` Kalesh Singh
2025-09-18 11:38 ` Pedro Falcato
2025-09-18 14:48 ` Steven Rostedt
2025-09-18 13:42 ` Lorenzo Stoakes
2025-09-18 13:51 ` Lorenzo Stoakes
2025-09-18 15:55 ` Kalesh Singh
2025-09-15 22:34 ` [PATCH v2 0/7] vma count: fixes, test and improvements Andrew Morton
2025-09-15 23:10 ` Kalesh Singh
2025-09-16 0:05 ` Andrew Morton
2025-09-16 1:23 ` Kalesh Singh
2025-09-16 10:12 ` Lorenzo Stoakes
2025-09-16 17:47 ` Kalesh Singh
2025-09-17 2:16 ` Andrew Morton
2025-09-17 5:36 ` Lorenzo Stoakes
2025-09-17 23:32 ` Andrew Morton
2025-09-18 10:29 ` Lorenzo Stoakes
2025-09-18 12:07 ` David Hildenbrand
2025-09-18 12:49 ` Lorenzo Stoakes
2025-09-18 20:59 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250915163838.631445-8-kaleshsingh@google.com \
--to=kaleshsingh@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=android-mm@google.com \
--cc=brauner@kernel.org \
--cc=bsegall@google.com \
--cc=david@redhat.com \
--cc=dietmar.eggemann@arm.com \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kernel-team@android.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mgorman@suse.de \
--cc=mhiramat@kernel.org \
--cc=mhocko@suse.com \
--cc=minchan@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=pfalcato@suse.de \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=vincent.guittot@linaro.org \
--cc=viro@zeniv.linux.org.uk \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®