]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
print_pid_stats: Revert order of pageframe tree and process list are traversed
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 16 Oct 2011 18:20:20 +0000 (21:20 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 16 Oct 2011 18:20:20 +0000 (21:20 +0300)
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 <kaapeli@itanic.dy.fi>
analyze.c

index 547a3add74a7c64289006988bb6e51d30cc916bc..cd8d5db4aa2ccbe90311f9a02c78835d513c8164 100644 (file)
--- 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 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;
        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
         */
 
        /*
         * 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)
 
        printf("     RSS  swapped      USS    total   pid");
        if (opts->with_threads)