public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ftrace: Do not over-allocate ftrace memory
Date: Tue, 6 Jan 2026 17:56:12 -0800	[thread overview]
Message-ID: <3cd8b2bf-c18f-4fb2-85ff-afcaaa1b38ca@roeck-us.net> (raw)
In-Reply-To: <20260106203352.539b9548@gandalf.local.home>

On Tue, Jan 06, 2026 at 08:33:52PM -0500, Steven Rostedt wrote:
> On Tue, 6 Jan 2026 16:54:27 -0800
> Guenter Roeck <linux@roeck-us.net> wrote:
> 
> > > Don't remove this block. It's still needed. A lot of entries are
> > > skipped when adding the records. Weak functions and zero'd pointers
> > > that were part of the count are skipped. This is the code that handles
> > > that. It has nothing to do with rounding errors.
> > >   
> > Sorry, misunderstanding. I thought that is what you meant with "This will
> > make pages equal the number of pages that were allocated. Then I'm not sure
> > we need this extra logic."
> > 
> > What is the no longer needed extra logic ?
> 
> I meant the added logic you had there, as I was a bit confused by the
> "spaces" part.
> 

That was just to avoid "skip" going negative in the for loop.
The code below should work as well. I'll give it a try.

Thanks,
Guenter

> The logic still needs to be updated, but I think it can be done with the
> following:
> 
> 	if (pg_unuse) {
> 		unsigned long pg_remaining, remaining = 0;
> 		long skip;
> 
> 		/* Count the number of entries unused and compare it to skipped. */
> 		pg_remaining = (PAGE_SIZE << pg->order) / ENTRIES_SIZE - pg->index;
> 
> 		if (!WARN(skipped < pg_remaining, "Extra allocated pages for ftrace")) {
> 
> 			skip = skipped - pg_remaining;
> 
> 			for (pg = pg_unuse; pg && skip > 0; pg = pg->next) {
> 				remaining += 1 << pg->order;
> 				skip -= (PAGE_SIZE << pg->order) / ENTRIES_SIZE;
> 			}
> 
> 			pages -= remaining;
> 
> 			/*
> 			 * Check to see if the number of pages remaining would
> 			 * just fit the number of entries skipped.
> 			 */
> 			WARN(pg || skip > 0, "Extra allocated pages for ftrace: %lu with %lu skipped",
> 			     remaining, skipped);
> 		}
> 		/* Need to synchronize with ftrace_location_range() */
> 		synchronize_rcu();
> 		ftrace_free_pages(pg_unuse);
> 	}
> 
> -- Steve

  reply	other threads:[~2026-01-07  1:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-07  0:24 [PATCH v2] ftrace: Do not over-allocate ftrace memory Guenter Roeck
2026-01-07  0:43 ` Steven Rostedt
2026-01-07  0:54   ` Guenter Roeck
2026-01-07  1:33     ` Steven Rostedt
2026-01-07  1:56       ` Guenter Roeck [this message]
2026-01-07  0:52 ` Steven Rostedt
2026-01-07  1:47   ` Guenter Roeck

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=3cd8b2bf-c18f-4fb2-85ff-afcaaa1b38ca@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.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