From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127155; b=JNLLMlh9E8cUqnLhMgR++/BxsoIPs20mCApcDRMLindHEASpf/WYaNms/EWPmUFr+tNu N/rYYJIKPUKUdkBtxyFxM+Jw9zoywoZTKSLYjfBglTNQAUzDb9+tM4xFZBlP8NZszUA3t 401P01wUfdz/KLdTU0klq3uSYOUGYTohgk2nf6K+VUw70CFTf7NqXQPeLu0V++rD3rRjJ mTyaJ37bYKddMnvaJpLg8S9G1bazRIBBdizDLVRY0yLHvD4UV+H49RlV2kYAWZmX5mhRi D01EETL1YhOzBxV6wLSjqV5oW2L2eKjUUkRPZU2JFoOu+l3n68d52m4VG6SFaTzUrzA== 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=XAOsLzEKaA5vV+lRvVjLRe+VdOY0dCOfEhAXoMTtX08b9RJLAzx7jf/wThnsnX8iNWFa eJsNCMu/pJc/Pr2NIiQnL23qsHjCdXItUaaw2QKaphi/j//55rF8jNv5k2W1IZuVXBcS3 4f5xXVecVBMIgxlhoqxamAjy6oqULbZFY+CiIGeUUoaVdqtezpqx4aujKN4sl2S5fROc+ /0coKT1IYdUtCi7eWOOxh11Dm/usphe3woXbizey39BqT/5zLMjsLYY5eq5OOURBCd44f fCkErRDlxOSMVVKxG4spIskWPtt+4FI9rjWO5MwBfU/HG2pVVhelUlKXC7CTSqlRXQw== 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.71 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (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 7EED5606A329 for ; Tue, 1 Dec 2026 12:12:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7EED5606A329 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-f71.google.com with SMTP id a640c23a62f3a-c49b95262a5so827174266b.3 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=r6hEBKqUv8BgXJbhWpD5+5j8+1xApXoBU1uoCG69hq/p1yvtMrZgy1765Otb2yNsGu aREcXUWi7jOvSsTvLd4WUBolbpK4VNPf1TWMgLA9oGJHGmSXje9HPNYcIaLWteb0Opqc 6iODlEsLpzFG6Jdrj24eK3j67fXhDIPXYR0tviQrPVr1BUWt3fFyiUuNRITA9SGD8O9j jb716gg6klsJE1eMhDkAHWn/x/FEpBHvwW3seTj8KEM0wJ6DEFoFGjeRJUmszrh2c0U5 QyT3uaH1LcEgfYcB/UK3TraH9RMhZw2SwxNvXwqnMU4lBvOl6EM93AUnxEyGAh5IPbBs 6aDg== X-Forwarded-Encrypted: i=1; AL+hErE5R85HShzb2k34WQEXCYrBRAXsjfKJ4XhF8l7896dIrH6Gm4oKJmHsQJez3a7nSw4FDAXstMKxm/jT89OJKCoE@vger.kernel.org X-Gm-Message-State: APuU4Z8bQM+flIpARrox8fJfpl6HjrPXBTmLBTWUZ6YlgSqN8jN0hoaL +3fbhaajZuDmySeKYiexWvEnr98dURRxp0QpW12iIVwlRRiIQaaJAzR2Y0dZU0u3nTckhJv9tQc V2A== 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-perf-users@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