#include #include #include #include #include #include #include #include "pagemap.h" int main(int argc, char *argv[]) { static char kpageflags_name[] = "/proc/kpageflags"; unsigned long i; uint64_t flags; int fd; fd = open(kpageflags_name, O_RDONLY); if (fd < 0) { perror(kpageflags_name); exit(1); } nr_pages = read(fd, kpageflags, sizeof(kpageflags)); if (nr_pages <= 0) { perror(kpageflags_name); exit(2); } if (nr_pages % KPF_BYTES != 0) { fprintf(stderr, "%s: partial read: %lu bytes\n", argv[0], nr_pages); exit(3); } nr_pages = nr_pages / KPF_BYTES; for (i = 0; i < nr_pages; i++) { flags = kpageflags[i]; if (flags >= ARRAY_SIZE(page_count)) { static int warned = 0; if (!warned) { warned = 1; fprintf(stderr, "%s: flags overflow: 0x%lx >= 0x%lx\n", argv[0], flags, ARRAY_SIZE(page_count)); fprintf(stderr, "Either the kernel is buggy(<=2.6.28), " "or I'm too old to recognize new flags.\n\n"); } flags = ARRAY_SIZE(page_count) - 1; } page_count[flags]++; } #if 0 for (i = 0; i < ARRAY_SIZE(page_flag_names); i++) { printf("%s ", page_flag_names[i]); } #endif printf(" flags\tpage-count MB symbolic-flags long-symbolic-flags\n"); for (i = 0; i < ARRAY_SIZE(page_count); i++) { if (page_count[i]) printf("0x%06lx\t%10lu %8lu %s %s\n", i, page_count[i], pages2mb(page_count[i]), page_flag_name(i), page_flag_longname(i)); } printf(" total\t%10lu %8lu\n", nr_pages, pages2mb(nr_pages)); return 0; }