Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 2 | #include "builtin.h" |
| 3 | #include "perf.h" |
| 4 | |
Arnaldo Carvalho de Melo | 4a3cec8 | 2019-08-30 11:11:01 -0300 | [diff] [blame] | 5 | #include "util/dso.h" |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 6 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | fcf65bf | 2012-08-07 09:58:03 -0300 | [diff] [blame] | 7 | #include "util/evsel.h" |
Taeung Song | 41840d2 | 2016-06-23 17:55:17 +0900 | [diff] [blame] | 8 | #include "util/config.h" |
Arnaldo Carvalho de Melo | 1101f69 | 2019-01-27 13:42:37 +0100 | [diff] [blame] | 9 | #include "util/map.h" |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 10 | #include "util/symbol.h" |
| 11 | #include "util/thread.h" |
| 12 | #include "util/header.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 13 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 14 | #include "util/tool.h" |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 15 | #include "util/callchain.h" |
David Ahern | 2a865bd | 2016-11-29 10:15:45 -0700 | [diff] [blame] | 16 | #include "util/time-utils.h" |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 17 | |
Arnaldo Carvalho de Melo | 8520a98 | 2019-08-29 16:18:59 -0300 | [diff] [blame] | 18 | #include <subcmd/pager.h> |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 19 | #include <subcmd/parse-options.h> |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 20 | #include "util/trace-event.h" |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 21 | #include "util/data.h" |
Don Zickus | 4b62795 | 2014-04-07 14:55:23 -0400 | [diff] [blame] | 22 | #include "util/cpumap.h" |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 23 | |
| 24 | #include "util/debug.h" |
Arnaldo Carvalho de Melo | 6a9fa4e | 2019-06-25 17:31:26 -0300 | [diff] [blame] | 25 | #include "util/string2.h" |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 26 | |
Arnaldo Carvalho de Melo | 877a7a1 | 2017-04-17 11:39:06 -0300 | [diff] [blame] | 27 | #include <linux/kernel.h> |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 28 | #include <linux/rbtree.h> |
Arnaldo Carvalho de Melo | 8d9233f | 2013-01-24 22:24:57 -0300 | [diff] [blame] | 29 | #include <linux/string.h> |
Arnaldo Carvalho de Melo | 7f7c536 | 2019-07-04 11:32:27 -0300 | [diff] [blame] | 30 | #include <linux/zalloc.h> |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 31 | #include <errno.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 32 | #include <inttypes.h> |
Namhyung Kim | 77cfe38 | 2015-03-23 15:30:40 +0900 | [diff] [blame] | 33 | #include <locale.h> |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 34 | #include <regex.h> |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 35 | |
Arnaldo Carvalho de Melo | 3052ba5 | 2019-06-25 17:27:31 -0300 | [diff] [blame] | 36 | #include <linux/ctype.h> |
Arnaldo Carvalho de Melo | 3d689ed | 2017-04-17 16:10:49 -0300 | [diff] [blame] | 37 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 38 | static int kmem_slab; |
| 39 | static int kmem_page; |
| 40 | |
| 41 | static long kmem_page_size; |
Namhyung Kim | 0c160d4 | 2015-04-21 13:55:06 +0900 | [diff] [blame] | 42 | static enum { |
| 43 | KMEM_SLAB, |
| 44 | KMEM_PAGE, |
| 45 | } kmem_default = KMEM_SLAB; /* for backward compatibility */ |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 46 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 47 | struct alloc_stat; |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 48 | typedef int (*sort_fn_t)(void *, void *); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 49 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 50 | static int alloc_flag; |
| 51 | static int caller_flag; |
| 52 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 53 | static int alloc_lines = -1; |
| 54 | static int caller_lines = -1; |
| 55 | |
Li Zefan | 7707b6b | 2009-11-24 13:25:48 +0800 | [diff] [blame] | 56 | static bool raw_ip; |
| 57 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 58 | struct alloc_stat { |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 59 | u64 call_site; |
| 60 | u64 ptr; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 61 | u64 bytes_req; |
| 62 | u64 bytes_alloc; |
David Ahern | aa58e9a | 2016-11-25 14:42:13 -0700 | [diff] [blame] | 63 | u64 last_alloc; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 64 | u32 hit; |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 65 | u32 pingpong; |
| 66 | |
| 67 | short alloc_cpu; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 68 | |
| 69 | struct rb_node node; |
| 70 | }; |
| 71 | |
| 72 | static struct rb_root root_alloc_stat; |
| 73 | static struct rb_root root_alloc_sorted; |
| 74 | static struct rb_root root_caller_stat; |
| 75 | static struct rb_root root_caller_sorted; |
| 76 | |
David Ahern | aa58e9a | 2016-11-25 14:42:13 -0700 | [diff] [blame] | 77 | static unsigned long total_requested, total_allocated, total_freed; |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 78 | static unsigned long nr_allocs, nr_cross_allocs; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 79 | |
David Ahern | 2a865bd | 2016-11-29 10:15:45 -0700 | [diff] [blame] | 80 | /* filters for controlling start and stop of time of analysis */ |
| 81 | static struct perf_time_interval ptime; |
| 82 | const char *time_str; |
| 83 | |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 84 | static int insert_alloc_stat(unsigned long call_site, unsigned long ptr, |
| 85 | int bytes_req, int bytes_alloc, int cpu) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 86 | { |
| 87 | struct rb_node **node = &root_alloc_stat.rb_node; |
| 88 | struct rb_node *parent = NULL; |
| 89 | struct alloc_stat *data = NULL; |
| 90 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 91 | while (*node) { |
| 92 | parent = *node; |
| 93 | data = rb_entry(*node, struct alloc_stat, node); |
| 94 | |
| 95 | if (ptr > data->ptr) |
| 96 | node = &(*node)->rb_right; |
| 97 | else if (ptr < data->ptr) |
| 98 | node = &(*node)->rb_left; |
| 99 | else |
| 100 | break; |
| 101 | } |
| 102 | |
| 103 | if (data && data->ptr == ptr) { |
| 104 | data->hit++; |
| 105 | data->bytes_req += bytes_req; |
Wenji Huang | 4efb529 | 2009-12-21 17:52:55 +0800 | [diff] [blame] | 106 | data->bytes_alloc += bytes_alloc; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 107 | } else { |
| 108 | data = malloc(sizeof(*data)); |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 109 | if (!data) { |
| 110 | pr_err("%s: malloc failed\n", __func__); |
| 111 | return -1; |
| 112 | } |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 113 | data->ptr = ptr; |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 114 | data->pingpong = 0; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 115 | data->hit = 1; |
| 116 | data->bytes_req = bytes_req; |
| 117 | data->bytes_alloc = bytes_alloc; |
| 118 | |
| 119 | rb_link_node(&data->node, parent, node); |
| 120 | rb_insert_color(&data->node, &root_alloc_stat); |
| 121 | } |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 122 | data->call_site = call_site; |
| 123 | data->alloc_cpu = cpu; |
David Ahern | aa58e9a | 2016-11-25 14:42:13 -0700 | [diff] [blame] | 124 | data->last_alloc = bytes_alloc; |
| 125 | |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 126 | return 0; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 127 | } |
| 128 | |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 129 | static int insert_caller_stat(unsigned long call_site, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 130 | int bytes_req, int bytes_alloc) |
| 131 | { |
| 132 | struct rb_node **node = &root_caller_stat.rb_node; |
| 133 | struct rb_node *parent = NULL; |
| 134 | struct alloc_stat *data = NULL; |
| 135 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 136 | while (*node) { |
| 137 | parent = *node; |
| 138 | data = rb_entry(*node, struct alloc_stat, node); |
| 139 | |
| 140 | if (call_site > data->call_site) |
| 141 | node = &(*node)->rb_right; |
| 142 | else if (call_site < data->call_site) |
| 143 | node = &(*node)->rb_left; |
| 144 | else |
| 145 | break; |
| 146 | } |
| 147 | |
| 148 | if (data && data->call_site == call_site) { |
| 149 | data->hit++; |
| 150 | data->bytes_req += bytes_req; |
Wenji Huang | 4efb529 | 2009-12-21 17:52:55 +0800 | [diff] [blame] | 151 | data->bytes_alloc += bytes_alloc; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 152 | } else { |
| 153 | data = malloc(sizeof(*data)); |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 154 | if (!data) { |
| 155 | pr_err("%s: malloc failed\n", __func__); |
| 156 | return -1; |
| 157 | } |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 158 | data->call_site = call_site; |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 159 | data->pingpong = 0; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 160 | data->hit = 1; |
| 161 | data->bytes_req = bytes_req; |
| 162 | data->bytes_alloc = bytes_alloc; |
| 163 | |
| 164 | rb_link_node(&data->node, parent, node); |
| 165 | rb_insert_color(&data->node, &root_caller_stat); |
| 166 | } |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 167 | |
| 168 | return 0; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 169 | } |
| 170 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 171 | static int perf_evsel__process_alloc_event(struct evsel *evsel, |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 172 | struct perf_sample *sample) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 173 | { |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 174 | unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr"), |
| 175 | call_site = perf_evsel__intval(evsel, sample, "call_site"); |
| 176 | int bytes_req = perf_evsel__intval(evsel, sample, "bytes_req"), |
| 177 | bytes_alloc = perf_evsel__intval(evsel, sample, "bytes_alloc"); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 178 | |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 179 | if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) || |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 180 | insert_caller_stat(call_site, bytes_req, bytes_alloc)) |
| 181 | return -1; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 182 | |
| 183 | total_requested += bytes_req; |
| 184 | total_allocated += bytes_alloc; |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 185 | |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 186 | nr_allocs++; |
| 187 | return 0; |
| 188 | } |
| 189 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 190 | static int perf_evsel__process_alloc_node_event(struct evsel *evsel, |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 191 | struct perf_sample *sample) |
| 192 | { |
| 193 | int ret = perf_evsel__process_alloc_event(evsel, sample); |
| 194 | |
| 195 | if (!ret) { |
Don Zickus | 4b62795 | 2014-04-07 14:55:23 -0400 | [diff] [blame] | 196 | int node1 = cpu__get_node(sample->cpu), |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 197 | node2 = perf_evsel__intval(evsel, sample, "node"); |
| 198 | |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 199 | if (node1 != node2) |
| 200 | nr_cross_allocs++; |
| 201 | } |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 202 | |
| 203 | return ret; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 204 | } |
| 205 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 206 | static int ptr_cmp(void *, void *); |
| 207 | static int slab_callsite_cmp(void *, void *); |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 208 | |
| 209 | static struct alloc_stat *search_alloc_stat(unsigned long ptr, |
| 210 | unsigned long call_site, |
| 211 | struct rb_root *root, |
| 212 | sort_fn_t sort_fn) |
| 213 | { |
| 214 | struct rb_node *node = root->rb_node; |
| 215 | struct alloc_stat key = { .ptr = ptr, .call_site = call_site }; |
| 216 | |
| 217 | while (node) { |
| 218 | struct alloc_stat *data; |
| 219 | int cmp; |
| 220 | |
| 221 | data = rb_entry(node, struct alloc_stat, node); |
| 222 | |
| 223 | cmp = sort_fn(&key, data); |
| 224 | if (cmp < 0) |
| 225 | node = node->rb_left; |
| 226 | else if (cmp > 0) |
| 227 | node = node->rb_right; |
| 228 | else |
| 229 | return data; |
| 230 | } |
| 231 | return NULL; |
| 232 | } |
| 233 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 234 | static int perf_evsel__process_free_event(struct evsel *evsel, |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 235 | struct perf_sample *sample) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 236 | { |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 237 | unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr"); |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 238 | struct alloc_stat *s_alloc, *s_caller; |
| 239 | |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 240 | s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp); |
| 241 | if (!s_alloc) |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 242 | return 0; |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 243 | |
David Ahern | aa58e9a | 2016-11-25 14:42:13 -0700 | [diff] [blame] | 244 | total_freed += s_alloc->last_alloc; |
| 245 | |
Arnaldo Carvalho de Melo | 22ad798 | 2012-08-07 10:56:43 -0300 | [diff] [blame] | 246 | if ((short)sample->cpu != s_alloc->alloc_cpu) { |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 247 | s_alloc->pingpong++; |
| 248 | |
| 249 | s_caller = search_alloc_stat(0, s_alloc->call_site, |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 250 | &root_caller_stat, |
| 251 | slab_callsite_cmp); |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 252 | if (!s_caller) |
| 253 | return -1; |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 254 | s_caller->pingpong++; |
| 255 | } |
| 256 | s_alloc->alloc_cpu = -1; |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 257 | |
| 258 | return 0; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 259 | } |
| 260 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 261 | static u64 total_page_alloc_bytes; |
| 262 | static u64 total_page_free_bytes; |
| 263 | static u64 total_page_nomatch_bytes; |
| 264 | static u64 total_page_fail_bytes; |
| 265 | static unsigned long nr_page_allocs; |
| 266 | static unsigned long nr_page_frees; |
| 267 | static unsigned long nr_page_fails; |
| 268 | static unsigned long nr_page_nomatch; |
| 269 | |
| 270 | static bool use_pfn; |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 271 | static bool live_page; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 272 | static struct perf_session *kmem_session; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 273 | |
| 274 | #define MAX_MIGRATE_TYPES 6 |
| 275 | #define MAX_PAGE_ORDER 11 |
| 276 | |
| 277 | static int order_stats[MAX_PAGE_ORDER][MAX_MIGRATE_TYPES]; |
| 278 | |
| 279 | struct page_stat { |
| 280 | struct rb_node node; |
| 281 | u64 page; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 282 | u64 callsite; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 283 | int order; |
| 284 | unsigned gfp_flags; |
| 285 | unsigned migrate_type; |
| 286 | u64 alloc_bytes; |
| 287 | u64 free_bytes; |
| 288 | int nr_alloc; |
| 289 | int nr_free; |
| 290 | }; |
| 291 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 292 | static struct rb_root page_live_tree; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 293 | static struct rb_root page_alloc_tree; |
| 294 | static struct rb_root page_alloc_sorted; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 295 | static struct rb_root page_caller_tree; |
| 296 | static struct rb_root page_caller_sorted; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 297 | |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 298 | struct alloc_func { |
| 299 | u64 start; |
| 300 | u64 end; |
| 301 | char *name; |
| 302 | }; |
| 303 | |
| 304 | static int nr_alloc_funcs; |
| 305 | static struct alloc_func *alloc_func_list; |
| 306 | |
| 307 | static int funcmp(const void *a, const void *b) |
| 308 | { |
| 309 | const struct alloc_func *fa = a; |
| 310 | const struct alloc_func *fb = b; |
| 311 | |
| 312 | if (fa->start > fb->start) |
| 313 | return 1; |
| 314 | else |
| 315 | return -1; |
| 316 | } |
| 317 | |
| 318 | static int callcmp(const void *a, const void *b) |
| 319 | { |
| 320 | const struct alloc_func *fa = a; |
| 321 | const struct alloc_func *fb = b; |
| 322 | |
| 323 | if (fb->start <= fa->start && fa->end < fb->end) |
| 324 | return 0; |
| 325 | |
| 326 | if (fa->start > fb->start) |
| 327 | return 1; |
| 328 | else |
| 329 | return -1; |
| 330 | } |
| 331 | |
| 332 | static int build_alloc_func_list(void) |
| 333 | { |
| 334 | int ret; |
| 335 | struct map *kernel_map; |
| 336 | struct symbol *sym; |
| 337 | struct rb_node *node; |
| 338 | struct alloc_func *func; |
| 339 | struct machine *machine = &kmem_session->machines.host; |
| 340 | regex_t alloc_func_regex; |
Rasmus Villemoes | 49b8e2b | 2018-11-03 00:06:23 +0100 | [diff] [blame] | 341 | static const char pattern[] = "^_?_?(alloc|get_free|get_zeroed)_pages?"; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 342 | |
| 343 | ret = regcomp(&alloc_func_regex, pattern, REG_EXTENDED); |
| 344 | if (ret) { |
| 345 | char err[BUFSIZ]; |
| 346 | |
| 347 | regerror(ret, &alloc_func_regex, err, sizeof(err)); |
| 348 | pr_err("Invalid regex: %s\n%s", pattern, err); |
| 349 | return -EINVAL; |
| 350 | } |
| 351 | |
Arnaldo Carvalho de Melo | a5e813c | 2015-09-30 11:54:04 -0300 | [diff] [blame] | 352 | kernel_map = machine__kernel_map(machine); |
Arnaldo Carvalho de Melo | be39db9 | 2016-09-01 19:25:52 -0300 | [diff] [blame] | 353 | if (map__load(kernel_map) < 0) { |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 354 | pr_err("cannot load kernel map\n"); |
| 355 | return -ENOENT; |
| 356 | } |
| 357 | |
| 358 | map__for_each_symbol(kernel_map, sym, node) { |
| 359 | if (regexec(&alloc_func_regex, sym->name, 0, NULL, 0)) |
| 360 | continue; |
| 361 | |
| 362 | func = realloc(alloc_func_list, |
| 363 | (nr_alloc_funcs + 1) * sizeof(*func)); |
| 364 | if (func == NULL) |
| 365 | return -ENOMEM; |
| 366 | |
| 367 | pr_debug("alloc func: %s\n", sym->name); |
| 368 | func[nr_alloc_funcs].start = sym->start; |
| 369 | func[nr_alloc_funcs].end = sym->end; |
| 370 | func[nr_alloc_funcs].name = sym->name; |
| 371 | |
| 372 | alloc_func_list = func; |
| 373 | nr_alloc_funcs++; |
| 374 | } |
| 375 | |
| 376 | qsort(alloc_func_list, nr_alloc_funcs, sizeof(*func), funcmp); |
| 377 | |
| 378 | regfree(&alloc_func_regex); |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Find first non-memory allocation function from callchain. |
| 384 | * The allocation functions are in the 'alloc_func_list'. |
| 385 | */ |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 386 | static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 387 | { |
| 388 | struct addr_location al; |
| 389 | struct machine *machine = &kmem_session->machines.host; |
| 390 | struct callchain_cursor_node *node; |
| 391 | |
| 392 | if (alloc_func_list == NULL) { |
| 393 | if (build_alloc_func_list() < 0) |
| 394 | goto out; |
| 395 | } |
| 396 | |
| 397 | al.thread = machine__findnew_thread(machine, sample->pid, sample->tid); |
Arnaldo Carvalho de Melo | 91d7b2d | 2016-04-14 14:48:07 -0300 | [diff] [blame] | 398 | sample__resolve_callchain(sample, &callchain_cursor, NULL, evsel, &al, 16); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 399 | |
| 400 | callchain_cursor_commit(&callchain_cursor); |
| 401 | while (true) { |
| 402 | struct alloc_func key, *caller; |
| 403 | u64 addr; |
| 404 | |
| 405 | node = callchain_cursor_current(&callchain_cursor); |
| 406 | if (node == NULL) |
| 407 | break; |
| 408 | |
| 409 | key.start = key.end = node->ip; |
| 410 | caller = bsearch(&key, alloc_func_list, nr_alloc_funcs, |
| 411 | sizeof(key), callcmp); |
| 412 | if (!caller) { |
| 413 | /* found */ |
| 414 | if (node->map) |
| 415 | addr = map__unmap_ip(node->map, node->ip); |
| 416 | else |
| 417 | addr = node->ip; |
| 418 | |
| 419 | return addr; |
| 420 | } else |
| 421 | pr_debug3("skipping alloc function: %s\n", caller->name); |
| 422 | |
| 423 | callchain_cursor_advance(&callchain_cursor); |
| 424 | } |
| 425 | |
| 426 | out: |
| 427 | pr_debug2("unknown callsite: %"PRIx64 "\n", sample->ip); |
| 428 | return sample->ip; |
| 429 | } |
| 430 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 431 | struct sort_dimension { |
| 432 | const char name[20]; |
| 433 | sort_fn_t cmp; |
| 434 | struct list_head list; |
| 435 | }; |
| 436 | |
| 437 | static LIST_HEAD(page_alloc_sort_input); |
| 438 | static LIST_HEAD(page_caller_sort_input); |
| 439 | |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 440 | static struct page_stat * |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 441 | __page_stat__findnew_page(struct page_stat *pstat, bool create) |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 442 | { |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 443 | struct rb_node **node = &page_live_tree.rb_node; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 444 | struct rb_node *parent = NULL; |
| 445 | struct page_stat *data; |
| 446 | |
| 447 | while (*node) { |
| 448 | s64 cmp; |
| 449 | |
| 450 | parent = *node; |
| 451 | data = rb_entry(*node, struct page_stat, node); |
| 452 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 453 | cmp = data->page - pstat->page; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 454 | if (cmp < 0) |
| 455 | node = &parent->rb_left; |
| 456 | else if (cmp > 0) |
| 457 | node = &parent->rb_right; |
| 458 | else |
| 459 | return data; |
| 460 | } |
| 461 | |
| 462 | if (!create) |
| 463 | return NULL; |
| 464 | |
| 465 | data = zalloc(sizeof(*data)); |
| 466 | if (data != NULL) { |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 467 | data->page = pstat->page; |
| 468 | data->order = pstat->order; |
| 469 | data->gfp_flags = pstat->gfp_flags; |
| 470 | data->migrate_type = pstat->migrate_type; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 471 | |
| 472 | rb_link_node(&data->node, parent, node); |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 473 | rb_insert_color(&data->node, &page_live_tree); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | return data; |
| 477 | } |
| 478 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 479 | static struct page_stat *page_stat__find_page(struct page_stat *pstat) |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 480 | { |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 481 | return __page_stat__findnew_page(pstat, false); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 482 | } |
| 483 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 484 | static struct page_stat *page_stat__findnew_page(struct page_stat *pstat) |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 485 | { |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 486 | return __page_stat__findnew_page(pstat, true); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 487 | } |
| 488 | |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 489 | static struct page_stat * |
| 490 | __page_stat__findnew_alloc(struct page_stat *pstat, bool create) |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 491 | { |
| 492 | struct rb_node **node = &page_alloc_tree.rb_node; |
| 493 | struct rb_node *parent = NULL; |
| 494 | struct page_stat *data; |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 495 | struct sort_dimension *sort; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 496 | |
| 497 | while (*node) { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 498 | int cmp = 0; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 499 | |
| 500 | parent = *node; |
| 501 | data = rb_entry(*node, struct page_stat, node); |
| 502 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 503 | list_for_each_entry(sort, &page_alloc_sort_input, list) { |
| 504 | cmp = sort->cmp(pstat, data); |
| 505 | if (cmp) |
| 506 | break; |
| 507 | } |
| 508 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 509 | if (cmp < 0) |
| 510 | node = &parent->rb_left; |
| 511 | else if (cmp > 0) |
| 512 | node = &parent->rb_right; |
| 513 | else |
| 514 | return data; |
| 515 | } |
| 516 | |
| 517 | if (!create) |
| 518 | return NULL; |
| 519 | |
| 520 | data = zalloc(sizeof(*data)); |
| 521 | if (data != NULL) { |
David Ahern | 6b1a275 | 2015-04-14 13:49:33 -0400 | [diff] [blame] | 522 | data->page = pstat->page; |
| 523 | data->order = pstat->order; |
| 524 | data->gfp_flags = pstat->gfp_flags; |
| 525 | data->migrate_type = pstat->migrate_type; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 526 | |
| 527 | rb_link_node(&data->node, parent, node); |
| 528 | rb_insert_color(&data->node, &page_alloc_tree); |
| 529 | } |
| 530 | |
| 531 | return data; |
| 532 | } |
| 533 | |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 534 | static struct page_stat *page_stat__find_alloc(struct page_stat *pstat) |
| 535 | { |
| 536 | return __page_stat__findnew_alloc(pstat, false); |
| 537 | } |
| 538 | |
| 539 | static struct page_stat *page_stat__findnew_alloc(struct page_stat *pstat) |
| 540 | { |
| 541 | return __page_stat__findnew_alloc(pstat, true); |
| 542 | } |
| 543 | |
| 544 | static struct page_stat * |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 545 | __page_stat__findnew_caller(struct page_stat *pstat, bool create) |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 546 | { |
| 547 | struct rb_node **node = &page_caller_tree.rb_node; |
| 548 | struct rb_node *parent = NULL; |
| 549 | struct page_stat *data; |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 550 | struct sort_dimension *sort; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 551 | |
| 552 | while (*node) { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 553 | int cmp = 0; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 554 | |
| 555 | parent = *node; |
| 556 | data = rb_entry(*node, struct page_stat, node); |
| 557 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 558 | list_for_each_entry(sort, &page_caller_sort_input, list) { |
| 559 | cmp = sort->cmp(pstat, data); |
| 560 | if (cmp) |
| 561 | break; |
| 562 | } |
| 563 | |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 564 | if (cmp < 0) |
| 565 | node = &parent->rb_left; |
| 566 | else if (cmp > 0) |
| 567 | node = &parent->rb_right; |
| 568 | else |
| 569 | return data; |
| 570 | } |
| 571 | |
| 572 | if (!create) |
| 573 | return NULL; |
| 574 | |
| 575 | data = zalloc(sizeof(*data)); |
| 576 | if (data != NULL) { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 577 | data->callsite = pstat->callsite; |
| 578 | data->order = pstat->order; |
| 579 | data->gfp_flags = pstat->gfp_flags; |
| 580 | data->migrate_type = pstat->migrate_type; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 581 | |
| 582 | rb_link_node(&data->node, parent, node); |
| 583 | rb_insert_color(&data->node, &page_caller_tree); |
| 584 | } |
| 585 | |
| 586 | return data; |
| 587 | } |
| 588 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 589 | static struct page_stat *page_stat__find_caller(struct page_stat *pstat) |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 590 | { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 591 | return __page_stat__findnew_caller(pstat, false); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 592 | } |
| 593 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 594 | static struct page_stat *page_stat__findnew_caller(struct page_stat *pstat) |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 595 | { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 596 | return __page_stat__findnew_caller(pstat, true); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 597 | } |
| 598 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 599 | static bool valid_page(u64 pfn_or_page) |
| 600 | { |
| 601 | if (use_pfn && pfn_or_page == -1UL) |
| 602 | return false; |
| 603 | if (!use_pfn && pfn_or_page == 0) |
| 604 | return false; |
| 605 | return true; |
| 606 | } |
| 607 | |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 608 | struct gfp_flag { |
| 609 | unsigned int flags; |
| 610 | char *compact_str; |
| 611 | char *human_readable; |
| 612 | }; |
| 613 | |
| 614 | static struct gfp_flag *gfps; |
| 615 | static int nr_gfps; |
| 616 | |
| 617 | static int gfpcmp(const void *a, const void *b) |
| 618 | { |
| 619 | const struct gfp_flag *fa = a; |
| 620 | const struct gfp_flag *fb = b; |
| 621 | |
| 622 | return fa->flags - fb->flags; |
| 623 | } |
| 624 | |
Vlastimil Babka | 420adbe9 | 2016-03-15 14:55:52 -0700 | [diff] [blame] | 625 | /* see include/trace/events/mmflags.h */ |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 626 | static const struct { |
| 627 | const char *original; |
| 628 | const char *compact; |
| 629 | } gfp_compact_table[] = { |
| 630 | { "GFP_TRANSHUGE", "THP" }, |
Vlastimil Babka | 2516035 | 2016-07-28 15:49:25 -0700 | [diff] [blame] | 631 | { "GFP_TRANSHUGE_LIGHT", "THL" }, |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 632 | { "GFP_HIGHUSER_MOVABLE", "HUM" }, |
| 633 | { "GFP_HIGHUSER", "HU" }, |
| 634 | { "GFP_USER", "U" }, |
Vlastimil Babka | 14e0a21 | 2016-03-15 14:55:49 -0700 | [diff] [blame] | 635 | { "GFP_KERNEL_ACCOUNT", "KAC" }, |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 636 | { "GFP_KERNEL", "K" }, |
| 637 | { "GFP_NOFS", "NF" }, |
| 638 | { "GFP_ATOMIC", "A" }, |
| 639 | { "GFP_NOIO", "NI" }, |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 640 | { "GFP_NOWAIT", "NW" }, |
Vlastimil Babka | 14e0a21 | 2016-03-15 14:55:49 -0700 | [diff] [blame] | 641 | { "GFP_DMA", "D" }, |
| 642 | { "__GFP_HIGHMEM", "HM" }, |
| 643 | { "GFP_DMA32", "D32" }, |
| 644 | { "__GFP_HIGH", "H" }, |
| 645 | { "__GFP_ATOMIC", "_A" }, |
| 646 | { "__GFP_IO", "I" }, |
| 647 | { "__GFP_FS", "F" }, |
Vlastimil Babka | 14e0a21 | 2016-03-15 14:55:49 -0700 | [diff] [blame] | 648 | { "__GFP_NOWARN", "NWR" }, |
Michal Hocko | dcda9b0 | 2017-07-12 14:36:45 -0700 | [diff] [blame] | 649 | { "__GFP_RETRY_MAYFAIL", "R" }, |
Vlastimil Babka | 14e0a21 | 2016-03-15 14:55:49 -0700 | [diff] [blame] | 650 | { "__GFP_NOFAIL", "NF" }, |
| 651 | { "__GFP_NORETRY", "NR" }, |
| 652 | { "__GFP_COMP", "C" }, |
| 653 | { "__GFP_ZERO", "Z" }, |
| 654 | { "__GFP_NOMEMALLOC", "NMA" }, |
| 655 | { "__GFP_MEMALLOC", "MA" }, |
| 656 | { "__GFP_HARDWALL", "HW" }, |
| 657 | { "__GFP_THISNODE", "TN" }, |
| 658 | { "__GFP_RECLAIMABLE", "RC" }, |
| 659 | { "__GFP_MOVABLE", "M" }, |
| 660 | { "__GFP_ACCOUNT", "AC" }, |
Vlastimil Babka | 14e0a21 | 2016-03-15 14:55:49 -0700 | [diff] [blame] | 661 | { "__GFP_WRITE", "WR" }, |
| 662 | { "__GFP_RECLAIM", "R" }, |
| 663 | { "__GFP_DIRECT_RECLAIM", "DR" }, |
| 664 | { "__GFP_KSWAPD_RECLAIM", "KR" }, |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | static size_t max_gfp_len; |
| 668 | |
| 669 | static char *compact_gfp_flags(char *gfp_flags) |
| 670 | { |
| 671 | char *orig_flags = strdup(gfp_flags); |
| 672 | char *new_flags = NULL; |
Arnaldo Carvalho de Melo | b236512 | 2015-05-29 09:48:13 -0300 | [diff] [blame] | 673 | char *str, *pos = NULL; |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 674 | size_t len = 0; |
| 675 | |
| 676 | if (orig_flags == NULL) |
| 677 | return NULL; |
| 678 | |
| 679 | str = strtok_r(orig_flags, "|", &pos); |
| 680 | while (str) { |
| 681 | size_t i; |
| 682 | char *new; |
| 683 | const char *cpt; |
| 684 | |
| 685 | for (i = 0; i < ARRAY_SIZE(gfp_compact_table); i++) { |
| 686 | if (strcmp(gfp_compact_table[i].original, str)) |
| 687 | continue; |
| 688 | |
| 689 | cpt = gfp_compact_table[i].compact; |
| 690 | new = realloc(new_flags, len + strlen(cpt) + 2); |
| 691 | if (new == NULL) { |
| 692 | free(new_flags); |
| 693 | return NULL; |
| 694 | } |
| 695 | |
| 696 | new_flags = new; |
| 697 | |
| 698 | if (!len) { |
| 699 | strcpy(new_flags, cpt); |
| 700 | } else { |
| 701 | strcat(new_flags, "|"); |
| 702 | strcat(new_flags, cpt); |
| 703 | len++; |
| 704 | } |
| 705 | |
| 706 | len += strlen(cpt); |
| 707 | } |
| 708 | |
| 709 | str = strtok_r(NULL, "|", &pos); |
| 710 | } |
| 711 | |
| 712 | if (max_gfp_len < len) |
| 713 | max_gfp_len = len; |
| 714 | |
| 715 | free(orig_flags); |
| 716 | return new_flags; |
| 717 | } |
| 718 | |
| 719 | static char *compact_gfp_string(unsigned long gfp_flags) |
| 720 | { |
| 721 | struct gfp_flag key = { |
| 722 | .flags = gfp_flags, |
| 723 | }; |
| 724 | struct gfp_flag *gfp; |
| 725 | |
| 726 | gfp = bsearch(&key, gfps, nr_gfps, sizeof(*gfps), gfpcmp); |
| 727 | if (gfp) |
| 728 | return gfp->compact_str; |
| 729 | |
| 730 | return NULL; |
| 731 | } |
| 732 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 733 | static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 734 | unsigned int gfp_flags) |
| 735 | { |
Tzvetomir Stoyanov (VMware) | cbc49b2 | 2018-08-08 14:02:47 -0400 | [diff] [blame] | 736 | struct tep_record record = { |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 737 | .cpu = sample->cpu, |
| 738 | .data = sample->raw_data, |
| 739 | .size = sample->raw_size, |
| 740 | }; |
| 741 | struct trace_seq seq; |
Arnaldo Carvalho de Melo | 08a9b98 | 2015-05-11 11:41:17 -0300 | [diff] [blame] | 742 | char *str, *pos = NULL; |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 743 | |
| 744 | if (nr_gfps) { |
| 745 | struct gfp_flag key = { |
| 746 | .flags = gfp_flags, |
| 747 | }; |
| 748 | |
| 749 | if (bsearch(&key, gfps, nr_gfps, sizeof(*gfps), gfpcmp)) |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | trace_seq_init(&seq); |
Tzvetomir Stoyanov | 38847db | 2019-08-05 16:43:13 -0400 | [diff] [blame] | 754 | tep_print_event(evsel->tp_format->tep, |
| 755 | &seq, &record, "%s", TEP_PRINT_INFO); |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 756 | |
| 757 | str = strtok_r(seq.buffer, " ", &pos); |
| 758 | while (str) { |
| 759 | if (!strncmp(str, "gfp_flags=", 10)) { |
| 760 | struct gfp_flag *new; |
| 761 | |
| 762 | new = realloc(gfps, (nr_gfps + 1) * sizeof(*gfps)); |
| 763 | if (new == NULL) |
| 764 | return -ENOMEM; |
| 765 | |
| 766 | gfps = new; |
| 767 | new += nr_gfps++; |
| 768 | |
| 769 | new->flags = gfp_flags; |
| 770 | new->human_readable = strdup(str + 10); |
| 771 | new->compact_str = compact_gfp_flags(str + 10); |
| 772 | if (!new->human_readable || !new->compact_str) |
| 773 | return -ENOMEM; |
| 774 | |
| 775 | qsort(gfps, nr_gfps, sizeof(*gfps), gfpcmp); |
| 776 | } |
| 777 | |
| 778 | str = strtok_r(NULL, " ", &pos); |
| 779 | } |
| 780 | |
| 781 | trace_seq_destroy(&seq); |
| 782 | return 0; |
| 783 | } |
| 784 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 785 | static int perf_evsel__process_page_alloc_event(struct evsel *evsel, |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 786 | struct perf_sample *sample) |
| 787 | { |
| 788 | u64 page; |
| 789 | unsigned int order = perf_evsel__intval(evsel, sample, "order"); |
| 790 | unsigned int gfp_flags = perf_evsel__intval(evsel, sample, "gfp_flags"); |
| 791 | unsigned int migrate_type = perf_evsel__intval(evsel, sample, |
| 792 | "migratetype"); |
| 793 | u64 bytes = kmem_page_size << order; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 794 | u64 callsite; |
David Ahern | 6b1a275 | 2015-04-14 13:49:33 -0400 | [diff] [blame] | 795 | struct page_stat *pstat; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 796 | struct page_stat this = { |
| 797 | .order = order, |
| 798 | .gfp_flags = gfp_flags, |
| 799 | .migrate_type = migrate_type, |
| 800 | }; |
| 801 | |
| 802 | if (use_pfn) |
| 803 | page = perf_evsel__intval(evsel, sample, "pfn"); |
| 804 | else |
| 805 | page = perf_evsel__intval(evsel, sample, "page"); |
| 806 | |
| 807 | nr_page_allocs++; |
| 808 | total_page_alloc_bytes += bytes; |
| 809 | |
| 810 | if (!valid_page(page)) { |
| 811 | nr_page_fails++; |
| 812 | total_page_fail_bytes += bytes; |
| 813 | |
| 814 | return 0; |
| 815 | } |
| 816 | |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 817 | if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) |
| 818 | return -1; |
| 819 | |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 820 | callsite = find_callsite(evsel, sample); |
| 821 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 822 | /* |
| 823 | * This is to find the current page (with correct gfp flags and |
| 824 | * migrate type) at free event. |
| 825 | */ |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 826 | this.page = page; |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 827 | pstat = page_stat__findnew_page(&this); |
David Ahern | 6b1a275 | 2015-04-14 13:49:33 -0400 | [diff] [blame] | 828 | if (pstat == NULL) |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 829 | return -ENOMEM; |
| 830 | |
David Ahern | 6b1a275 | 2015-04-14 13:49:33 -0400 | [diff] [blame] | 831 | pstat->nr_alloc++; |
| 832 | pstat->alloc_bytes += bytes; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 833 | pstat->callsite = callsite; |
| 834 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 835 | if (!live_page) { |
| 836 | pstat = page_stat__findnew_alloc(&this); |
| 837 | if (pstat == NULL) |
| 838 | return -ENOMEM; |
| 839 | |
| 840 | pstat->nr_alloc++; |
| 841 | pstat->alloc_bytes += bytes; |
| 842 | pstat->callsite = callsite; |
| 843 | } |
| 844 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 845 | this.callsite = callsite; |
| 846 | pstat = page_stat__findnew_caller(&this); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 847 | if (pstat == NULL) |
| 848 | return -ENOMEM; |
| 849 | |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 850 | pstat->nr_alloc++; |
| 851 | pstat->alloc_bytes += bytes; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 852 | |
| 853 | order_stats[order][migrate_type]++; |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 858 | static int perf_evsel__process_page_free_event(struct evsel *evsel, |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 859 | struct perf_sample *sample) |
| 860 | { |
| 861 | u64 page; |
| 862 | unsigned int order = perf_evsel__intval(evsel, sample, "order"); |
| 863 | u64 bytes = kmem_page_size << order; |
David Ahern | 6b1a275 | 2015-04-14 13:49:33 -0400 | [diff] [blame] | 864 | struct page_stat *pstat; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 865 | struct page_stat this = { |
| 866 | .order = order, |
| 867 | }; |
| 868 | |
| 869 | if (use_pfn) |
| 870 | page = perf_evsel__intval(evsel, sample, "pfn"); |
| 871 | else |
| 872 | page = perf_evsel__intval(evsel, sample, "page"); |
| 873 | |
| 874 | nr_page_frees++; |
| 875 | total_page_free_bytes += bytes; |
| 876 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 877 | this.page = page; |
| 878 | pstat = page_stat__find_page(&this); |
David Ahern | 6b1a275 | 2015-04-14 13:49:33 -0400 | [diff] [blame] | 879 | if (pstat == NULL) { |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 880 | pr_debug2("missing free at page %"PRIx64" (order: %d)\n", |
| 881 | page, order); |
| 882 | |
| 883 | nr_page_nomatch++; |
| 884 | total_page_nomatch_bytes += bytes; |
| 885 | |
| 886 | return 0; |
| 887 | } |
| 888 | |
David Ahern | 6b1a275 | 2015-04-14 13:49:33 -0400 | [diff] [blame] | 889 | this.gfp_flags = pstat->gfp_flags; |
| 890 | this.migrate_type = pstat->migrate_type; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 891 | this.callsite = pstat->callsite; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 892 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 893 | rb_erase(&pstat->node, &page_live_tree); |
David Ahern | 6b1a275 | 2015-04-14 13:49:33 -0400 | [diff] [blame] | 894 | free(pstat); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 895 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 896 | if (live_page) { |
| 897 | order_stats[this.order][this.migrate_type]--; |
| 898 | } else { |
| 899 | pstat = page_stat__find_alloc(&this); |
| 900 | if (pstat == NULL) |
| 901 | return -ENOMEM; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 902 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 903 | pstat->nr_free++; |
| 904 | pstat->free_bytes += bytes; |
| 905 | } |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 906 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 907 | pstat = page_stat__find_caller(&this); |
David Ahern | 6b1a275 | 2015-04-14 13:49:33 -0400 | [diff] [blame] | 908 | if (pstat == NULL) |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 909 | return -ENOENT; |
| 910 | |
David Ahern | 6b1a275 | 2015-04-14 13:49:33 -0400 | [diff] [blame] | 911 | pstat->nr_free++; |
| 912 | pstat->free_bytes += bytes; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 913 | |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 914 | if (live_page) { |
| 915 | pstat->nr_alloc--; |
| 916 | pstat->alloc_bytes -= bytes; |
| 917 | |
| 918 | if (pstat->nr_alloc == 0) { |
| 919 | rb_erase(&pstat->node, &page_caller_tree); |
| 920 | free(pstat); |
| 921 | } |
| 922 | } |
| 923 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 924 | return 0; |
| 925 | } |
| 926 | |
David Ahern | 2a865bd | 2016-11-29 10:15:45 -0700 | [diff] [blame] | 927 | static bool perf_kmem__skip_sample(struct perf_sample *sample) |
| 928 | { |
| 929 | /* skip sample based on time? */ |
| 930 | if (perf_time__skip_sample(&ptime, sample->time)) |
| 931 | return true; |
| 932 | |
| 933 | return false; |
| 934 | } |
| 935 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 936 | typedef int (*tracepoint_handler)(struct evsel *evsel, |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 937 | struct perf_sample *sample); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 938 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 939 | static int process_sample_event(struct perf_tool *tool __maybe_unused, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 940 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 941 | struct perf_sample *sample, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 942 | struct evsel *evsel, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 943 | struct machine *machine) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 944 | { |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 945 | int err = 0; |
Adrian Hunter | ef89325 | 2013-08-27 11:23:06 +0300 | [diff] [blame] | 946 | struct thread *thread = machine__findnew_thread(machine, sample->pid, |
Namhyung Kim | 13ce34d | 2014-05-12 09:56:42 +0900 | [diff] [blame] | 947 | sample->tid); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 948 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 949 | if (thread == NULL) { |
| 950 | pr_debug("problem processing %d event, skipping it.\n", |
| 951 | event->header.type); |
| 952 | return -1; |
| 953 | } |
| 954 | |
David Ahern | 2a865bd | 2016-11-29 10:15:45 -0700 | [diff] [blame] | 955 | if (perf_kmem__skip_sample(sample)) |
| 956 | return 0; |
| 957 | |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 958 | dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 959 | |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 960 | if (evsel->handler != NULL) { |
| 961 | tracepoint_handler f = evsel->handler; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 962 | err = f(evsel, sample); |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 963 | } |
| 964 | |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 965 | thread__put(thread); |
| 966 | |
| 967 | return err; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 968 | } |
| 969 | |
Arnaldo Carvalho de Melo | fcf65bf | 2012-08-07 09:58:03 -0300 | [diff] [blame] | 970 | static struct perf_tool perf_kmem = { |
| 971 | .sample = process_sample_event, |
| 972 | .comm = perf_event__process_comm, |
Namhyung Kim | 64c4090 | 2014-08-01 14:59:31 +0900 | [diff] [blame] | 973 | .mmap = perf_event__process_mmap, |
| 974 | .mmap2 = perf_event__process_mmap2, |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 975 | .namespaces = perf_event__process_namespaces, |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 976 | .ordered_events = true, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 977 | }; |
| 978 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 979 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) |
| 980 | { |
| 981 | if (n_alloc == 0) |
| 982 | return 0.0; |
| 983 | else |
| 984 | return 100.0 - (100.0 * n_req / n_alloc); |
| 985 | } |
| 986 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 987 | static void __print_slab_result(struct rb_root *root, |
| 988 | struct perf_session *session, |
| 989 | int n_lines, int is_caller) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 990 | { |
| 991 | struct rb_node *next; |
Arnaldo Carvalho de Melo | 34ba512 | 2012-12-19 09:04:24 -0300 | [diff] [blame] | 992 | struct machine *machine = &session->machines.host; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 993 | |
Namhyung Kim | 65f46e0 | 2015-03-12 16:32:48 +0900 | [diff] [blame] | 994 | printf("%.105s\n", graph_dotted_line); |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 995 | printf(" %-34s |", is_caller ? "Callsite": "Alloc Ptr"); |
Pekka Enberg | 4710327 | 2010-01-19 19:23:23 +0200 | [diff] [blame] | 996 | printf(" Total_alloc/Per | Total_req/Per | Hit | Ping-pong | Frag\n"); |
Namhyung Kim | 65f46e0 | 2015-03-12 16:32:48 +0900 | [diff] [blame] | 997 | printf("%.105s\n", graph_dotted_line); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 998 | |
| 999 | next = rb_first(root); |
| 1000 | |
| 1001 | while (next && n_lines--) { |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 1002 | struct alloc_stat *data = rb_entry(next, struct alloc_stat, |
| 1003 | node); |
| 1004 | struct symbol *sym = NULL; |
Arnaldo Carvalho de Melo | 71cf8b8 | 2010-04-01 21:24:38 -0300 | [diff] [blame] | 1005 | struct map *map; |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 1006 | char buf[BUFSIZ]; |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 1007 | u64 addr; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1008 | |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 1009 | if (is_caller) { |
| 1010 | addr = data->call_site; |
Li Zefan | 7707b6b | 2009-11-24 13:25:48 +0800 | [diff] [blame] | 1011 | if (!raw_ip) |
Arnaldo Carvalho de Melo | 107cad9 | 2018-04-30 12:20:54 -0300 | [diff] [blame] | 1012 | sym = machine__find_kernel_symbol(machine, addr, &map); |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 1013 | } else |
| 1014 | addr = data->ptr; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1015 | |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 1016 | if (sym != NULL) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1017 | snprintf(buf, sizeof(buf), "%s+%" PRIx64 "", sym->name, |
Arnaldo Carvalho de Melo | 71cf8b8 | 2010-04-01 21:24:38 -0300 | [diff] [blame] | 1018 | addr - map->unmap_ip(map, sym->start)); |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 1019 | else |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1020 | snprintf(buf, sizeof(buf), "%#" PRIx64 "", addr); |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 1021 | printf(" %-34s |", buf); |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 1022 | |
Namhyung Kim | 65f46e0 | 2015-03-12 16:32:48 +0900 | [diff] [blame] | 1023 | printf(" %9llu/%-5lu | %9llu/%-5lu | %8lu | %9lu | %6.3f%%\n", |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 1024 | (unsigned long long)data->bytes_alloc, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1025 | (unsigned long)data->bytes_alloc / data->hit, |
| 1026 | (unsigned long long)data->bytes_req, |
| 1027 | (unsigned long)data->bytes_req / data->hit, |
| 1028 | (unsigned long)data->hit, |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 1029 | (unsigned long)data->pingpong, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1030 | fragmentation(data->bytes_req, data->bytes_alloc)); |
| 1031 | |
| 1032 | next = rb_next(next); |
| 1033 | } |
| 1034 | |
| 1035 | if (n_lines == -1) |
Namhyung Kim | 65f46e0 | 2015-03-12 16:32:48 +0900 | [diff] [blame] | 1036 | printf(" ... | ... | ... | ... | ... | ... \n"); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1037 | |
Namhyung Kim | 65f46e0 | 2015-03-12 16:32:48 +0900 | [diff] [blame] | 1038 | printf("%.105s\n", graph_dotted_line); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1039 | } |
| 1040 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1041 | static const char * const migrate_type_str[] = { |
| 1042 | "UNMOVABL", |
| 1043 | "RECLAIM", |
| 1044 | "MOVABLE", |
| 1045 | "RESERVED", |
| 1046 | "CMA/ISLT", |
| 1047 | "UNKNOWN", |
| 1048 | }; |
| 1049 | |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1050 | static void __print_page_alloc_result(struct perf_session *session, int n_lines) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1051 | { |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1052 | struct rb_node *next = rb_first(&page_alloc_sorted); |
| 1053 | struct machine *machine = &session->machines.host; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1054 | const char *format; |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1055 | int gfp_len = max(strlen("GFP flags"), max_gfp_len); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1056 | |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1057 | printf("\n%.105s\n", graph_dotted_line); |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1058 | printf(" %-16s | %5s alloc (KB) | Hits | Order | Mig.type | %-*s | Callsite\n", |
| 1059 | use_pfn ? "PFN" : "Page", live_page ? "Live" : "Total", |
| 1060 | gfp_len, "GFP flags"); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1061 | printf("%.105s\n", graph_dotted_line); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1062 | |
| 1063 | if (use_pfn) |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1064 | format = " %16llu | %'16llu | %'9d | %5d | %8s | %-*s | %s\n"; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1065 | else |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1066 | format = " %016llx | %'16llu | %'9d | %5d | %8s | %-*s | %s\n"; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1067 | |
| 1068 | while (next && n_lines--) { |
| 1069 | struct page_stat *data; |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1070 | struct symbol *sym; |
| 1071 | struct map *map; |
| 1072 | char buf[32]; |
| 1073 | char *caller = buf; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1074 | |
| 1075 | data = rb_entry(next, struct page_stat, node); |
Arnaldo Carvalho de Melo | 107cad9 | 2018-04-30 12:20:54 -0300 | [diff] [blame] | 1076 | sym = machine__find_kernel_symbol(machine, data->callsite, &map); |
Arnaldo Carvalho de Melo | a7c3899 | 2017-02-13 16:52:15 -0300 | [diff] [blame] | 1077 | if (sym) |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1078 | caller = sym->name; |
| 1079 | else |
| 1080 | scnprintf(buf, sizeof(buf), "%"PRIx64, data->callsite); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1081 | |
| 1082 | printf(format, (unsigned long long)data->page, |
| 1083 | (unsigned long long)data->alloc_bytes / 1024, |
| 1084 | data->nr_alloc, data->order, |
| 1085 | migrate_type_str[data->migrate_type], |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1086 | gfp_len, compact_gfp_string(data->gfp_flags), caller); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1087 | |
| 1088 | next = rb_next(next); |
| 1089 | } |
| 1090 | |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1091 | if (n_lines == -1) { |
| 1092 | printf(" ... | ... | ... | ... | ... | %-*s | ...\n", |
| 1093 | gfp_len, "..."); |
| 1094 | } |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1095 | |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1096 | printf("%.105s\n", graph_dotted_line); |
| 1097 | } |
| 1098 | |
| 1099 | static void __print_page_caller_result(struct perf_session *session, int n_lines) |
| 1100 | { |
| 1101 | struct rb_node *next = rb_first(&page_caller_sorted); |
| 1102 | struct machine *machine = &session->machines.host; |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1103 | int gfp_len = max(strlen("GFP flags"), max_gfp_len); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1104 | |
| 1105 | printf("\n%.105s\n", graph_dotted_line); |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1106 | printf(" %5s alloc (KB) | Hits | Order | Mig.type | %-*s | Callsite\n", |
| 1107 | live_page ? "Live" : "Total", gfp_len, "GFP flags"); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1108 | printf("%.105s\n", graph_dotted_line); |
| 1109 | |
| 1110 | while (next && n_lines--) { |
| 1111 | struct page_stat *data; |
| 1112 | struct symbol *sym; |
| 1113 | struct map *map; |
| 1114 | char buf[32]; |
| 1115 | char *caller = buf; |
| 1116 | |
| 1117 | data = rb_entry(next, struct page_stat, node); |
Arnaldo Carvalho de Melo | 107cad9 | 2018-04-30 12:20:54 -0300 | [diff] [blame] | 1118 | sym = machine__find_kernel_symbol(machine, data->callsite, &map); |
Arnaldo Carvalho de Melo | a7c3899 | 2017-02-13 16:52:15 -0300 | [diff] [blame] | 1119 | if (sym) |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1120 | caller = sym->name; |
| 1121 | else |
| 1122 | scnprintf(buf, sizeof(buf), "%"PRIx64, data->callsite); |
| 1123 | |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1124 | printf(" %'16llu | %'9d | %5d | %8s | %-*s | %s\n", |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1125 | (unsigned long long)data->alloc_bytes / 1024, |
| 1126 | data->nr_alloc, data->order, |
| 1127 | migrate_type_str[data->migrate_type], |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1128 | gfp_len, compact_gfp_string(data->gfp_flags), caller); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1129 | |
| 1130 | next = rb_next(next); |
| 1131 | } |
| 1132 | |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1133 | if (n_lines == -1) { |
| 1134 | printf(" ... | ... | ... | ... | %-*s | ...\n", |
| 1135 | gfp_len, "..."); |
| 1136 | } |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1137 | |
| 1138 | printf("%.105s\n", graph_dotted_line); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1139 | } |
| 1140 | |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1141 | static void print_gfp_flags(void) |
| 1142 | { |
| 1143 | int i; |
| 1144 | |
| 1145 | printf("#\n"); |
| 1146 | printf("# GFP flags\n"); |
| 1147 | printf("# ---------\n"); |
| 1148 | for (i = 0; i < nr_gfps; i++) { |
| 1149 | printf("# %08x: %*s: %s\n", gfps[i].flags, |
| 1150 | (int) max_gfp_len, gfps[i].compact_str, |
| 1151 | gfps[i].human_readable); |
| 1152 | } |
| 1153 | } |
| 1154 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1155 | static void print_slab_summary(void) |
| 1156 | { |
| 1157 | printf("\nSUMMARY (SLAB allocator)"); |
| 1158 | printf("\n========================\n"); |
Namhyung Kim | 77cfe38 | 2015-03-23 15:30:40 +0900 | [diff] [blame] | 1159 | printf("Total bytes requested: %'lu\n", total_requested); |
| 1160 | printf("Total bytes allocated: %'lu\n", total_allocated); |
David Ahern | aa58e9a | 2016-11-25 14:42:13 -0700 | [diff] [blame] | 1161 | printf("Total bytes freed: %'lu\n", total_freed); |
| 1162 | if (total_allocated > total_freed) { |
| 1163 | printf("Net total bytes allocated: %'lu\n", |
| 1164 | total_allocated - total_freed); |
| 1165 | } |
Namhyung Kim | 77cfe38 | 2015-03-23 15:30:40 +0900 | [diff] [blame] | 1166 | printf("Total bytes wasted on internal fragmentation: %'lu\n", |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1167 | total_allocated - total_requested); |
| 1168 | printf("Internal fragmentation: %f%%\n", |
| 1169 | fragmentation(total_requested, total_allocated)); |
Namhyung Kim | 77cfe38 | 2015-03-23 15:30:40 +0900 | [diff] [blame] | 1170 | printf("Cross CPU allocations: %'lu/%'lu\n", nr_cross_allocs, nr_allocs); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1171 | } |
| 1172 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1173 | static void print_page_summary(void) |
| 1174 | { |
| 1175 | int o, m; |
| 1176 | u64 nr_alloc_freed = nr_page_frees - nr_page_nomatch; |
| 1177 | u64 total_alloc_freed_bytes = total_page_free_bytes - total_page_nomatch_bytes; |
| 1178 | |
| 1179 | printf("\nSUMMARY (page allocator)"); |
| 1180 | printf("\n========================\n"); |
| 1181 | printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total allocation requests", |
| 1182 | nr_page_allocs, total_page_alloc_bytes / 1024); |
| 1183 | printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total free requests", |
| 1184 | nr_page_frees, total_page_free_bytes / 1024); |
| 1185 | printf("\n"); |
| 1186 | |
Will Deacon | 6145c25 | 2015-04-23 14:40:37 +0100 | [diff] [blame] | 1187 | printf("%-30s: %'16"PRIu64" [ %'16"PRIu64" KB ]\n", "Total alloc+freed requests", |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1188 | nr_alloc_freed, (total_alloc_freed_bytes) / 1024); |
Will Deacon | 6145c25 | 2015-04-23 14:40:37 +0100 | [diff] [blame] | 1189 | printf("%-30s: %'16"PRIu64" [ %'16"PRIu64" KB ]\n", "Total alloc-only requests", |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1190 | nr_page_allocs - nr_alloc_freed, |
| 1191 | (total_page_alloc_bytes - total_alloc_freed_bytes) / 1024); |
| 1192 | printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total free-only requests", |
| 1193 | nr_page_nomatch, total_page_nomatch_bytes / 1024); |
| 1194 | printf("\n"); |
| 1195 | |
| 1196 | printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total allocation failures", |
| 1197 | nr_page_fails, total_page_fail_bytes / 1024); |
| 1198 | printf("\n"); |
| 1199 | |
| 1200 | printf("%5s %12s %12s %12s %12s %12s\n", "Order", "Unmovable", |
| 1201 | "Reclaimable", "Movable", "Reserved", "CMA/Isolated"); |
| 1202 | printf("%.5s %.12s %.12s %.12s %.12s %.12s\n", graph_dotted_line, |
| 1203 | graph_dotted_line, graph_dotted_line, graph_dotted_line, |
| 1204 | graph_dotted_line, graph_dotted_line); |
| 1205 | |
| 1206 | for (o = 0; o < MAX_PAGE_ORDER; o++) { |
| 1207 | printf("%5d", o); |
| 1208 | for (m = 0; m < MAX_MIGRATE_TYPES - 1; m++) { |
| 1209 | if (order_stats[o][m]) |
| 1210 | printf(" %'12d", order_stats[o][m]); |
| 1211 | else |
| 1212 | printf(" %12c", '.'); |
| 1213 | } |
| 1214 | printf("\n"); |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | static void print_slab_result(struct perf_session *session) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1219 | { |
| 1220 | if (caller_flag) |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1221 | __print_slab_result(&root_caller_sorted, session, caller_lines, 1); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1222 | if (alloc_flag) |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1223 | __print_slab_result(&root_alloc_sorted, session, alloc_lines, 0); |
| 1224 | print_slab_summary(); |
| 1225 | } |
| 1226 | |
| 1227 | static void print_page_result(struct perf_session *session) |
| 1228 | { |
Namhyung Kim | 0e11115 | 2015-04-21 13:55:05 +0900 | [diff] [blame] | 1229 | if (caller_flag || alloc_flag) |
| 1230 | print_gfp_flags(); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1231 | if (caller_flag) |
| 1232 | __print_page_caller_result(session, caller_lines); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1233 | if (alloc_flag) |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1234 | __print_page_alloc_result(session, alloc_lines); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1235 | print_page_summary(); |
| 1236 | } |
| 1237 | |
| 1238 | static void print_result(struct perf_session *session) |
| 1239 | { |
| 1240 | if (kmem_slab) |
| 1241 | print_slab_result(session); |
| 1242 | if (kmem_page) |
| 1243 | print_page_result(session); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1244 | } |
| 1245 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1246 | static LIST_HEAD(slab_caller_sort); |
| 1247 | static LIST_HEAD(slab_alloc_sort); |
| 1248 | static LIST_HEAD(page_caller_sort); |
| 1249 | static LIST_HEAD(page_alloc_sort); |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1250 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1251 | static void sort_slab_insert(struct rb_root *root, struct alloc_stat *data, |
| 1252 | struct list_head *sort_list) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1253 | { |
| 1254 | struct rb_node **new = &(root->rb_node); |
| 1255 | struct rb_node *parent = NULL; |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1256 | struct sort_dimension *sort; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1257 | |
| 1258 | while (*new) { |
| 1259 | struct alloc_stat *this; |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1260 | int cmp = 0; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1261 | |
| 1262 | this = rb_entry(*new, struct alloc_stat, node); |
| 1263 | parent = *new; |
| 1264 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1265 | list_for_each_entry(sort, sort_list, list) { |
| 1266 | cmp = sort->cmp(data, this); |
| 1267 | if (cmp) |
| 1268 | break; |
| 1269 | } |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1270 | |
| 1271 | if (cmp > 0) |
| 1272 | new = &((*new)->rb_left); |
| 1273 | else |
| 1274 | new = &((*new)->rb_right); |
| 1275 | } |
| 1276 | |
| 1277 | rb_link_node(&data->node, parent, new); |
| 1278 | rb_insert_color(&data->node, root); |
| 1279 | } |
| 1280 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1281 | static void __sort_slab_result(struct rb_root *root, struct rb_root *root_sorted, |
| 1282 | struct list_head *sort_list) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1283 | { |
| 1284 | struct rb_node *node; |
| 1285 | struct alloc_stat *data; |
| 1286 | |
| 1287 | for (;;) { |
| 1288 | node = rb_first(root); |
| 1289 | if (!node) |
| 1290 | break; |
| 1291 | |
| 1292 | rb_erase(node, root); |
| 1293 | data = rb_entry(node, struct alloc_stat, node); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1294 | sort_slab_insert(root_sorted, data, sort_list); |
| 1295 | } |
| 1296 | } |
| 1297 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1298 | static void sort_page_insert(struct rb_root *root, struct page_stat *data, |
| 1299 | struct list_head *sort_list) |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1300 | { |
| 1301 | struct rb_node **new = &root->rb_node; |
| 1302 | struct rb_node *parent = NULL; |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1303 | struct sort_dimension *sort; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1304 | |
| 1305 | while (*new) { |
| 1306 | struct page_stat *this; |
| 1307 | int cmp = 0; |
| 1308 | |
| 1309 | this = rb_entry(*new, struct page_stat, node); |
| 1310 | parent = *new; |
| 1311 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1312 | list_for_each_entry(sort, sort_list, list) { |
| 1313 | cmp = sort->cmp(data, this); |
| 1314 | if (cmp) |
| 1315 | break; |
| 1316 | } |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1317 | |
| 1318 | if (cmp > 0) |
| 1319 | new = &parent->rb_left; |
| 1320 | else |
| 1321 | new = &parent->rb_right; |
| 1322 | } |
| 1323 | |
| 1324 | rb_link_node(&data->node, parent, new); |
| 1325 | rb_insert_color(&data->node, root); |
| 1326 | } |
| 1327 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1328 | static void __sort_page_result(struct rb_root *root, struct rb_root *root_sorted, |
| 1329 | struct list_head *sort_list) |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1330 | { |
| 1331 | struct rb_node *node; |
| 1332 | struct page_stat *data; |
| 1333 | |
| 1334 | for (;;) { |
| 1335 | node = rb_first(root); |
| 1336 | if (!node) |
| 1337 | break; |
| 1338 | |
| 1339 | rb_erase(node, root); |
| 1340 | data = rb_entry(node, struct page_stat, node); |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1341 | sort_page_insert(root_sorted, data, sort_list); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | static void sort_result(void) |
| 1346 | { |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1347 | if (kmem_slab) { |
| 1348 | __sort_slab_result(&root_alloc_stat, &root_alloc_sorted, |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1349 | &slab_alloc_sort); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1350 | __sort_slab_result(&root_caller_stat, &root_caller_sorted, |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1351 | &slab_caller_sort); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1352 | } |
| 1353 | if (kmem_page) { |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 1354 | if (live_page) |
| 1355 | __sort_page_result(&page_live_tree, &page_alloc_sorted, |
| 1356 | &page_alloc_sort); |
| 1357 | else |
| 1358 | __sort_page_result(&page_alloc_tree, &page_alloc_sorted, |
| 1359 | &page_alloc_sort); |
| 1360 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1361 | __sort_page_result(&page_caller_tree, &page_caller_sorted, |
| 1362 | &page_caller_sort); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1363 | } |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1364 | } |
| 1365 | |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1366 | static int __cmd_kmem(struct perf_session *session) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1367 | { |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1368 | int err = -EINVAL; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1369 | struct evsel *evsel; |
| 1370 | const struct evsel_str_handler kmem_tracepoints[] = { |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1371 | /* slab allocator */ |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 1372 | { "kmem:kmalloc", perf_evsel__process_alloc_event, }, |
| 1373 | { "kmem:kmem_cache_alloc", perf_evsel__process_alloc_event, }, |
| 1374 | { "kmem:kmalloc_node", perf_evsel__process_alloc_node_event, }, |
| 1375 | { "kmem:kmem_cache_alloc_node", perf_evsel__process_alloc_node_event, }, |
| 1376 | { "kmem:kfree", perf_evsel__process_free_event, }, |
| 1377 | { "kmem:kmem_cache_free", perf_evsel__process_free_event, }, |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1378 | /* page allocator */ |
| 1379 | { "kmem:mm_page_alloc", perf_evsel__process_page_alloc_event, }, |
| 1380 | { "kmem:mm_page_free", perf_evsel__process_page_free_event, }, |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 1381 | }; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1382 | |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1383 | if (!perf_session__has_traces(session, "kmem record")) |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1384 | goto out; |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1385 | |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 1386 | if (perf_session__set_tracepoints_handlers(session, kmem_tracepoints)) { |
| 1387 | pr_err("Initializing perf session tracepoint handlers failed\n"); |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1388 | goto out; |
Arnaldo Carvalho de Melo | 0f7d2f1 | 2012-09-24 10:46:54 -0300 | [diff] [blame] | 1389 | } |
| 1390 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 1391 | evlist__for_each_entry(session->evlist, evsel) { |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1392 | if (!strcmp(perf_evsel__name(evsel), "kmem:mm_page_alloc") && |
| 1393 | perf_evsel__field(evsel, "pfn")) { |
| 1394 | use_pfn = true; |
| 1395 | break; |
| 1396 | } |
| 1397 | } |
| 1398 | |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 1399 | setup_pager(); |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1400 | err = perf_session__process_events(session); |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1401 | if (err != 0) { |
| 1402 | pr_err("error during process events: %d\n", err); |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1403 | goto out; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1404 | } |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 1405 | sort_result(); |
| 1406 | print_result(session); |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1407 | out: |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 1408 | return err; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1409 | } |
| 1410 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1411 | /* slab sort keys */ |
| 1412 | static int ptr_cmp(void *a, void *b) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1413 | { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1414 | struct alloc_stat *l = a; |
| 1415 | struct alloc_stat *r = b; |
| 1416 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1417 | if (l->ptr < r->ptr) |
| 1418 | return -1; |
| 1419 | else if (l->ptr > r->ptr) |
| 1420 | return 1; |
| 1421 | return 0; |
| 1422 | } |
| 1423 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1424 | static struct sort_dimension ptr_sort_dimension = { |
| 1425 | .name = "ptr", |
| 1426 | .cmp = ptr_cmp, |
| 1427 | }; |
| 1428 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1429 | static int slab_callsite_cmp(void *a, void *b) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1430 | { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1431 | struct alloc_stat *l = a; |
| 1432 | struct alloc_stat *r = b; |
| 1433 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1434 | if (l->call_site < r->call_site) |
| 1435 | return -1; |
| 1436 | else if (l->call_site > r->call_site) |
| 1437 | return 1; |
| 1438 | return 0; |
| 1439 | } |
| 1440 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1441 | static struct sort_dimension callsite_sort_dimension = { |
| 1442 | .name = "callsite", |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1443 | .cmp = slab_callsite_cmp, |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1444 | }; |
| 1445 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1446 | static int hit_cmp(void *a, void *b) |
Pekka Enberg | f3ced7c | 2009-11-22 11:58:00 +0200 | [diff] [blame] | 1447 | { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1448 | struct alloc_stat *l = a; |
| 1449 | struct alloc_stat *r = b; |
| 1450 | |
Pekka Enberg | f3ced7c | 2009-11-22 11:58:00 +0200 | [diff] [blame] | 1451 | if (l->hit < r->hit) |
| 1452 | return -1; |
| 1453 | else if (l->hit > r->hit) |
| 1454 | return 1; |
| 1455 | return 0; |
| 1456 | } |
| 1457 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1458 | static struct sort_dimension hit_sort_dimension = { |
| 1459 | .name = "hit", |
| 1460 | .cmp = hit_cmp, |
| 1461 | }; |
| 1462 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1463 | static int bytes_cmp(void *a, void *b) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1464 | { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1465 | struct alloc_stat *l = a; |
| 1466 | struct alloc_stat *r = b; |
| 1467 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1468 | if (l->bytes_alloc < r->bytes_alloc) |
| 1469 | return -1; |
| 1470 | else if (l->bytes_alloc > r->bytes_alloc) |
| 1471 | return 1; |
| 1472 | return 0; |
| 1473 | } |
| 1474 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1475 | static struct sort_dimension bytes_sort_dimension = { |
| 1476 | .name = "bytes", |
| 1477 | .cmp = bytes_cmp, |
| 1478 | }; |
| 1479 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1480 | static int frag_cmp(void *a, void *b) |
Pekka Enberg | f3ced7c | 2009-11-22 11:58:00 +0200 | [diff] [blame] | 1481 | { |
| 1482 | double x, y; |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1483 | struct alloc_stat *l = a; |
| 1484 | struct alloc_stat *r = b; |
Pekka Enberg | f3ced7c | 2009-11-22 11:58:00 +0200 | [diff] [blame] | 1485 | |
| 1486 | x = fragmentation(l->bytes_req, l->bytes_alloc); |
| 1487 | y = fragmentation(r->bytes_req, r->bytes_alloc); |
| 1488 | |
| 1489 | if (x < y) |
| 1490 | return -1; |
| 1491 | else if (x > y) |
| 1492 | return 1; |
| 1493 | return 0; |
| 1494 | } |
| 1495 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1496 | static struct sort_dimension frag_sort_dimension = { |
| 1497 | .name = "frag", |
| 1498 | .cmp = frag_cmp, |
| 1499 | }; |
| 1500 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1501 | static int pingpong_cmp(void *a, void *b) |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 1502 | { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1503 | struct alloc_stat *l = a; |
| 1504 | struct alloc_stat *r = b; |
| 1505 | |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 1506 | if (l->pingpong < r->pingpong) |
| 1507 | return -1; |
| 1508 | else if (l->pingpong > r->pingpong) |
| 1509 | return 1; |
| 1510 | return 0; |
| 1511 | } |
| 1512 | |
| 1513 | static struct sort_dimension pingpong_sort_dimension = { |
| 1514 | .name = "pingpong", |
| 1515 | .cmp = pingpong_cmp, |
| 1516 | }; |
| 1517 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1518 | /* page sort keys */ |
| 1519 | static int page_cmp(void *a, void *b) |
| 1520 | { |
| 1521 | struct page_stat *l = a; |
| 1522 | struct page_stat *r = b; |
| 1523 | |
| 1524 | if (l->page < r->page) |
| 1525 | return -1; |
| 1526 | else if (l->page > r->page) |
| 1527 | return 1; |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
| 1531 | static struct sort_dimension page_sort_dimension = { |
| 1532 | .name = "page", |
| 1533 | .cmp = page_cmp, |
| 1534 | }; |
| 1535 | |
| 1536 | static int page_callsite_cmp(void *a, void *b) |
| 1537 | { |
| 1538 | struct page_stat *l = a; |
| 1539 | struct page_stat *r = b; |
| 1540 | |
| 1541 | if (l->callsite < r->callsite) |
| 1542 | return -1; |
| 1543 | else if (l->callsite > r->callsite) |
| 1544 | return 1; |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | static struct sort_dimension page_callsite_sort_dimension = { |
| 1549 | .name = "callsite", |
| 1550 | .cmp = page_callsite_cmp, |
| 1551 | }; |
| 1552 | |
| 1553 | static int page_hit_cmp(void *a, void *b) |
| 1554 | { |
| 1555 | struct page_stat *l = a; |
| 1556 | struct page_stat *r = b; |
| 1557 | |
| 1558 | if (l->nr_alloc < r->nr_alloc) |
| 1559 | return -1; |
| 1560 | else if (l->nr_alloc > r->nr_alloc) |
| 1561 | return 1; |
| 1562 | return 0; |
| 1563 | } |
| 1564 | |
| 1565 | static struct sort_dimension page_hit_sort_dimension = { |
| 1566 | .name = "hit", |
| 1567 | .cmp = page_hit_cmp, |
| 1568 | }; |
| 1569 | |
| 1570 | static int page_bytes_cmp(void *a, void *b) |
| 1571 | { |
| 1572 | struct page_stat *l = a; |
| 1573 | struct page_stat *r = b; |
| 1574 | |
| 1575 | if (l->alloc_bytes < r->alloc_bytes) |
| 1576 | return -1; |
| 1577 | else if (l->alloc_bytes > r->alloc_bytes) |
| 1578 | return 1; |
| 1579 | return 0; |
| 1580 | } |
| 1581 | |
| 1582 | static struct sort_dimension page_bytes_sort_dimension = { |
| 1583 | .name = "bytes", |
| 1584 | .cmp = page_bytes_cmp, |
| 1585 | }; |
| 1586 | |
| 1587 | static int page_order_cmp(void *a, void *b) |
| 1588 | { |
| 1589 | struct page_stat *l = a; |
| 1590 | struct page_stat *r = b; |
| 1591 | |
| 1592 | if (l->order < r->order) |
| 1593 | return -1; |
| 1594 | else if (l->order > r->order) |
| 1595 | return 1; |
| 1596 | return 0; |
| 1597 | } |
| 1598 | |
| 1599 | static struct sort_dimension page_order_sort_dimension = { |
| 1600 | .name = "order", |
| 1601 | .cmp = page_order_cmp, |
| 1602 | }; |
| 1603 | |
| 1604 | static int migrate_type_cmp(void *a, void *b) |
| 1605 | { |
| 1606 | struct page_stat *l = a; |
| 1607 | struct page_stat *r = b; |
| 1608 | |
| 1609 | /* for internal use to find free'd page */ |
| 1610 | if (l->migrate_type == -1U) |
| 1611 | return 0; |
| 1612 | |
| 1613 | if (l->migrate_type < r->migrate_type) |
| 1614 | return -1; |
| 1615 | else if (l->migrate_type > r->migrate_type) |
| 1616 | return 1; |
| 1617 | return 0; |
| 1618 | } |
| 1619 | |
| 1620 | static struct sort_dimension migrate_type_sort_dimension = { |
| 1621 | .name = "migtype", |
| 1622 | .cmp = migrate_type_cmp, |
| 1623 | }; |
| 1624 | |
| 1625 | static int gfp_flags_cmp(void *a, void *b) |
| 1626 | { |
| 1627 | struct page_stat *l = a; |
| 1628 | struct page_stat *r = b; |
| 1629 | |
| 1630 | /* for internal use to find free'd page */ |
| 1631 | if (l->gfp_flags == -1U) |
| 1632 | return 0; |
| 1633 | |
| 1634 | if (l->gfp_flags < r->gfp_flags) |
| 1635 | return -1; |
| 1636 | else if (l->gfp_flags > r->gfp_flags) |
| 1637 | return 1; |
| 1638 | return 0; |
| 1639 | } |
| 1640 | |
| 1641 | static struct sort_dimension gfp_flags_sort_dimension = { |
| 1642 | .name = "gfp", |
| 1643 | .cmp = gfp_flags_cmp, |
| 1644 | }; |
| 1645 | |
| 1646 | static struct sort_dimension *slab_sorts[] = { |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1647 | &ptr_sort_dimension, |
| 1648 | &callsite_sort_dimension, |
| 1649 | &hit_sort_dimension, |
| 1650 | &bytes_sort_dimension, |
| 1651 | &frag_sort_dimension, |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 1652 | &pingpong_sort_dimension, |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1653 | }; |
| 1654 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1655 | static struct sort_dimension *page_sorts[] = { |
| 1656 | &page_sort_dimension, |
| 1657 | &page_callsite_sort_dimension, |
| 1658 | &page_hit_sort_dimension, |
| 1659 | &page_bytes_sort_dimension, |
| 1660 | &page_order_sort_dimension, |
| 1661 | &migrate_type_sort_dimension, |
| 1662 | &gfp_flags_sort_dimension, |
| 1663 | }; |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1664 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1665 | static int slab_sort_dimension__add(const char *tok, struct list_head *list) |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1666 | { |
| 1667 | struct sort_dimension *sort; |
| 1668 | int i; |
| 1669 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1670 | for (i = 0; i < (int)ARRAY_SIZE(slab_sorts); i++) { |
| 1671 | if (!strcmp(slab_sorts[i]->name, tok)) { |
| 1672 | sort = memdup(slab_sorts[i], sizeof(*slab_sorts[i])); |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 1673 | if (!sort) { |
Arnaldo Carvalho de Melo | 8d9233f | 2013-01-24 22:24:57 -0300 | [diff] [blame] | 1674 | pr_err("%s: memdup failed\n", __func__); |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 1675 | return -1; |
| 1676 | } |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1677 | list_add_tail(&sort->list, list); |
| 1678 | return 0; |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | return -1; |
| 1683 | } |
| 1684 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1685 | static int page_sort_dimension__add(const char *tok, struct list_head *list) |
| 1686 | { |
| 1687 | struct sort_dimension *sort; |
| 1688 | int i; |
| 1689 | |
| 1690 | for (i = 0; i < (int)ARRAY_SIZE(page_sorts); i++) { |
| 1691 | if (!strcmp(page_sorts[i]->name, tok)) { |
| 1692 | sort = memdup(page_sorts[i], sizeof(*page_sorts[i])); |
| 1693 | if (!sort) { |
| 1694 | pr_err("%s: memdup failed\n", __func__); |
| 1695 | return -1; |
| 1696 | } |
| 1697 | list_add_tail(&sort->list, list); |
| 1698 | return 0; |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | return -1; |
| 1703 | } |
| 1704 | |
| 1705 | static int setup_slab_sorting(struct list_head *sort_list, const char *arg) |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1706 | { |
| 1707 | char *tok; |
| 1708 | char *str = strdup(arg); |
Namhyung Kim | 405f875 | 2015-03-12 16:32:46 +0900 | [diff] [blame] | 1709 | char *pos = str; |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1710 | |
Arnaldo Carvalho de Melo | 2814eb0 | 2012-09-08 22:53:06 -0300 | [diff] [blame] | 1711 | if (!str) { |
| 1712 | pr_err("%s: strdup failed\n", __func__); |
| 1713 | return -1; |
| 1714 | } |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1715 | |
| 1716 | while (true) { |
Namhyung Kim | 405f875 | 2015-03-12 16:32:46 +0900 | [diff] [blame] | 1717 | tok = strsep(&pos, ","); |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1718 | if (!tok) |
| 1719 | break; |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1720 | if (slab_sort_dimension__add(tok, sort_list) < 0) { |
Arnaldo Carvalho de Melo | 62d94b0 | 2017-06-27 11:22:31 -0300 | [diff] [blame] | 1721 | pr_err("Unknown slab --sort key: '%s'", tok); |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1722 | free(str); |
| 1723 | return -1; |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | free(str); |
| 1728 | return 0; |
| 1729 | } |
| 1730 | |
| 1731 | static int setup_page_sorting(struct list_head *sort_list, const char *arg) |
| 1732 | { |
| 1733 | char *tok; |
| 1734 | char *str = strdup(arg); |
| 1735 | char *pos = str; |
| 1736 | |
| 1737 | if (!str) { |
| 1738 | pr_err("%s: strdup failed\n", __func__); |
| 1739 | return -1; |
| 1740 | } |
| 1741 | |
| 1742 | while (true) { |
| 1743 | tok = strsep(&pos, ","); |
| 1744 | if (!tok) |
| 1745 | break; |
| 1746 | if (page_sort_dimension__add(tok, sort_list) < 0) { |
Arnaldo Carvalho de Melo | 62d94b0 | 2017-06-27 11:22:31 -0300 | [diff] [blame] | 1747 | pr_err("Unknown page --sort key: '%s'", tok); |
Namhyung Kim | 1b22859 | 2012-01-08 02:25:29 +0900 | [diff] [blame] | 1748 | free(str); |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 1749 | return -1; |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | free(str); |
| 1754 | return 0; |
| 1755 | } |
| 1756 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 1757 | static int parse_sort_opt(const struct option *opt __maybe_unused, |
| 1758 | const char *arg, int unset __maybe_unused) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1759 | { |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1760 | if (!arg) |
| 1761 | return -1; |
| 1762 | |
Namhyung Kim | 0c160d4 | 2015-04-21 13:55:06 +0900 | [diff] [blame] | 1763 | if (kmem_page > kmem_slab || |
| 1764 | (kmem_page == 0 && kmem_slab == 0 && kmem_default == KMEM_PAGE)) { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1765 | if (caller_flag > alloc_flag) |
| 1766 | return setup_page_sorting(&page_caller_sort, arg); |
| 1767 | else |
| 1768 | return setup_page_sorting(&page_alloc_sort, arg); |
| 1769 | } else { |
| 1770 | if (caller_flag > alloc_flag) |
| 1771 | return setup_slab_sorting(&slab_caller_sort, arg); |
| 1772 | else |
| 1773 | return setup_slab_sorting(&slab_alloc_sort, arg); |
| 1774 | } |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1775 | |
| 1776 | return 0; |
| 1777 | } |
| 1778 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 1779 | static int parse_caller_opt(const struct option *opt __maybe_unused, |
| 1780 | const char *arg __maybe_unused, |
| 1781 | int unset __maybe_unused) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1782 | { |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 1783 | caller_flag = (alloc_flag + 1); |
| 1784 | return 0; |
| 1785 | } |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1786 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 1787 | static int parse_alloc_opt(const struct option *opt __maybe_unused, |
| 1788 | const char *arg __maybe_unused, |
| 1789 | int unset __maybe_unused) |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 1790 | { |
| 1791 | alloc_flag = (caller_flag + 1); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1792 | return 0; |
| 1793 | } |
| 1794 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1795 | static int parse_slab_opt(const struct option *opt __maybe_unused, |
| 1796 | const char *arg __maybe_unused, |
| 1797 | int unset __maybe_unused) |
| 1798 | { |
| 1799 | kmem_slab = (kmem_page + 1); |
| 1800 | return 0; |
| 1801 | } |
| 1802 | |
| 1803 | static int parse_page_opt(const struct option *opt __maybe_unused, |
| 1804 | const char *arg __maybe_unused, |
| 1805 | int unset __maybe_unused) |
| 1806 | { |
| 1807 | kmem_page = (kmem_slab + 1); |
| 1808 | return 0; |
| 1809 | } |
| 1810 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 1811 | static int parse_line_opt(const struct option *opt __maybe_unused, |
| 1812 | const char *arg, int unset __maybe_unused) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1813 | { |
| 1814 | int lines; |
| 1815 | |
| 1816 | if (!arg) |
| 1817 | return -1; |
| 1818 | |
| 1819 | lines = strtoul(arg, NULL, 10); |
| 1820 | |
| 1821 | if (caller_flag > alloc_flag) |
| 1822 | caller_lines = lines; |
| 1823 | else |
| 1824 | alloc_lines = lines; |
| 1825 | |
| 1826 | return 0; |
| 1827 | } |
| 1828 | |
Arnaldo Carvalho de Melo | 0433ffb | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1829 | static int __cmd_record(int argc, const char **argv) |
| 1830 | { |
| 1831 | const char * const record_args[] = { |
Jiri Olsa | 4a4d371 | 2013-06-05 13:37:21 +0200 | [diff] [blame] | 1832 | "record", "-a", "-R", "-c", "1", |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1833 | }; |
| 1834 | const char * const slab_events[] = { |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1835 | "-e", "kmem:kmalloc", |
| 1836 | "-e", "kmem:kmalloc_node", |
| 1837 | "-e", "kmem:kfree", |
| 1838 | "-e", "kmem:kmem_cache_alloc", |
| 1839 | "-e", "kmem:kmem_cache_alloc_node", |
| 1840 | "-e", "kmem:kmem_cache_free", |
Arnaldo Carvalho de Melo | 0433ffb | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1841 | }; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1842 | const char * const page_events[] = { |
| 1843 | "-e", "kmem:mm_page_alloc", |
| 1844 | "-e", "kmem:mm_page_free", |
| 1845 | }; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1846 | unsigned int rec_argc, i, j; |
| 1847 | const char **rec_argv; |
| 1848 | |
| 1849 | rec_argc = ARRAY_SIZE(record_args) + argc - 1; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1850 | if (kmem_slab) |
| 1851 | rec_argc += ARRAY_SIZE(slab_events); |
| 1852 | if (kmem_page) |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1853 | rec_argc += ARRAY_SIZE(page_events) + 1; /* for -g */ |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1854 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1855 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 1856 | |
Chris Samuel | ce47dc5 | 2010-11-13 13:35:06 +1100 | [diff] [blame] | 1857 | if (rec_argv == NULL) |
| 1858 | return -ENOMEM; |
| 1859 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1860 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
| 1861 | rec_argv[i] = strdup(record_args[i]); |
| 1862 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1863 | if (kmem_slab) { |
| 1864 | for (j = 0; j < ARRAY_SIZE(slab_events); j++, i++) |
| 1865 | rec_argv[i] = strdup(slab_events[j]); |
| 1866 | } |
| 1867 | if (kmem_page) { |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1868 | rec_argv[i++] = strdup("-g"); |
| 1869 | |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1870 | for (j = 0; j < ARRAY_SIZE(page_events); j++, i++) |
| 1871 | rec_argv[i] = strdup(page_events[j]); |
| 1872 | } |
| 1873 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1874 | for (j = 1; j < (unsigned int)argc; j++, i++) |
| 1875 | rec_argv[i] = argv[j]; |
| 1876 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1877 | return cmd_record(i, rec_argv); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1878 | } |
| 1879 | |
Wang Nan | b8cbb34 | 2016-02-26 09:31:51 +0000 | [diff] [blame] | 1880 | static int kmem_config(const char *var, const char *value, void *cb __maybe_unused) |
Namhyung Kim | 0c160d4 | 2015-04-21 13:55:06 +0900 | [diff] [blame] | 1881 | { |
| 1882 | if (!strcmp(var, "kmem.default")) { |
| 1883 | if (!strcmp(value, "slab")) |
| 1884 | kmem_default = KMEM_SLAB; |
| 1885 | else if (!strcmp(value, "page")) |
| 1886 | kmem_default = KMEM_PAGE; |
| 1887 | else |
| 1888 | pr_err("invalid default value ('slab' or 'page' required): %s\n", |
| 1889 | value); |
| 1890 | return 0; |
| 1891 | } |
| 1892 | |
Wang Nan | b8cbb34 | 2016-02-26 09:31:51 +0000 | [diff] [blame] | 1893 | return 0; |
Namhyung Kim | 0c160d4 | 2015-04-21 13:55:06 +0900 | [diff] [blame] | 1894 | } |
| 1895 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1896 | int cmd_kmem(int argc, const char **argv) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1897 | { |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1898 | const char * const default_slab_sort = "frag,hit,bytes"; |
| 1899 | const char * const default_page_sort = "bytes,hit"; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1900 | struct perf_data data = { |
Yunlong Song | d1eeb77 | 2015-04-02 21:47:12 +0800 | [diff] [blame] | 1901 | .mode = PERF_DATA_MODE_READ, |
| 1902 | }; |
Arnaldo Carvalho de Melo | 0433ffb | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1903 | const struct option kmem_options[] = { |
| 1904 | OPT_STRING('i', "input", &input_name, "file", "input file name"), |
Namhyung Kim | bd72a33 | 2015-03-12 16:32:47 +0900 | [diff] [blame] | 1905 | OPT_INCR('v', "verbose", &verbose, |
| 1906 | "be more verbose (show symbol address, etc)"), |
Arnaldo Carvalho de Melo | 0433ffb | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1907 | OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL, |
| 1908 | "show per-callsite statistics", parse_caller_opt), |
| 1909 | OPT_CALLBACK_NOOPT(0, "alloc", NULL, NULL, |
| 1910 | "show per-allocation statistics", parse_alloc_opt), |
| 1911 | OPT_CALLBACK('s', "sort", NULL, "key[,key2...]", |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 1912 | "sort by keys: ptr, callsite, bytes, hit, pingpong, frag, " |
| 1913 | "page, order, migtype, gfp", parse_sort_opt), |
Arnaldo Carvalho de Melo | 0433ffb | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1914 | OPT_CALLBACK('l', "line", NULL, "num", "show n lines", parse_line_opt), |
| 1915 | OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"), |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1916 | OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"), |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1917 | OPT_CALLBACK_NOOPT(0, "slab", NULL, NULL, "Analyze slab allocator", |
| 1918 | parse_slab_opt), |
| 1919 | OPT_CALLBACK_NOOPT(0, "page", NULL, NULL, "Analyze page allocator", |
| 1920 | parse_page_opt), |
Namhyung Kim | 2a7ef02 | 2015-04-21 13:55:04 +0900 | [diff] [blame] | 1921 | OPT_BOOLEAN(0, "live", &live_page, "Show live page stat"), |
David Ahern | 2a865bd | 2016-11-29 10:15:45 -0700 | [diff] [blame] | 1922 | OPT_STRING(0, "time", &time_str, "str", |
| 1923 | "Time span of interest (start,stop)"), |
Arnaldo Carvalho de Melo | 0433ffb | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1924 | OPT_END() |
| 1925 | }; |
Ramkumar Ramachandra | 3bca235 | 2014-03-14 23:17:51 -0400 | [diff] [blame] | 1926 | const char *const kmem_subcommands[] = { "record", "stat", NULL }; |
| 1927 | const char *kmem_usage[] = { |
| 1928 | NULL, |
Arnaldo Carvalho de Melo | 0433ffb | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 1929 | NULL |
| 1930 | }; |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1931 | struct perf_session *session; |
Rasmus Villemoes | 49b8e2b | 2018-11-03 00:06:23 +0100 | [diff] [blame] | 1932 | static const char errmsg[] = "No %s allocation events found. Have you run 'perf kmem record --%s'?\n"; |
Arnaldo Carvalho de Melo | ecc4c56 | 2017-01-24 13:44:10 -0300 | [diff] [blame] | 1933 | int ret = perf_config(kmem_config, NULL); |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1934 | |
Arnaldo Carvalho de Melo | ecc4c56 | 2017-01-24 13:44:10 -0300 | [diff] [blame] | 1935 | if (ret) |
| 1936 | return ret; |
| 1937 | |
Ramkumar Ramachandra | 3bca235 | 2014-03-14 23:17:51 -0400 | [diff] [blame] | 1938 | argc = parse_options_subcommand(argc, argv, kmem_options, |
| 1939 | kmem_subcommands, kmem_usage, 0); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1940 | |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 1941 | if (!argc) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1942 | usage_with_options(kmem_usage, kmem_options); |
| 1943 | |
Namhyung Kim | 0c160d4 | 2015-04-21 13:55:06 +0900 | [diff] [blame] | 1944 | if (kmem_slab == 0 && kmem_page == 0) { |
| 1945 | if (kmem_default == KMEM_SLAB) |
| 1946 | kmem_slab = 1; |
| 1947 | else |
| 1948 | kmem_page = 1; |
| 1949 | } |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1950 | |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1951 | if (!strncmp(argv[0], "rec", 3)) { |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 1952 | symbol__init(NULL); |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1953 | return __cmd_record(argc, argv); |
| 1954 | } |
| 1955 | |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 1956 | data.path = input_name; |
Jiri Olsa | 28939e1 | 2015-04-06 14:36:08 +0900 | [diff] [blame] | 1957 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1958 | kmem_session = session = perf_session__new(&data, false, &perf_kmem); |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1959 | if (session == NULL) |
Taeung Song | 52e02834 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 1960 | return -1; |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1961 | |
Arnaldo Carvalho de Melo | ecc4c56 | 2017-01-24 13:44:10 -0300 | [diff] [blame] | 1962 | ret = -1; |
| 1963 | |
Namhyung Kim | a923e2c | 2015-05-05 23:52:52 +0900 | [diff] [blame] | 1964 | if (kmem_slab) { |
| 1965 | if (!perf_evlist__find_tracepoint_by_name(session->evlist, |
| 1966 | "kmem:kmalloc")) { |
| 1967 | pr_err(errmsg, "slab", "slab"); |
Taeung Song | 249ca1a | 2015-06-30 17:15:21 +0900 | [diff] [blame] | 1968 | goto out_delete; |
Namhyung Kim | a923e2c | 2015-05-05 23:52:52 +0900 | [diff] [blame] | 1969 | } |
| 1970 | } |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1971 | |
Namhyung Kim | a923e2c | 2015-05-05 23:52:52 +0900 | [diff] [blame] | 1972 | if (kmem_page) { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1973 | struct evsel *evsel; |
Namhyung Kim | a923e2c | 2015-05-05 23:52:52 +0900 | [diff] [blame] | 1974 | |
| 1975 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 1976 | "kmem:mm_page_alloc"); |
| 1977 | if (evsel == NULL) { |
| 1978 | pr_err(errmsg, "page", "page"); |
Taeung Song | 249ca1a | 2015-06-30 17:15:21 +0900 | [diff] [blame] | 1979 | goto out_delete; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1980 | } |
| 1981 | |
Tzvetomir Stoyanov | 69769ce | 2019-04-01 12:43:18 -0400 | [diff] [blame] | 1982 | kmem_page_size = tep_get_page_size(evsel->tp_format->tep); |
Namhyung Kim | c9758cc | 2015-04-21 13:55:02 +0900 | [diff] [blame] | 1983 | symbol_conf.use_callchain = true; |
Namhyung Kim | 0d68bc9 | 2015-04-06 14:36:10 +0900 | [diff] [blame] | 1984 | } |
| 1985 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 1986 | symbol__init(&session->header.env); |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 1987 | |
David Ahern | 2a865bd | 2016-11-29 10:15:45 -0700 | [diff] [blame] | 1988 | if (perf_time__parse_str(&ptime, time_str) != 0) { |
| 1989 | pr_err("Invalid time string\n"); |
Christophe JAILLET | 79f56eb | 2017-09-16 08:09:36 +0200 | [diff] [blame] | 1990 | ret = -EINVAL; |
| 1991 | goto out_delete; |
David Ahern | 2a865bd | 2016-11-29 10:15:45 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1994 | if (!strcmp(argv[0], "stat")) { |
Namhyung Kim | 77cfe38 | 2015-03-23 15:30:40 +0900 | [diff] [blame] | 1995 | setlocale(LC_ALL, ""); |
| 1996 | |
Don Zickus | 4b62795 | 2014-04-07 14:55:23 -0400 | [diff] [blame] | 1997 | if (cpu__setup_cpunode_map()) |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 1998 | goto out_delete; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1999 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 2000 | if (list_empty(&slab_caller_sort)) |
| 2001 | setup_slab_sorting(&slab_caller_sort, default_slab_sort); |
| 2002 | if (list_empty(&slab_alloc_sort)) |
| 2003 | setup_slab_sorting(&slab_alloc_sort, default_slab_sort); |
| 2004 | if (list_empty(&page_caller_sort)) |
| 2005 | setup_page_sorting(&page_caller_sort, default_page_sort); |
| 2006 | if (list_empty(&page_alloc_sort)) |
| 2007 | setup_page_sorting(&page_alloc_sort, default_page_sort); |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 2008 | |
Namhyung Kim | fb4f313 | 2015-04-21 13:55:03 +0900 | [diff] [blame] | 2009 | if (kmem_page) { |
| 2010 | setup_page_sorting(&page_alloc_sort_input, |
| 2011 | "page,order,migtype,gfp"); |
| 2012 | setup_page_sorting(&page_caller_sort_input, |
| 2013 | "callsite,order,migtype,gfp"); |
| 2014 | } |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 2015 | ret = __cmd_kmem(session); |
Pekka Enberg | b00eca8 | 2010-01-19 19:26:11 +0200 | [diff] [blame] | 2016 | } else |
| 2017 | usage_with_options(kmem_usage, kmem_options); |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 2018 | |
Namhyung Kim | 2b2b2c6 | 2014-08-12 15:40:38 +0900 | [diff] [blame] | 2019 | out_delete: |
| 2020 | perf_session__delete(session); |
| 2021 | |
| 2022 | return ret; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 2023 | } |
| 2024 | |