[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <174085965013.10177.15241731066112284921.tip-bot2@tip-bot2>
Date: Sat, 01 Mar 2025 20:07:30 -0000
From: "tip-bot2 for Peter Zijlstra" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: "Peter Zijlstra (Intel)" <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>, x86@...nel.org, linux-kernel@...r.kernel.org
Subject: [tip: perf/core] perf/core: Remove retry loop from perf_mmap()
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 6cbfc06a8590ab4db69f8af9431e816c859e2776
Gitweb: https://git.kernel.org/tip/6cbfc06a8590ab4db69f8af9431e816c859e2776
Author: Peter Zijlstra <peterz@...radead.org>
AuthorDate: Mon, 04 Nov 2024 14:39:26 +01:00
Committer: Ingo Molnar <mingo@...nel.org>
CommitterDate: Sat, 01 Mar 2025 20:25:57 +01:00
perf/core: Remove retry loop from perf_mmap()
AFAICT there is no actual benefit from the mutex drop on re-try. The
'worst' case scenario is that we instantly re-gain the mutex without
perf_mmap_close() getting it. So might as well make that the normal
case.
Reflow the code to make the ring buffer detach case naturally flow
into the no ring buffer case.
[ mingo: Forward ported it ]
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Signed-off-by: Ingo Molnar <mingo@...nel.org>
Link: https://lore.kernel.org/r/20241104135519.463607258@infradead.org
---
kernel/events/core.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4cd3494..ca4c124 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6719,28 +6719,33 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
return -EINVAL;
WARN_ON_ONCE(event->ctx->parent_ctx);
-again:
mutex_lock(&event->mmap_mutex);
+
if (event->rb) {
if (data_page_nr(event->rb) != nr_pages) {
ret = -EINVAL;
goto unlock;
}
- if (!atomic_inc_not_zero(&event->rb->mmap_count)) {
+ if (atomic_inc_not_zero(&event->rb->mmap_count)) {
/*
- * Raced against perf_mmap_close(); remove the
- * event and try again.
+ * Success -- managed to mmap() the same buffer
+ * multiple times.
*/
- ring_buffer_attach(event, NULL);
- mutex_unlock(&event->mmap_mutex);
- goto again;
+ ret = 0;
+ /* We need the rb to map pages. */
+ rb = event->rb;
+ goto unlock;
}
- /* We need the rb to map pages. */
- rb = event->rb;
- goto unlock;
+ /*
+ * Raced against perf_mmap_close()'s
+ * atomic_dec_and_mutex_lock() remove the
+ * event and continue as if !event->rb
+ */
+ ring_buffer_attach(event, NULL);
}
+
} else {
/*
* AUX area mapping: if rb->aux_nr_pages != 0, it's already
Powered by blists - more mailing lists