9 #define SI_M (SI_k * SI_k)
10 #define SI_G (SI_M * SI_k)
12 #define PRETTY_THRESH 100
14 ((a) < SI_k * PRETTY_THRESH ? (a) : \
15 (a < SI_M * PRETTY_THRESH ? ((a) / SI_k) : \
16 (a < SI_G * PRETTY_THRESH ? ((a) / SI_M) : \
19 #define NICE_UNIT(a) \
20 ((a) < (SI_k * PRETTY_THRESH) ? " " : \
21 ((a) < (SI_G * PRETTY_THRESH) ? "k" : \
22 ((a) < (SI_G * PRETTY_THRESH) ? "M" : "G")))
24 #define PAGE_TO_NICE(a) NICE_DIV((long long)a * PAGE_SIZE)
25 #define PAGE_TO_NICE_UNIT(a) NICE_UNIT((long long)a * PAGE_SIZE)
27 struct analyze_frames {
28 struct bintree_ops ops;
29 long int present_pages;
30 long int swapped_pages;
31 long int unused_pages;
34 #define bintree_ops_to_af(bintree_ops) \
35 container_of((bintree_ops), struct analyze_frames, ops)
37 static void count_pages(struct bintree *b, struct bintree_ops *ops)
39 struct pageframe *pf = tree_to_pageframe(b);
40 struct analyze_frames *af = bintree_ops_to_af(ops);
42 if (pf->page_present) {
43 af->present_pages += pf->refcount;
44 } else if (pf->page_swapped) {
45 af->swapped_pages += pf->refcount;
47 af->unused_pages += pf->refcount;
52 * print_page_stats - Prints system wide page stats
54 void print_page_stats(struct pageframe *pf)
56 struct analyze_frames af;
58 memset(&af, 0, sizeof(af));
60 af.ops.callback = count_pages;
62 count = bintree_walk(&pf->tree, &af.ops);
63 printf("present pages: %ld, %lld %sB\n"
64 "Swapped pages: %ld, %lld %sB\n"
65 "Unused pages: %ld, %lld %sB\n"
66 "Total %ld physical pages, %lld %sB\n",
68 PAGE_TO_NICE(af.present_pages),
69 PAGE_TO_NICE_UNIT(af.present_pages),
71 PAGE_TO_NICE(af.swapped_pages),
72 PAGE_TO_NICE_UNIT(af.swapped_pages),
74 PAGE_TO_NICE(af.unused_pages),
75 PAGE_TO_NICE_UNIT(af.unused_pages),
78 PAGE_TO_NICE_UNIT(count));
81 void print_pid_stats(struct pageframe *pf, struct process *process_list)
85 long int swapped, present;
87 printf(" in ram swapped pid name\n");
89 list_for_each_entry(ps, &process_list->list, list) {
90 swapped = present = 0;
93 list_for_each_entry(map, &ps->maps->list, list) {
94 present += map->pages_present;
95 swapped += map->pages_swapped;
98 if ((swapped + present) == 0)
101 printf("% 6lld %sB % 6lld %sB % 5d %s",
102 PAGE_TO_NICE(present), PAGE_TO_NICE_UNIT(present),
103 PAGE_TO_NICE(swapped), PAGE_TO_NICE_UNIT(swapped),