From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127155; b=o1X4m91vpxz8xw55N/9DU6oLT195vD4JWIQ64fohEgWEV7we05iZCA4SqjMZKQYV0Cnx CxkG8TJ9DvwA7nr3y//Co2P9jaJBoZzw6R1c5Y5RwGmWO9jFm3HexV5PSkzYIO6w0bScF zReXTsqvLZAweHQ1we0OSVJZFPjC6Pv6HRc3YYecSiI+Rv31MqnrUkv+pBrAmYf+rUsFh sYkc/U3MWovjiNHQCzMoyMjevgnOKUAFWP+ODBV3Ro2+cZ848ikyazKpIwhnccrgSHbZw r0s0ucwxhZxf5RcO+TILwsHdYXonUkLtwy+vXzMlzncu1+rQ4clHx+qb3izEq7Trd0w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127155; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type:Content-Transfer-Encoding; bh=1brH2LTr1zthnhz3CMBR7qFisrjhQbhnzxcSJRKtWxA=; b=nMT2XMtmcrAdKRSM/al/+9tCg0Yph9JOJ6jN/tWflTc2d9N6thQfuo3DGBGqp0V82wz4 sl/Vz62cWJtDFeML0jUtj+P5JH+WdbVZrTyI3qzApmccXtd8xwRQ0KZnoa74zHfi3Dwkr 0b2jA/FzkRZWJAZqRUzsHm9rm2QZow2soFKRoKaOGjcjdhWRd6b+0rCpbDtZ1DYCcCukd wozl+0aPv315VfObuWNebBjiPae783+wudfmdFNjibc/b0YcqYmkhf6mDWWR3kLdYA4Uo y7tdHWr4ixBiy8N3Svgo2h849gdpC40oIcu8DV6YPzloLpg0DVteW28lbipUjEBffgg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--ptosi.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=BBmDzJ0z; arc=none smtp.remote-ip=209.85.218.69 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BD90606A320 for ; Tue, 1 Dec 2026 12:12:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6BD90606A320 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--ptosi.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=BBmDzJ0z Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c5095dd1514so1055325766b.0 for ; Tue, 01 Dec 2026 04:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796127154; x=1796731954; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=1brH2LTr1zthnhz3CMBR7qFisrjhQbhnzxcSJRKtWxA=; b=BBmDzJ0zX2fB1I0LSQaemwECCcjV0wKaw/YtW118nwN1PI+dRdEtGdj87B639BjjfP gahbsP+11XqqPmyd79YGnkDrw+CGkj9p+JW8dC81BJAhPu6AkDmvKv6sontb6asJ6bmT 53x+2dB1hFk2+ovX372QTNwb7lggrU9D9tso6dcwPO2QjhtS5HS/DNF1KuL9uRBT7sxW woDQb2U553yHygdfu/VDRWQtLoOUEe6fIBjXm/Yvnkkr9XwjlO8RohHQ6krMBziCbDL1 opg72abJ/P8tkV5cc1vR9TWNNQ0aE7nT6uOrS74gq5lef9U59rzvlqhy3YfvFNWEXQeh //xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796127154; x=1796731954; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1brH2LTr1zthnhz3CMBR7qFisrjhQbhnzxcSJRKtWxA=; b=fsXPWldM3pO8LXWBbI045a42jWuLkV+9gJ0i5cOsu1+9mbY4YvBNpCce1KmjMytU+P P/h/3nkboTIMRyiSTfWtCI9CVdB0GSlZjq7oQuuMan1qXho4bw1OvZpk12w9yjtBrPkQ kS3Stv5DTgBVW4ZbfmalMJ9AGGcAobYvAJu5Yo/L5rUK/f8HHk8zrRB2EZbPd05ARYvG 5cS9ekQdr2TY8NQM47204+AbslJM780BS5T8phh8/C/E6W7EatlBnvQekLbNr7QulILp e2vshSsa9Ym0ESkhqZnxAsJxz4FeAPzrsUTJTGXgOhvxy3pd51lBIKXuT20vqsP+Xjt4 Wu4Q== X-Forwarded-Encrypted: i=1; AL+hErEp8zyYCAA9VFY4C/MN4+iyTHv08ooB7HnH8bDC6NkdwWJfR9Zs1pKxl9tgn5FFjwhC6JTVbwcfvK4DkFI=@vger.kernel.org X-Gm-Message-State: APuU4Z9ivfn3pKC+tz9k0IaAmxMHoxaVEvxynK6ap9onSDs9xWimhL2h yA4zQKDwCFcVpr1C5qj8B+/qCjd/Woa+UTEe89GOZwGURcxmlKwLr/SF8LatfHv4eXpft1JfW5b MJQ== X-Received: from ejdo7.prod.google.com ([2002:a17:906:2887:b0:c3f:f64c:d857]) (user=ptosi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:26cd:b0:c41:26b8:c49c with SMTP id a640c23a62f3a-c513a5db1d6mr2348536766b.10.1796127153588; Tue, 01 Dec 2026 04:12:33 -0800 (PST) Date: Tue, 01 Dec 2026 13:11:50 +0100 In-Reply-To: <20261201-perf-prot-mte-v1-0-4dc4e1da7460@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261201-perf-prot-mte-v1-0-4dc4e1da7460@google.com> X-Mailer: b4 0.14.3 Message-ID: <20261201-perf-prot-mte-v1-1-4dc4e1da7460@google.com> Subject: [PATCH 1/4] perf bench mem: Report why mmap() failed From: "=?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?=" To: Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , James Clark Cc: Ankur Arora , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, "=?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?=" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C3=A9ment Tosi --- 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-functi= ons.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) =20 +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(sb= uf))); + if (err =3D=3D ENOMEM) { + printf(" - maybe size (%s) %s?", size_str, + p->page_shift !=3D 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 !=3D PAGE_SHIFT_4KB ? "has insufficient hugepages" : "is = too large"); + print_mmap_error(p, errno); goto out_free; } =20 @@ -373,20 +385,21 @@ static void bench_munmap(void *p, size_t size) munmap(p, size); } =20 +/* 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 =3D bench_mmap(p->size, true, p->page_shift); - failed =3D *dst =3D=3D NULL; + if (!*dst) + return true; =20 if (info->alloc_src) { *src =3D bench_mmap(p->size, true, p->page_shift); - failed =3D failed || *src =3D=3D NULL; + if (!*src) + return true; } =20 - return failed; + return false; } =20 static void mem_free(struct bench_mem_info *info __maybe_unused, @@ -543,7 +556,7 @@ static void *do_mmap_thread(void *arg) =20 return data; out: - data->error =3D -ENOMEM; + data->error =3D -errno; return NULL; } =20 @@ -580,14 +593,13 @@ static int do_mmap(const struct function *r, struct b= ench_params *p, update_stats(&stats, t->cycles); else update_stats(&stats, t->tv.tv_sec * 1e6 + t->tv.tv_usec); - error |=3D data[i].error; + if (!error) + error =3D data[i].error; } free(data); =20 - if (error) { - printf("# Memory allocation failed - maybe size (%s) %s?\n", size_str, - p->page_shift !=3D PAGE_SHIFT_4KB ? "has insufficient hugepages" = : "is too large"); - } + if (error) + print_mmap_error(p, -error); return error ? -1 : 0; } =20 --=20 2.56.1.839.g22a8290db9-goog