From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> A major speed regression in trace-cmd v2.8 is reported by Johannes Berg when parsing a huge trace.dat file: "I have a ~1.7G file with just under 620k events (not exactly big by our standards), and parsing speed (with -N to disable plugins) goes from ~4.5 seconds on commit 1ad32c24746 to >>4.5 minutes (I aborted there) on master. I was talking to Steven about another issue, and he pointed me to commit c2fc2bc296f7. Reverting that on master makes it take ~2 seconds, so that'd actually be an improvement." Proposed solution: do not free pages from "struct page **pages" lookup table in struct cpu_data, in case a trace file is loaded. This reverts the behavior for this use case, as it was before commit c2fc2bc296f7. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203411 Fixes: c2fc2bc296f7 ("trace-cmd: Fix crash when trace-cmd is executed with args profile -F sleep 1") Reported-by: Johannes Berg <johannes@xxxxxxxxxxxxxxxx> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx> --- lib/trace-cmd/trace-input.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 7acecf3..32af20c 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -987,15 +987,17 @@ static void __free_page(struct tracecmd_input *handle, struct page *page) free(page); - for (index = cpu_data->nr_pages - 1; index > 0; index--) - if (cpu_data->pages[index]) - break; - if (index < (cpu_data->nr_pages - 1)) { - pages = realloc(cpu_data->pages, (index + 1) * sizeof(*cpu_data->pages)); - if (!pages) - return; - cpu_data->pages = pages; - cpu_data->nr_pages = index + 1; + if (handle->use_pipe) { + for (index = cpu_data->nr_pages - 1; index > 0; index--) + if (cpu_data->pages[index]) + break; + if (index < (cpu_data->nr_pages - 1)) { + pages = realloc(cpu_data->pages, (index + 1) * sizeof(*cpu_data->pages)); + if (!pages) + return; + cpu_data->pages = pages; + cpu_data->nr_pages = index + 1; + } } } -- 2.21.0