Lines Matching +full:0 +full:- +full:9 +full:a +full:- +full:fa +full:- +full:f
1 // SPDX-License-Identifier: GPL-2.0
16 #include "util/time-utils.h"
20 #include <subcmd/parse-options.h>
21 #include "util/trace-event.h"
54 static int alloc_lines = -1;
55 static int caller_lines = -1;
96 if (ptr > data->ptr) in insert_alloc_stat()
97 node = &(*node)->rb_right; in insert_alloc_stat()
98 else if (ptr < data->ptr) in insert_alloc_stat()
99 node = &(*node)->rb_left; in insert_alloc_stat()
104 if (data && data->ptr == ptr) { in insert_alloc_stat()
105 data->hit++; in insert_alloc_stat()
106 data->bytes_req += bytes_req; in insert_alloc_stat()
107 data->bytes_alloc += bytes_alloc; in insert_alloc_stat()
112 return -1; in insert_alloc_stat()
114 data->ptr = ptr; in insert_alloc_stat()
115 data->pingpong = 0; in insert_alloc_stat()
116 data->hit = 1; in insert_alloc_stat()
117 data->bytes_req = bytes_req; in insert_alloc_stat()
118 data->bytes_alloc = bytes_alloc; in insert_alloc_stat()
120 rb_link_node(&data->node, parent, node); in insert_alloc_stat()
121 rb_insert_color(&data->node, &root_alloc_stat); in insert_alloc_stat()
123 data->call_site = call_site; in insert_alloc_stat()
124 data->alloc_cpu = cpu; in insert_alloc_stat()
125 data->last_alloc = bytes_alloc; in insert_alloc_stat()
127 return 0; in insert_alloc_stat()
141 if (call_site > data->call_site) in insert_caller_stat()
142 node = &(*node)->rb_right; in insert_caller_stat()
143 else if (call_site < data->call_site) in insert_caller_stat()
144 node = &(*node)->rb_left; in insert_caller_stat()
149 if (data && data->call_site == call_site) { in insert_caller_stat()
150 data->hit++; in insert_caller_stat()
151 data->bytes_req += bytes_req; in insert_caller_stat()
152 data->bytes_alloc += bytes_alloc; in insert_caller_stat()
157 return -1; in insert_caller_stat()
159 data->call_site = call_site; in insert_caller_stat()
160 data->pingpong = 0; in insert_caller_stat()
161 data->hit = 1; in insert_caller_stat()
162 data->bytes_req = bytes_req; in insert_caller_stat()
163 data->bytes_alloc = bytes_alloc; in insert_caller_stat()
165 rb_link_node(&data->node, parent, node); in insert_caller_stat()
166 rb_insert_color(&data->node, &root_caller_stat); in insert_caller_stat()
169 return 0; in insert_caller_stat()
179 if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) || in evsel__process_alloc_event()
181 return -1; in evsel__process_alloc_event()
187 return 0; in evsel__process_alloc_event()
195 int node1 = cpu__get_node(sample->cpu), in evsel__process_alloc_node_event()
213 struct rb_node *node = root->rb_node; in search_alloc_stat()
223 if (cmp < 0) in search_alloc_stat()
224 node = node->rb_left; in search_alloc_stat()
225 else if (cmp > 0) in search_alloc_stat()
226 node = node->rb_right; in search_alloc_stat()
238 s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp); in evsel__process_free_event()
240 return 0; in evsel__process_free_event()
242 total_freed += s_alloc->last_alloc; in evsel__process_free_event()
244 if ((short)sample->cpu != s_alloc->alloc_cpu) { in evsel__process_free_event()
245 s_alloc->pingpong++; in evsel__process_free_event()
247 s_caller = search_alloc_stat(0, s_alloc->call_site, in evsel__process_free_event()
251 return -1; in evsel__process_free_event()
252 s_caller->pingpong++; in evsel__process_free_event()
254 s_alloc->alloc_cpu = -1; in evsel__process_free_event()
256 return 0; in evsel__process_free_event()
305 static int funcmp(const void *a, const void *b) in funcmp() argument
307 const struct alloc_func *fa = a; in funcmp() local
310 if (fa->start > fb->start) in funcmp()
313 return -1; in funcmp()
316 static int callcmp(const void *a, const void *b) in callcmp() argument
318 const struct alloc_func *fa = a; in callcmp() local
321 if (fb->start <= fa->start && fa->end < fb->end) in callcmp()
322 return 0; in callcmp()
324 if (fa->start > fb->start) in callcmp()
327 return -1; in callcmp()
337 struct machine *machine = &kmem_session->machines.host; in build_alloc_func_list()
347 return -EINVAL; in build_alloc_func_list()
351 if (map__load(kernel_map) < 0) { in build_alloc_func_list()
353 return -ENOENT; in build_alloc_func_list()
357 if (regexec(&alloc_func_regex, sym->name, 0, NULL, 0)) in build_alloc_func_list()
363 return -ENOMEM; in build_alloc_func_list()
365 pr_debug("alloc func: %s\n", sym->name); in build_alloc_func_list()
366 func[nr_alloc_funcs].start = sym->start; in build_alloc_func_list()
367 func[nr_alloc_funcs].end = sym->end; in build_alloc_func_list()
368 func[nr_alloc_funcs].name = sym->name; in build_alloc_func_list()
377 return 0; in build_alloc_func_list()
381 * Find first non-memory allocation function from callchain.
387 struct machine *machine = &kmem_session->machines.host; in find_callsite()
391 if (build_alloc_func_list() < 0) in find_callsite()
395 al.thread = machine__findnew_thread(machine, sample->pid, sample->tid); in find_callsite()
407 key.start = key.end = node->ip; in find_callsite()
412 if (node->ms.map) in find_callsite()
413 addr = map__unmap_ip(node->ms.map, node->ip); in find_callsite()
415 addr = node->ip; in find_callsite()
419 pr_debug3("skipping alloc function: %s\n", caller->name); in find_callsite()
425 pr_debug2("unknown callsite: %"PRIx64 "\n", sample->ip); in find_callsite()
426 return sample->ip; in find_callsite()
451 cmp = data->page - pstat->page; in __page_stat__findnew_page()
452 if (cmp < 0) in __page_stat__findnew_page()
453 node = &parent->rb_left; in __page_stat__findnew_page()
454 else if (cmp > 0) in __page_stat__findnew_page()
455 node = &parent->rb_right; in __page_stat__findnew_page()
465 data->page = pstat->page; in __page_stat__findnew_page()
466 data->order = pstat->order; in __page_stat__findnew_page()
467 data->gfp_flags = pstat->gfp_flags; in __page_stat__findnew_page()
468 data->migrate_type = pstat->migrate_type; in __page_stat__findnew_page()
470 rb_link_node(&data->node, parent, node); in __page_stat__findnew_page()
471 rb_insert_color(&data->node, &page_live_tree); in __page_stat__findnew_page()
496 int cmp = 0; in __page_stat__findnew_alloc()
502 cmp = sort->cmp(pstat, data); in __page_stat__findnew_alloc()
507 if (cmp < 0) in __page_stat__findnew_alloc()
508 node = &parent->rb_left; in __page_stat__findnew_alloc()
509 else if (cmp > 0) in __page_stat__findnew_alloc()
510 node = &parent->rb_right; in __page_stat__findnew_alloc()
520 data->page = pstat->page; in __page_stat__findnew_alloc()
521 data->order = pstat->order; in __page_stat__findnew_alloc()
522 data->gfp_flags = pstat->gfp_flags; in __page_stat__findnew_alloc()
523 data->migrate_type = pstat->migrate_type; in __page_stat__findnew_alloc()
525 rb_link_node(&data->node, parent, node); in __page_stat__findnew_alloc()
526 rb_insert_color(&data->node, &page_alloc_tree); in __page_stat__findnew_alloc()
551 int cmp = 0; in __page_stat__findnew_caller()
557 cmp = sort->cmp(pstat, data); in __page_stat__findnew_caller()
562 if (cmp < 0) in __page_stat__findnew_caller()
563 node = &parent->rb_left; in __page_stat__findnew_caller()
564 else if (cmp > 0) in __page_stat__findnew_caller()
565 node = &parent->rb_right; in __page_stat__findnew_caller()
575 data->callsite = pstat->callsite; in __page_stat__findnew_caller()
576 data->order = pstat->order; in __page_stat__findnew_caller()
577 data->gfp_flags = pstat->gfp_flags; in __page_stat__findnew_caller()
578 data->migrate_type = pstat->migrate_type; in __page_stat__findnew_caller()
580 rb_link_node(&data->node, parent, node); in __page_stat__findnew_caller()
581 rb_insert_color(&data->node, &page_caller_tree); in __page_stat__findnew_caller()
599 if (use_pfn && pfn_or_page == -1UL) in valid_page()
601 if (!use_pfn && pfn_or_page == 0) in valid_page()
615 static int gfpcmp(const void *a, const void *b) in gfpcmp() argument
617 const struct gfp_flag *fa = a; in gfpcmp() local
620 return fa->flags - fb->flags; in gfpcmp()
636 { "GFP_ATOMIC", "A" },
645 { "__GFP_FS", "F" },
672 size_t len = 0; in compact_gfp_flags()
683 for (i = 0; i < ARRAY_SIZE(gfp_compact_table); i++) { in compact_gfp_flags()
727 return gfp->compact_str; in compact_gfp_string()
736 .cpu = sample->cpu, in parse_gfp_flags()
737 .data = sample->raw_data, in parse_gfp_flags()
738 .size = sample->raw_size, in parse_gfp_flags()
749 return 0; in parse_gfp_flags()
753 tep_print_event(evsel->tp_format->tep, in parse_gfp_flags()
763 return -ENOMEM; in parse_gfp_flags()
768 new->flags = gfp_flags; in parse_gfp_flags()
769 new->human_readable = strdup(str + 10); in parse_gfp_flags()
770 new->compact_str = compact_gfp_flags(str + 10); in parse_gfp_flags()
771 if (!new->human_readable || !new->compact_str) in parse_gfp_flags()
772 return -ENOMEM; in parse_gfp_flags()
781 return 0; in parse_gfp_flags()
812 return 0; in evsel__process_page_alloc_event()
815 if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) in evsel__process_page_alloc_event()
816 return -1; in evsel__process_page_alloc_event()
827 return -ENOMEM; in evsel__process_page_alloc_event()
829 pstat->nr_alloc++; in evsel__process_page_alloc_event()
830 pstat->alloc_bytes += bytes; in evsel__process_page_alloc_event()
831 pstat->callsite = callsite; in evsel__process_page_alloc_event()
836 return -ENOMEM; in evsel__process_page_alloc_event()
838 pstat->nr_alloc++; in evsel__process_page_alloc_event()
839 pstat->alloc_bytes += bytes; in evsel__process_page_alloc_event()
840 pstat->callsite = callsite; in evsel__process_page_alloc_event()
846 return -ENOMEM; in evsel__process_page_alloc_event()
848 pstat->nr_alloc++; in evsel__process_page_alloc_event()
849 pstat->alloc_bytes += bytes; in evsel__process_page_alloc_event()
853 return 0; in evsel__process_page_alloc_event()
883 return 0; in evsel__process_page_free_event()
886 this.gfp_flags = pstat->gfp_flags; in evsel__process_page_free_event()
887 this.migrate_type = pstat->migrate_type; in evsel__process_page_free_event()
888 this.callsite = pstat->callsite; in evsel__process_page_free_event()
890 rb_erase(&pstat->node, &page_live_tree); in evsel__process_page_free_event()
894 order_stats[this.order][this.migrate_type]--; in evsel__process_page_free_event()
898 return -ENOMEM; in evsel__process_page_free_event()
900 pstat->nr_free++; in evsel__process_page_free_event()
901 pstat->free_bytes += bytes; in evsel__process_page_free_event()
906 return -ENOENT; in evsel__process_page_free_event()
908 pstat->nr_free++; in evsel__process_page_free_event()
909 pstat->free_bytes += bytes; in evsel__process_page_free_event()
912 pstat->nr_alloc--; in evsel__process_page_free_event()
913 pstat->alloc_bytes -= bytes; in evsel__process_page_free_event()
915 if (pstat->nr_alloc == 0) { in evsel__process_page_free_event()
916 rb_erase(&pstat->node, &page_caller_tree); in evsel__process_page_free_event()
921 return 0; in evsel__process_page_free_event()
927 if (perf_time__skip_sample(&ptime, sample->time)) in perf_kmem__skip_sample()
942 int err = 0; in process_sample_event()
943 struct thread *thread = machine__findnew_thread(machine, sample->pid, in process_sample_event()
944 sample->tid); in process_sample_event()
948 event->header.type); in process_sample_event()
949 return -1; in process_sample_event()
953 return 0; in process_sample_event()
955 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid); in process_sample_event()
957 if (evsel->handler != NULL) { in process_sample_event()
958 tracepoint_handler f = evsel->handler; in process_sample_event() local
959 err = f(evsel, sample); in process_sample_event()
978 if (n_alloc == 0) in fragmentation()
981 return 100.0 - (100.0 * n_req / n_alloc); in fragmentation()
989 struct machine *machine = &session->machines.host; in __print_slab_result()
992 printf(" %-34s |", is_caller ? "Callsite": "Alloc Ptr"); in __print_slab_result()
993 printf(" Total_alloc/Per | Total_req/Per | Hit | Ping-pong | Frag\n"); in __print_slab_result()
998 while (next && n_lines--) { in __print_slab_result()
1007 addr = data->call_site; in __print_slab_result()
1011 addr = data->ptr; in __print_slab_result()
1014 snprintf(buf, sizeof(buf), "%s+%" PRIx64 "", sym->name, in __print_slab_result()
1015 addr - map->unmap_ip(map, sym->start)); in __print_slab_result()
1018 printf(" %-34s |", buf); in __print_slab_result()
1020 printf(" %9llu/%-5lu | %9llu/%-5lu | %8lu | %9lu | %6.3f%%\n", in __print_slab_result()
1021 (unsigned long long)data->bytes_alloc, in __print_slab_result()
1022 (unsigned long)data->bytes_alloc / data->hit, in __print_slab_result()
1023 (unsigned long long)data->bytes_req, in __print_slab_result()
1024 (unsigned long)data->bytes_req / data->hit, in __print_slab_result()
1025 (unsigned long)data->hit, in __print_slab_result()
1026 (unsigned long)data->pingpong, in __print_slab_result()
1027 fragmentation(data->bytes_req, data->bytes_alloc)); in __print_slab_result()
1032 if (n_lines == -1) in __print_slab_result()
1050 struct machine *machine = &session->machines.host; in __print_page_alloc_result()
1055 printf(" %-16s | %5s alloc (KB) | Hits | Order | Mig.type | %-*s | Callsite\n", in __print_page_alloc_result()
1061 format = " %16llu | %'16llu | %'9d | %5d | %8s | %-*s | %s\n"; in __print_page_alloc_result()
1063 format = " %016llx | %'16llu | %'9d | %5d | %8s | %-*s | %s\n"; in __print_page_alloc_result()
1065 while (next && n_lines--) { in __print_page_alloc_result()
1073 sym = machine__find_kernel_symbol(machine, data->callsite, &map); in __print_page_alloc_result()
1075 caller = sym->name; in __print_page_alloc_result()
1077 scnprintf(buf, sizeof(buf), "%"PRIx64, data->callsite); in __print_page_alloc_result()
1079 printf(format, (unsigned long long)data->page, in __print_page_alloc_result()
1080 (unsigned long long)data->alloc_bytes / 1024, in __print_page_alloc_result()
1081 data->nr_alloc, data->order, in __print_page_alloc_result()
1082 migrate_type_str[data->migrate_type], in __print_page_alloc_result()
1083 gfp_len, compact_gfp_string(data->gfp_flags), caller); in __print_page_alloc_result()
1088 if (n_lines == -1) { in __print_page_alloc_result()
1089 printf(" ... | ... | ... | ... | ... | %-*s | ...\n", in __print_page_alloc_result()
1099 struct machine *machine = &session->machines.host; in __print_page_caller_result()
1103 printf(" %5s alloc (KB) | Hits | Order | Mig.type | %-*s | Callsite\n", in __print_page_caller_result()
1107 while (next && n_lines--) { in __print_page_caller_result()
1115 sym = machine__find_kernel_symbol(machine, data->callsite, &map); in __print_page_caller_result()
1117 caller = sym->name; in __print_page_caller_result()
1119 scnprintf(buf, sizeof(buf), "%"PRIx64, data->callsite); in __print_page_caller_result()
1121 printf(" %'16llu | %'9d | %5d | %8s | %-*s | %s\n", in __print_page_caller_result()
1122 (unsigned long long)data->alloc_bytes / 1024, in __print_page_caller_result()
1123 data->nr_alloc, data->order, in __print_page_caller_result()
1124 migrate_type_str[data->migrate_type], in __print_page_caller_result()
1125 gfp_len, compact_gfp_string(data->gfp_flags), caller); in __print_page_caller_result()
1130 if (n_lines == -1) { in __print_page_caller_result()
1131 printf(" ... | ... | ... | ... | %-*s | ...\n", in __print_page_caller_result()
1144 printf("# ---------\n"); in print_gfp_flags()
1145 for (i = 0; i < nr_gfps; i++) { in print_gfp_flags()
1161 total_allocated - total_freed); in print_slab_summary()
1164 total_allocated - total_requested); in print_slab_summary()
1165 printf("Internal fragmentation: %f%%\n", in print_slab_summary()
1173 u64 nr_alloc_freed = nr_page_frees - nr_page_nomatch; in print_page_summary()
1174 u64 total_alloc_freed_bytes = total_page_free_bytes - total_page_nomatch_bytes; in print_page_summary()
1178 printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total allocation requests", in print_page_summary()
1180 printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total free requests", in print_page_summary()
1184 printf("%-30s: %'16"PRIu64" [ %'16"PRIu64" KB ]\n", "Total alloc+freed requests", in print_page_summary()
1186 printf("%-30s: %'16"PRIu64" [ %'16"PRIu64" KB ]\n", "Total alloc-only requests", in print_page_summary()
1187 nr_page_allocs - nr_alloc_freed, in print_page_summary()
1188 (total_page_alloc_bytes - total_alloc_freed_bytes) / 1024); in print_page_summary()
1189 printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total free-only requests", in print_page_summary()
1193 printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total allocation failures", in print_page_summary()
1203 for (o = 0; o < MAX_PAGE_ORDER; o++) { in print_page_summary()
1205 for (m = 0; m < MAX_MIGRATE_TYPES - 1; m++) { in print_page_summary()
1220 __print_slab_result(&root_alloc_sorted, session, alloc_lines, 0); in print_slab_result()
1251 struct rb_node **new = &(root->rb_node); in sort_slab_insert()
1257 int cmp = 0; in sort_slab_insert()
1263 cmp = sort->cmp(data, this); in sort_slab_insert()
1268 if (cmp > 0) in sort_slab_insert()
1269 new = &((*new)->rb_left); in sort_slab_insert()
1271 new = &((*new)->rb_right); in sort_slab_insert()
1274 rb_link_node(&data->node, parent, new); in sort_slab_insert()
1275 rb_insert_color(&data->node, root); in sort_slab_insert()
1298 struct rb_node **new = &root->rb_node; in sort_page_insert()
1304 int cmp = 0; in sort_page_insert()
1310 cmp = sort->cmp(data, this); in sort_page_insert()
1315 if (cmp > 0) in sort_page_insert()
1316 new = &parent->rb_left; in sort_page_insert()
1318 new = &parent->rb_right; in sort_page_insert()
1321 rb_link_node(&data->node, parent, new); in sort_page_insert()
1322 rb_insert_color(&data->node, root); in sort_page_insert()
1365 int err = -EINVAL; in __cmd_kmem()
1388 evlist__for_each_entry(session->evlist, evsel) { in __cmd_kmem()
1398 if (err != 0) { in __cmd_kmem()
1409 static int ptr_cmp(void *a, void *b) in ptr_cmp() argument
1411 struct alloc_stat *l = a; in ptr_cmp()
1414 if (l->ptr < r->ptr) in ptr_cmp()
1415 return -1; in ptr_cmp()
1416 else if (l->ptr > r->ptr) in ptr_cmp()
1418 return 0; in ptr_cmp()
1426 static int slab_callsite_cmp(void *a, void *b) in slab_callsite_cmp() argument
1428 struct alloc_stat *l = a; in slab_callsite_cmp()
1431 if (l->call_site < r->call_site) in slab_callsite_cmp()
1432 return -1; in slab_callsite_cmp()
1433 else if (l->call_site > r->call_site) in slab_callsite_cmp()
1435 return 0; in slab_callsite_cmp()
1443 static int hit_cmp(void *a, void *b) in hit_cmp() argument
1445 struct alloc_stat *l = a; in hit_cmp()
1448 if (l->hit < r->hit) in hit_cmp()
1449 return -1; in hit_cmp()
1450 else if (l->hit > r->hit) in hit_cmp()
1452 return 0; in hit_cmp()
1460 static int bytes_cmp(void *a, void *b) in bytes_cmp() argument
1462 struct alloc_stat *l = a; in bytes_cmp()
1465 if (l->bytes_alloc < r->bytes_alloc) in bytes_cmp()
1466 return -1; in bytes_cmp()
1467 else if (l->bytes_alloc > r->bytes_alloc) in bytes_cmp()
1469 return 0; in bytes_cmp()
1477 static int frag_cmp(void *a, void *b) in frag_cmp() argument
1480 struct alloc_stat *l = a; in frag_cmp()
1483 x = fragmentation(l->bytes_req, l->bytes_alloc); in frag_cmp()
1484 y = fragmentation(r->bytes_req, r->bytes_alloc); in frag_cmp()
1487 return -1; in frag_cmp()
1490 return 0; in frag_cmp()
1498 static int pingpong_cmp(void *a, void *b) in pingpong_cmp() argument
1500 struct alloc_stat *l = a; in pingpong_cmp()
1503 if (l->pingpong < r->pingpong) in pingpong_cmp()
1504 return -1; in pingpong_cmp()
1505 else if (l->pingpong > r->pingpong) in pingpong_cmp()
1507 return 0; in pingpong_cmp()
1516 static int page_cmp(void *a, void *b) in page_cmp() argument
1518 struct page_stat *l = a; in page_cmp()
1521 if (l->page < r->page) in page_cmp()
1522 return -1; in page_cmp()
1523 else if (l->page > r->page) in page_cmp()
1525 return 0; in page_cmp()
1533 static int page_callsite_cmp(void *a, void *b) in page_callsite_cmp() argument
1535 struct page_stat *l = a; in page_callsite_cmp()
1538 if (l->callsite < r->callsite) in page_callsite_cmp()
1539 return -1; in page_callsite_cmp()
1540 else if (l->callsite > r->callsite) in page_callsite_cmp()
1542 return 0; in page_callsite_cmp()
1550 static int page_hit_cmp(void *a, void *b) in page_hit_cmp() argument
1552 struct page_stat *l = a; in page_hit_cmp()
1555 if (l->nr_alloc < r->nr_alloc) in page_hit_cmp()
1556 return -1; in page_hit_cmp()
1557 else if (l->nr_alloc > r->nr_alloc) in page_hit_cmp()
1559 return 0; in page_hit_cmp()
1567 static int page_bytes_cmp(void *a, void *b) in page_bytes_cmp() argument
1569 struct page_stat *l = a; in page_bytes_cmp()
1572 if (l->alloc_bytes < r->alloc_bytes) in page_bytes_cmp()
1573 return -1; in page_bytes_cmp()
1574 else if (l->alloc_bytes > r->alloc_bytes) in page_bytes_cmp()
1576 return 0; in page_bytes_cmp()
1584 static int page_order_cmp(void *a, void *b) in page_order_cmp() argument
1586 struct page_stat *l = a; in page_order_cmp()
1589 if (l->order < r->order) in page_order_cmp()
1590 return -1; in page_order_cmp()
1591 else if (l->order > r->order) in page_order_cmp()
1593 return 0; in page_order_cmp()
1601 static int migrate_type_cmp(void *a, void *b) in migrate_type_cmp() argument
1603 struct page_stat *l = a; in migrate_type_cmp()
1607 if (l->migrate_type == -1U) in migrate_type_cmp()
1608 return 0; in migrate_type_cmp()
1610 if (l->migrate_type < r->migrate_type) in migrate_type_cmp()
1611 return -1; in migrate_type_cmp()
1612 else if (l->migrate_type > r->migrate_type) in migrate_type_cmp()
1614 return 0; in migrate_type_cmp()
1622 static int gfp_flags_cmp(void *a, void *b) in gfp_flags_cmp() argument
1624 struct page_stat *l = a; in gfp_flags_cmp()
1628 if (l->gfp_flags == -1U) in gfp_flags_cmp()
1629 return 0; in gfp_flags_cmp()
1631 if (l->gfp_flags < r->gfp_flags) in gfp_flags_cmp()
1632 return -1; in gfp_flags_cmp()
1633 else if (l->gfp_flags > r->gfp_flags) in gfp_flags_cmp()
1635 return 0; in gfp_flags_cmp()
1667 for (i = 0; i < (int)ARRAY_SIZE(slab_sorts); i++) { in slab_sort_dimension__add()
1668 if (!strcmp(slab_sorts[i]->name, tok)) { in slab_sort_dimension__add()
1672 return -1; in slab_sort_dimension__add()
1674 list_add_tail(&sort->list, list); in slab_sort_dimension__add()
1675 return 0; in slab_sort_dimension__add()
1679 return -1; in slab_sort_dimension__add()
1687 for (i = 0; i < (int)ARRAY_SIZE(page_sorts); i++) { in page_sort_dimension__add()
1688 if (!strcmp(page_sorts[i]->name, tok)) { in page_sort_dimension__add()
1692 return -1; in page_sort_dimension__add()
1694 list_add_tail(&sort->list, list); in page_sort_dimension__add()
1695 return 0; in page_sort_dimension__add()
1699 return -1; in page_sort_dimension__add()
1710 return -1; in setup_slab_sorting()
1717 if (slab_sort_dimension__add(tok, sort_list) < 0) { in setup_slab_sorting()
1718 pr_err("Unknown slab --sort key: '%s'", tok); in setup_slab_sorting()
1720 return -1; in setup_slab_sorting()
1725 return 0; in setup_slab_sorting()
1736 return -1; in setup_page_sorting()
1743 if (page_sort_dimension__add(tok, sort_list) < 0) { in setup_page_sorting()
1744 pr_err("Unknown page --sort key: '%s'", tok); in setup_page_sorting()
1746 return -1; in setup_page_sorting()
1751 return 0; in setup_page_sorting()
1758 return -1; in parse_sort_opt()
1761 (kmem_page == 0 && kmem_slab == 0 && kmem_default == KMEM_PAGE)) { in parse_sort_opt()
1773 return 0; in parse_sort_opt()
1781 return 0; in parse_caller_opt()
1789 return 0; in parse_alloc_opt()
1797 return 0; in parse_slab_opt()
1805 return 0; in parse_page_opt()
1814 return -1; in parse_line_opt()
1823 return 0; in parse_line_opt()
1829 "record", "-a", "-R", "-c", "1", in __cmd_record()
1832 "-e", "kmem:kmalloc", in __cmd_record()
1833 "-e", "kmem:kmalloc_node", in __cmd_record()
1834 "-e", "kmem:kfree", in __cmd_record()
1835 "-e", "kmem:kmem_cache_alloc", in __cmd_record()
1836 "-e", "kmem:kmem_cache_alloc_node", in __cmd_record()
1837 "-e", "kmem:kmem_cache_free", in __cmd_record()
1840 "-e", "kmem:mm_page_alloc", in __cmd_record()
1841 "-e", "kmem:mm_page_free", in __cmd_record()
1846 rec_argc = ARRAY_SIZE(record_args) + argc - 1; in __cmd_record()
1850 rec_argc += ARRAY_SIZE(page_events) + 1; /* for -g */ in __cmd_record()
1855 return -ENOMEM; in __cmd_record()
1857 for (i = 0; i < ARRAY_SIZE(record_args); i++) in __cmd_record()
1861 for (j = 0; j < ARRAY_SIZE(slab_events); j++, i++) in __cmd_record()
1865 rec_argv[i++] = strdup("-g"); in __cmd_record()
1867 for (j = 0; j < ARRAY_SIZE(page_events); j++, i++) in __cmd_record()
1887 return 0; in kmem_config()
1890 return 0; in kmem_config()
1904 OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL, in cmd_kmem()
1905 "show per-callsite statistics", parse_caller_opt), in cmd_kmem()
1906 OPT_CALLBACK_NOOPT(0, "alloc", NULL, NULL, in cmd_kmem()
1907 "show per-allocation statistics", parse_alloc_opt), in cmd_kmem()
1912 OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"), in cmd_kmem()
1913 OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"), in cmd_kmem()
1914 OPT_CALLBACK_NOOPT(0, "slab", NULL, NULL, "Analyze slab allocator", in cmd_kmem()
1916 OPT_CALLBACK_NOOPT(0, "page", NULL, NULL, "Analyze page allocator", in cmd_kmem()
1918 OPT_BOOLEAN(0, "live", &live_page, "Show live page stat"), in cmd_kmem()
1919 OPT_STRING(0, "time", &time_str, "str", in cmd_kmem()
1929 …static const char errmsg[] = "No %s allocation events found. Have you run 'perf kmem record --%s'… in cmd_kmem()
1942 if (kmem_slab == 0 && kmem_page == 0) { in cmd_kmem()
1949 if (!strncmp(argv[0], "rec", 3)) { in cmd_kmem()
1960 ret = -1; in cmd_kmem()
1963 if (!perf_evlist__find_tracepoint_by_name(session->evlist, in cmd_kmem()
1973 evsel = perf_evlist__find_tracepoint_by_name(session->evlist, in cmd_kmem()
1980 kmem_page_size = tep_get_page_size(evsel->tp_format->tep); in cmd_kmem()
1984 symbol__init(&session->header.env); in cmd_kmem()
1986 if (perf_time__parse_str(&ptime, time_str) != 0) { in cmd_kmem()
1988 ret = -EINVAL; in cmd_kmem()
1992 if (!strcmp(argv[0], "stat")) { in cmd_kmem()