Re: [PATCH v5] ftrace: Fix possible warning on checking all pages used in ftrace_process_locs()

From: Steven Rostedt
Date: Wed Jul 12 2023 - 08:37:36 EST


On Wed, 12 Jul 2023 14:04:52 +0800
Zheng Yejian <zhengyejian1@xxxxxxxxxx> wrote:

> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -3305,6 +3305,22 @@ static int ftrace_allocate_records(struct ftrace_page *pg, int count)
> return cnt;
> }
>
> +static void ftrace_free_pages(struct ftrace_page *pages)
> +{
> + struct ftrace_page *pg = pages;
> +
> + while (pg) {
> + if (pg->records) {
> + free_pages((unsigned long)pg->records, pg->order);
> + ftrace_number_of_pages -= 1 << pg->order;
> + }
> + pages = pg->next;
> + kfree(pg);
> + pg = pages;
> + ftrace_number_of_groups--;
> + }
> +}
> +
> static struct ftrace_page *
> ftrace_allocate_pages(unsigned long num_to_init)
> {
> @@ -3343,17 +3359,7 @@ ftrace_allocate_pages(unsigned long num_to_init)
> return start_pg;
>
> free_pages:
> - pg = start_pg;
> - while (pg) {
> - if (pg->records) {
> - free_pages((unsigned long)pg->records, pg->order);
> - ftrace_number_of_pages -= 1 << pg->order;
> - }
> - start_pg = pg->next;
> - kfree(pg);
> - pg = start_pg;
> - ftrace_number_of_groups--;
> - }
> + ftrace_free_pages(start_pg);
> pr_info("ftrace: FAILED to allocate memory for functions\n");
> return NULL;
> }

Nice little clean up. I had already started testing your previous patch,
but due to my test machine running out of disk space (perf doesn't clean up
its .debug directory :-p), I have to rerun it.

I'll apply this one for the new testing.

Thanks!

-- Steve