From: "Pierre-Clément Tosi" <ptosi@google.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
James Clark <james.clark@linaro.org>
Cc: "Ankur Arora" <ankur.a.arora@oracle.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
"Pierre-Clément Tosi" <ptosi@google.com>
Subject: [PATCH 1/4] perf bench mem: Report why mmap() failed
Date: Tue, 01 Dec 2026 13:11:50 +0100 [thread overview]
Message-ID: <20261201-perf-prot-mte-v1-1-4dc4e1da7460@google.com> (raw)
In-Reply-To: <20261201-perf-prot-mte-v1-0-4dc4e1da7460@google.com>
When mapping a buffer fails, 'perf bench mem' prints
# Memory allocation failed - maybe size (1MB) is too large?
whatever the error, and the mmap benchmark records -ENOMEM for any
failure. Errors such as EINVAL or EACCES are then blamed on the size of
the buffers or on the number of hugepages.
Print the error returned by mmap(), and keep the hint about the size
and hugepages for ENOMEM. When several threads fail, report the error
of the first one instead of ORing negative error codes together.
Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
---
tools/perf/bench/mem-functions.c | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c
index 5ede52853953..412281b03c75 100644
--- a/tools/perf/bench/mem-functions.c
+++ b/tools/perf/bench/mem-functions.c
@@ -193,6 +193,19 @@ static double timeval2double(struct timeval *ts)
printf(" %14lf GB/sec", x / K / K / K); \
} while (0)
+static void print_mmap_error(const struct bench_params *p, int err)
+{
+ char sbuf[STRERR_BUFSIZE];
+
+ printf("# Memory allocation failed: %s", str_error_r(err, sbuf, sizeof(sbuf)));
+ if (err == ENOMEM) {
+ printf(" - maybe size (%s) %s?", size_str,
+ p->page_shift != PAGE_SHIFT_4KB ?
+ "has insufficient hugepages" : "is too large");
+ }
+ printf("\n");
+}
+
static void __bench_mem_function(struct bench_mem_info *info, struct bench_params *p,
int r_idx)
{
@@ -247,8 +260,7 @@ static void __bench_mem_function(struct bench_mem_info *info, struct bench_param
if (r->fn.fini) r->fn.fini(info, p, &src, &dst);
return;
out_init_failed:
- printf("# Memory allocation failed - maybe size (%s) %s?\n", size_str,
- p->page_shift != PAGE_SHIFT_4KB ? "has insufficient hugepages" : "is too large");
+ print_mmap_error(p, errno);
goto out_free;
}
@@ -373,20 +385,21 @@ static void bench_munmap(void *p, size_t size)
munmap(p, size);
}
+/* Return true on failure, with errno set. */
static bool mem_alloc(struct bench_mem_info *info, struct bench_params *p,
void **src, void **dst)
{
- bool failed;
-
*dst = bench_mmap(p->size, true, p->page_shift);
- failed = *dst == NULL;
+ if (!*dst)
+ return true;
if (info->alloc_src) {
*src = bench_mmap(p->size, true, p->page_shift);
- failed = failed || *src == NULL;
+ if (!*src)
+ return true;
}
- return failed;
+ return false;
}
static void mem_free(struct bench_mem_info *info __maybe_unused,
@@ -543,7 +556,7 @@ static void *do_mmap_thread(void *arg)
return data;
out:
- data->error = -ENOMEM;
+ data->error = -errno;
return NULL;
}
@@ -580,14 +593,13 @@ static int do_mmap(const struct function *r, struct bench_params *p,
update_stats(&stats, t->cycles);
else
update_stats(&stats, t->tv.tv_sec * 1e6 + t->tv.tv_usec);
- error |= data[i].error;
+ if (!error)
+ error = data[i].error;
}
free(data);
- if (error) {
- printf("# Memory allocation failed - maybe size (%s) %s?\n", size_str,
- p->page_shift != PAGE_SHIFT_4KB ? "has insufficient hugepages" : "is too large");
- }
+ if (error)
+ print_mmap_error(p, -error);
return error ? -1 : 0;
}
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-12-01 12:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 12:11 [PATCH 0/4] perf bench mem: Add support for PROT_MTE Pierre-Clément Tosi
2026-12-01 12:11 ` Pierre-Clément Tosi [this message]
2026-12-01 12:11 ` [PATCH 2/4] perf bench mem: Pass bench_params to bench_mmap() Pierre-Clément Tosi
2026-12-01 12:11 ` [PATCH 3/4] perf bench mem: Add --prot option Pierre-Clément Tosi
2026-12-01 12:11 ` [PATCH 4/4] perf bench mem: Support PROT_MTE on arm64 Pierre-Clément Tosi
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=20261201-perf-prot-mte-v1-1-4dc4e1da7460@google.com \
--to=ptosi@google.com \
--cc=acme@kernel.org \
--cc=ankur.a.arora@oracle.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/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®