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>
{
struct analyze_frames af;
struct process *ps;
{
struct analyze_frames af;
struct process *ps;
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;
/*
* 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)