From 345ef6a3f9fa03089c4d18ff02162a2a7299c80c Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sun, 16 Oct 2011 21:20:20 +0300 Subject: [PATCH] print_pid_stats: Revert order of pageframe tree and process list are traversed The pageframe tree is usually quite big, in order of dozens of megabytes. The process list on the other hand is usually quite small, usually in the order of tens of kilobytes. The process list thus can fit entirely in L2 (or even in L1) cache whereas the pageframe tree most likely does not fit in any cache at all. Therefore, when calculating the pid statistics, walking through the page frame tree as many times as there are processes in the process list will likely cause very big traffic to the memory bus. Changing the ordering of the loops will significantly increase cache locality and reduce the memory bus traffic, decreasing the execution times a lot. Signed-off-by: Timo Kokkonen --- analyze.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/analyze.c b/analyze.c index 547a3ad..cd8d5db 100644 --- a/analyze.c +++ b/analyze.c @@ -225,34 +225,29 @@ void print_pid_stats(struct rb_root *root, struct process *process_list, { struct analyze_frames af; struct process *ps; + struct pageframe *pf; long int swapped, present, unique, total; long int biggest = 0, second_biggest; int count, processes = 0; - int len = 0, i; /* * walk through all processes, find the one with most present * pages */ - printf("\rAnalyzing pages for process: "); - list_for_each_entry(ps, &process_list->list, list) { - for (i = 0; i < len; i++) - putchar('\b'); - len = printf("% 5d", ps->pid); - fflush(stdout); - - memset(&af, 0, sizeof(af)); - af.pid = ps->pid; - - count_pages(root, &af); - ps->pages_present = af.pages_present; - ps->pages_swapped = af.pages_swapped; - ps->pages_unique = af.pages_unique; - biggest = MAX(biggest, ps->pages_present + ps->pages_swapped); + pf = rb_to_pageframe(rb_first(root)); + while(pf) { + list_for_each_entry(ps, &process_list->list, list) { + memset(&af, 0, sizeof(af)); + af.pid = ps->pid; + + count_page(pf, &af); + ps->pages_present += af.pages_present; + ps->pages_swapped += af.pages_swapped; + ps->pages_unique += af.pages_unique; + biggest = MAX(biggest, ps->pages_present + ps->pages_swapped); + } + pf = rb_to_pageframe(rb_next(&pf->tree)); } - for (i = 0; i < len; i++) - putchar('\b'); - printf("Done \n\n"); printf(" RSS swapped USS total pid"); if (opts->with_threads) -- 2.44.0