Lines Matching refs:kp
62 static int read_pages(struct ksm_pages *kp, pm_map_t **maps, size_t num_maps, uint8_t pr_flags);
63 static void print_pages(struct ksm_pages *kp, uint8_t pr_flags);
64 static void free_pages(struct ksm_pages *kp, uint8_t pr_flags);
81 struct ksm_pages kp; in main() local
83 memset(&kp, 0, sizeof(kp)); in main()
168 if (read_pages(&kp, maps, num_maps, pr_flags) < 0) { in main()
180 qsort(kp.pages, kp.len, sizeof(*kp.pages), cmp_pages); in main()
182 print_pages(&kp, pr_flags); in main()
185 free_pages(&kp, pr_flags); in main()
190 static int read_pages(struct ksm_pages *kp, pm_map_t **maps, size_t num_maps, uint8_t pr_flags) { in read_pages() argument
261 for (k = 0; k < kp->len; k++) { in read_pages()
262 if (kp->pages[k].hash == hash) break; in read_pages()
265 if (k == kp->len) { in read_pages()
266 if (kp->len == kp->size) { in read_pages()
267 struct ksm_page *tmp = realloc(kp->pages, in read_pages()
268 (kp->size + GROWTH_FACTOR) * sizeof(*kp->pages)); in read_pages()
276 kp->pages = tmp; in read_pages()
277 kp->size += GROWTH_FACTOR; in read_pages()
279 rc = pm_kernel_count(ker, PM_PAGEMAP_PFN(pagemap[j]), &kp->pages[kp->len].count); in read_pages()
285 kp->pages[kp->len].hash = hash; in read_pages()
286 kp->pages[kp->len].pattern = in read_pages()
289 kp->len++; in read_pages()
292 cur_page = &kp->pages[k]; in read_pages()
330 for (i = 0; i < kp->len; i++) { in read_pages()
331 free(kp->pages[i].vaddr); in read_pages()
334 free(kp->pages); in read_pages()
343 static void print_pages(struct ksm_pages *kp, uint8_t pr_flags) { in print_pages() argument
348 for (i = 0; i < kp->len; i++) { in print_pages()
349 if (kp->pages[i].pattern != NO_PATTERN) { in print_pages()
350 printf("0x%02x byte pattern: ", kp->pages[i].pattern); in print_pages()
352 printf("KSM CRC 0x%08x:", kp->pages[i].hash); in print_pages()
354 printf(" %4zu page", kp->pages[i].vaddr_count); in print_pages()
355 if (kp->pages[i].vaddr_count > 1) { in print_pages()
359 printf(" (%" PRIu64 " reference", kp->pages[i].count); in print_pages()
360 if (kp->pages[i].count > 1) { in print_pages()
369 while (j < kp->pages[i].vaddr_len) { in print_pages()
371 for (k = 0; k < 8 && j < kp->pages[i].vaddr_len; k++, j++) { in print_pages()
372 printf(" 0x%08lx", kp->pages[i].vaddr[j].addr); in print_pages()
375 kp->pages[i].vaddr[j].num_pages); in print_pages()
378 kp->pages[i].vaddr[j].pid); in print_pages()
388 static void free_pages(struct ksm_pages *kp, uint8_t pr_flags) { in free_pages() argument
392 for (i = 0; i < kp->len; i++) { in free_pages()
393 free(kp->pages[i].vaddr); in free_pages()
396 free(kp->pages); in free_pages()