All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 01/18] perf kmem: Use the allocation order when matching page frees
Date: Fri, 27 Nov 2026 01:53:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-236420@kernel.org> (raw)
In-Reply-To: <20261127013801.14841-2-acme@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] perf kmem: mismatched live byte accounting in
  evsel__process_page_free_event()
- [Medium] perf kmem: stale order on reused page_live_tree entry causes
  -ENOENT on free
- [Low] perf kmem: missing Fixes: trailer in commit message
--

commit 638b1c81610cb380bfc3f707e98e97a94a357759
Author: Arnaldo Carvalho de Melo <acme@redhat.com>

> perf kmem: Use the allocation order when matching page frees
>
> The page alloc tree is keyed by the values recorded at allocation
> time, but the free path looks it up with the order from the free
> event while taking the other key fields from the live page record.
> When a page is split or reused the orders differ, the lookup misses
> and the whole stat fails with a misleading -ENOMEM.
>
> Use the order from the live page record, as is already done for the
> gfp flags, migrate type and callsite, so the lookup finds the entry
> created at allocation time.
>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

[Severity: Low]
Should this include a Fixes tag for the commit that introduced page
allocator event tracking?

  Fixes: 0d68bc92c481 ("perf kmem: Analyze page allocator events also")

> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
> index 8693c6b135cad..3accb5276bd53 100644
> --- a/tools/perf/builtin-kmem.c
> +++ b/tools/perf/builtin-kmem.c
> @@ -928,6 +928,12 @@ static int evsel__process_page_free_event(struct perf_sample *sample)
>  		return 0;
>  	}
>  
> +	/*
> +	 * The alloc tree is keyed by the values recorded at allocation
> +	 * time.  Use the order from the live page as well, otherwise a
> +	 * free of a split/reused page looks up the wrong entry.
> +	 */
> +	this.order = pstat->order;
>  	this.gfp_flags = pstat->gfp_flags;
>  	this.migrate_type = pstat->migrate_type;
>  	this.callsite = pstat->callsite;

[Severity: Medium]
Does live_page accounting in evsel__process_page_free_event() corrupt
pstat->alloc_bytes when the free order differs from pstat->order?

bytes is still computed from the free event's order (kmem_page_size <<
order), while page_stat__find_caller(&this) now looks up the caller entry
for this.order:

tools/perf/builtin-kmem.c:evsel__process_page_free_event() {
	...
	if (live_page) {
		pstat->nr_alloc--;
		pstat->alloc_bytes -= bytes;

		if (pstat->nr_alloc == 0) {
			rb_erase(&pstat->node, &page_caller_tree);
			free(pstat);
		}
	}
}

When a higher-order allocation is split and freed in smaller chunks, only
the head page matches in page_live_tree and is erased, so pstat->nr_alloc
drops by one full allocation while pstat->alloc_bytes only subtracts the
smaller free size.  If a coalesced free has order > this.order while
another allocation on the same caller entry remains live, subtracting
bytes underflows pstat->alloc_bytes.

[Severity: Medium]
Can page_stat__find_caller(&this) fail with -ENOENT when a page already
present in page_live_tree is reused with a different order and callsite?

When page_stat__findnew_page() finds an existing entry in page_live_tree
(for example, when frees were not captured due to sampling or a tail page
was freed as part of a coalesced higher-order block),
__page_stat__findnew_page() returns the existing node without updating
data->order, data->gfp_flags, or data->migrate_type, while
evsel__process_page_alloc_event() overwrites pstat->callsite and inserts
into page_caller_tree using the new order and callsite:

tools/perf/builtin-kmem.c:evsel__process_page_alloc_event() {
	...
	this.page = page;
	pstat = page_stat__findnew_page(&this);
	if (pstat == NULL)
		return -ENOMEM;

	pstat->nr_alloc++;
	pstat->alloc_bytes += bytes;
	pstat->callsite = callsite;
	...
	this.callsite = callsite;
	pstat = page_stat__findnew_caller(&this);

On the next free of that page, evsel__process_page_free_event() combines
the old pstat->order with the new pstat->callsite, producing a hybrid key
that does not exist in page_caller_tree and aborting stat processing with
-ENOENT.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127013801.14841-1-acme@kernel.org?part=1

  reply	other threads:[~2026-11-27  1:53 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  1:37 [PATCH v2 00/18] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 01/18] perf kmem: Use the allocation order when matching page frees Arnaldo Carvalho de Melo
2026-11-27  1:53   ` sashiko-bot [this message]
2026-11-27  1:37 ` [PATCH v2 02/18] perf tests top: Pin the ring buffer size Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 03/18] perf tests sched: Exercise the sched views and options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 04/18] perf tests help: Add a basic perf help test Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 05/18] perf tests config: Exercise the config file and list options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 06/18] perf tests script: Exercise the list, fields and dump options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 07/18] perf tests sort: Exercise the report and diff sort keys Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 08/18] perf tests diff: Exercise the output options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 09/18] perf tests annotate: Exercise the output and filter options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 10/18] perf tests report: Exercise the output and format options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 11/18] perf tests record: Exercise more record options Arnaldo Carvalho de Melo
2026-11-27  1:52   ` sashiko-bot
2026-11-27  1:37 ` [PATCH v2 12/18] perf tests trace: Exercise the tracing options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 13/18] perf tests timechart: Exercise the report options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 14/18] perf tests kmem: Add a basic perf kmem test Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 15/18] perf tests bench: Add smoke tests for perf bench Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 16/18] perf tests lock: Exercise perf lock report and info Arnaldo Carvalho de Melo
2026-11-27  1:38 ` [PATCH v2 17/18] perf tests probe: Exercise the variable and line listing Arnaldo Carvalho de Melo
2026-11-27  1:38 ` [PATCH v2 18/18] perf tests report: Exercise the TUI browsers Arnaldo Carvalho de Melo
2026-11-27  1:53 ` [PATCH v2 00/18] perf tests: Add coverage for the untested perf subcommands sashiko-bot
2026-12-01 17:05 ` Athira Rajeev

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=sashiko-outbox-236420@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acme@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.