Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Slabinfo: Tool to get reports about slabs |
| 4 | * |
Christoph Lameter | cde5353 | 2008-07-04 09:59:22 -0700 | [diff] [blame] | 5 | * (C) 2007 sgi, Christoph Lameter |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 6 | * (C) 2011 Linux Foundation, Christoph Lameter |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 7 | * |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 8 | * Compile with: |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 9 | * |
| 10 | * gcc -o slabinfo slabinfo.c |
| 11 | */ |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <sys/types.h> |
| 15 | #include <dirent.h> |
WANG Cong | f32143a | 2007-10-16 23:31:29 -0700 | [diff] [blame] | 16 | #include <strings.h> |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 17 | #include <string.h> |
| 18 | #include <unistd.h> |
| 19 | #include <stdarg.h> |
| 20 | #include <getopt.h> |
| 21 | #include <regex.h> |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 22 | #include <errno.h> |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 23 | |
| 24 | #define MAX_SLABS 500 |
| 25 | #define MAX_ALIASES 500 |
| 26 | #define MAX_NODES 1024 |
| 27 | |
| 28 | struct slabinfo { |
| 29 | char *name; |
| 30 | int alias; |
| 31 | int refs; |
| 32 | int aliases, align, cache_dma, cpu_slabs, destroy_by_rcu; |
Naoya Horiguchi | 9045065 | 2018-09-04 15:45:48 -0700 | [diff] [blame] | 33 | unsigned int hwcache_align, object_size, objs_per_slab; |
| 34 | unsigned int sanity_checks, slab_size, store_user, trace; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 35 | int order, poison, reclaim_account, red_zone; |
Christoph Lameter | 205ab99 | 2008-04-14 19:11:40 +0300 | [diff] [blame] | 36 | unsigned long partial, objects, slabs, objects_partial, objects_total; |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 37 | unsigned long alloc_fastpath, alloc_slowpath; |
| 38 | unsigned long free_fastpath, free_slowpath; |
| 39 | unsigned long free_frozen, free_add_partial, free_remove_partial; |
| 40 | unsigned long alloc_from_partial, alloc_slab, free_slab, alloc_refill; |
| 41 | unsigned long cpuslab_flush, deactivate_full, deactivate_empty; |
| 42 | unsigned long deactivate_to_head, deactivate_to_tail; |
Christoph Lameter | f715e6f | 2008-04-29 16:14:46 -0700 | [diff] [blame] | 43 | unsigned long deactivate_remote_frees, order_fallback; |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 44 | unsigned long cmpxchg_double_cpu_fail, cmpxchg_double_fail; |
| 45 | unsigned long alloc_node_mismatch, deactivate_bypass; |
Christoph Lameter | aca726a | 2011-08-09 16:12:28 -0500 | [diff] [blame] | 46 | unsigned long cpu_partial_alloc, cpu_partial_free; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 47 | int numa[MAX_NODES]; |
| 48 | int numa_partial[MAX_NODES]; |
| 49 | } slabinfo[MAX_SLABS]; |
| 50 | |
| 51 | struct aliasinfo { |
| 52 | char *name; |
| 53 | char *ref; |
| 54 | struct slabinfo *slab; |
| 55 | } aliasinfo[MAX_ALIASES]; |
| 56 | |
Sergey Senozhatsky | 2cee611 | 2015-11-05 18:45:34 -0800 | [diff] [blame] | 57 | int slabs; |
| 58 | int actual_slabs; |
| 59 | int aliases; |
| 60 | int alias_targets; |
| 61 | int highest_node; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 62 | |
| 63 | char buffer[4096]; |
| 64 | |
Sergey Senozhatsky | 2cee611 | 2015-11-05 18:45:34 -0800 | [diff] [blame] | 65 | int show_empty; |
| 66 | int show_report; |
| 67 | int show_alias; |
| 68 | int show_slab; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 69 | int skip_zero = 1; |
Sergey Senozhatsky | 2cee611 | 2015-11-05 18:45:34 -0800 | [diff] [blame] | 70 | int show_numa; |
| 71 | int show_track; |
| 72 | int show_first_alias; |
| 73 | int validate; |
| 74 | int shrink; |
| 75 | int show_inverted; |
| 76 | int show_single_ref; |
| 77 | int show_totals; |
| 78 | int sort_size; |
| 79 | int sort_active; |
| 80 | int set_debug; |
| 81 | int show_ops; |
Tobin C. Harding | 1106b20 | 2019-07-11 20:59:38 -0700 | [diff] [blame] | 82 | int sort_partial; |
Sergey Senozhatsky | 2cee611 | 2015-11-05 18:45:34 -0800 | [diff] [blame] | 83 | int show_activity; |
Sergey Senozhatsky | 4980a96 | 2015-11-05 18:45:20 -0800 | [diff] [blame] | 84 | int output_lines = -1; |
Sergey Senozhatsky | 2651f6e | 2015-11-05 18:45:22 -0800 | [diff] [blame] | 85 | int sort_loss; |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 86 | int extended_totals; |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 87 | int show_bytes; |
Yang Shi | 7ad3f18 | 2017-11-15 17:31:59 -0800 | [diff] [blame] | 88 | int unreclaim_only; |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 89 | |
| 90 | /* Debug options */ |
Sergey Senozhatsky | 2cee611 | 2015-11-05 18:45:34 -0800 | [diff] [blame] | 91 | int sanity; |
| 92 | int redzone; |
| 93 | int poison; |
| 94 | int tracking; |
| 95 | int tracing; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 96 | |
| 97 | int page_size; |
| 98 | |
| 99 | regex_t pattern; |
| 100 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 101 | static void fatal(const char *x, ...) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 102 | { |
| 103 | va_list ap; |
| 104 | |
| 105 | va_start(ap, x); |
| 106 | vfprintf(stderr, x, ap); |
| 107 | va_end(ap); |
WANG Cong | f32143a | 2007-10-16 23:31:29 -0700 | [diff] [blame] | 108 | exit(EXIT_FAILURE); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 111 | static void usage(void) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 112 | { |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 113 | printf("slabinfo 4/15/2011. (c) 2007 sgi/(c) 2011 Linux Foundation.\n\n" |
Tobin C. Harding | 53a83f9 | 2019-07-11 20:59:42 -0700 | [diff] [blame] | 114 | "slabinfo [-aABDefhilLnoPrsStTUvXz1] [N=K] [-dafzput] [slab-regexp]\n" |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 115 | "-a|--aliases Show aliases\n" |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 116 | "-A|--activity Most active slabs first\n" |
Tobin C. Harding | b80fd30 | 2019-03-05 15:49:03 -0800 | [diff] [blame] | 117 | "-B|--Bytes Show size in bytes\n" |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 118 | "-D|--display-active Switch line format to activity\n" |
| 119 | "-e|--empty Show empty slabs\n" |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 120 | "-f|--first-alias Show first alias\n" |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 121 | "-h|--help Show usage information\n" |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 122 | "-i|--inverted Inverted list\n" |
| 123 | "-l|--slabs Show slabs\n" |
Tobin C. Harding | b80fd30 | 2019-03-05 15:49:03 -0800 | [diff] [blame] | 124 | "-L|--Loss Sort by loss\n" |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 125 | "-n|--numa Show NUMA information\n" |
Tobin C. Harding | b80fd30 | 2019-03-05 15:49:03 -0800 | [diff] [blame] | 126 | "-N|--lines=K Show the first K slabs\n" |
Tobin C. Harding | 3c89ff9 | 2019-03-05 15:49:07 -0800 | [diff] [blame] | 127 | "-o|--ops Show kmem_cache_ops\n" |
Tobin C. Harding | 53a83f9 | 2019-07-11 20:59:42 -0700 | [diff] [blame] | 128 | "-P|--partial Sort by number of partial slabs\n" |
Tobin C. Harding | 3c89ff9 | 2019-03-05 15:49:07 -0800 | [diff] [blame] | 129 | "-r|--report Detailed report on single slabs\n" |
Tobin C. Harding | b80fd30 | 2019-03-05 15:49:03 -0800 | [diff] [blame] | 130 | "-s|--shrink Shrink slabs\n" |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 131 | "-S|--Size Sort by size\n" |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 132 | "-t|--tracking Show alloc/free information\n" |
| 133 | "-T|--Totals Show summary information\n" |
Tobin C. Harding | 3c89ff9 | 2019-03-05 15:49:07 -0800 | [diff] [blame] | 134 | "-U|--Unreclaim Show unreclaimable slabs only\n" |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 135 | "-v|--validate Validate slabs\n" |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 136 | "-X|--Xtotals Show extended summary information\n" |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 137 | "-z|--zero Include empty slabs\n" |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 138 | "-1|--1ref Single reference\n" |
Tobin C. Harding | b80fd30 | 2019-03-05 15:49:03 -0800 | [diff] [blame] | 139 | |
Tobin C. Harding | b2f0246 | 2019-03-05 15:49:10 -0800 | [diff] [blame] | 140 | "\n" |
| 141 | "-d | --debug Switch off all debug options\n" |
| 142 | "-da | --debug=a Switch on all debug options (--debug=FZPU)\n" |
| 143 | |
| 144 | "\n" |
| 145 | "-d[afzput] | --debug=[afzput]\n" |
| 146 | " f | F Sanity Checks (SLAB_CONSISTENCY_CHECKS)\n" |
| 147 | " z | Z Redzoning\n" |
| 148 | " p | P Poisoning\n" |
| 149 | " u | U Tracking\n" |
| 150 | " t | T Tracing\n" |
Tobin C. Harding | cbf800d | 2019-07-11 20:59:46 -0700 | [diff] [blame] | 151 | |
| 152 | "\nSorting options (--Loss, --Size, --Partial) are mutually exclusive\n" |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 153 | ); |
| 154 | } |
| 155 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 156 | static unsigned long read_obj(const char *name) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 157 | { |
| 158 | FILE *f = fopen(name, "r"); |
| 159 | |
| 160 | if (!f) |
| 161 | buffer[0] = 0; |
| 162 | else { |
WANG Cong | f32143a | 2007-10-16 23:31:29 -0700 | [diff] [blame] | 163 | if (!fgets(buffer, sizeof(buffer), f)) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 164 | buffer[0] = 0; |
| 165 | fclose(f); |
| 166 | if (buffer[strlen(buffer)] == '\n') |
| 167 | buffer[strlen(buffer)] = 0; |
| 168 | } |
| 169 | return strlen(buffer); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | /* |
| 174 | * Get the contents of an attribute |
| 175 | */ |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 176 | static unsigned long get_obj(const char *name) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 177 | { |
| 178 | if (!read_obj(name)) |
| 179 | return 0; |
| 180 | |
| 181 | return atol(buffer); |
| 182 | } |
| 183 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 184 | static unsigned long get_obj_and_str(const char *name, char **x) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 185 | { |
| 186 | unsigned long result = 0; |
| 187 | char *p; |
| 188 | |
| 189 | *x = NULL; |
| 190 | |
| 191 | if (!read_obj(name)) { |
| 192 | x = NULL; |
| 193 | return 0; |
| 194 | } |
| 195 | result = strtoul(buffer, &p, 10); |
| 196 | while (*p == ' ') |
| 197 | p++; |
| 198 | if (*p) |
| 199 | *x = strdup(p); |
| 200 | return result; |
| 201 | } |
| 202 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 203 | static void set_obj(struct slabinfo *s, const char *name, int n) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 204 | { |
| 205 | char x[100]; |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 206 | FILE *f; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 207 | |
WANG Cong | f32143a | 2007-10-16 23:31:29 -0700 | [diff] [blame] | 208 | snprintf(x, 100, "%s/%s", s->name, name); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 209 | f = fopen(x, "w"); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 210 | if (!f) |
| 211 | fatal("Cannot write to %s\n", x); |
| 212 | |
| 213 | fprintf(f, "%d\n", n); |
| 214 | fclose(f); |
| 215 | } |
| 216 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 217 | static unsigned long read_slab_obj(struct slabinfo *s, const char *name) |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 218 | { |
| 219 | char x[100]; |
| 220 | FILE *f; |
WANG Cong | f32143a | 2007-10-16 23:31:29 -0700 | [diff] [blame] | 221 | size_t l; |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 222 | |
WANG Cong | f32143a | 2007-10-16 23:31:29 -0700 | [diff] [blame] | 223 | snprintf(x, 100, "%s/%s", s->name, name); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 224 | f = fopen(x, "r"); |
| 225 | if (!f) { |
| 226 | buffer[0] = 0; |
| 227 | l = 0; |
| 228 | } else { |
| 229 | l = fread(buffer, 1, sizeof(buffer), f); |
| 230 | buffer[l] = 0; |
| 231 | fclose(f); |
| 232 | } |
| 233 | return l; |
| 234 | } |
| 235 | |
| 236 | |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 237 | /* |
| 238 | * Put a size string together |
| 239 | */ |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 240 | static int store_size(char *buffer, unsigned long value) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 241 | { |
| 242 | unsigned long divisor = 1; |
| 243 | char trailer = 0; |
| 244 | int n; |
| 245 | |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 246 | if (!show_bytes) { |
| 247 | if (value > 1000000000UL) { |
| 248 | divisor = 100000000UL; |
| 249 | trailer = 'G'; |
| 250 | } else if (value > 1000000UL) { |
| 251 | divisor = 100000UL; |
| 252 | trailer = 'M'; |
| 253 | } else if (value > 1000UL) { |
| 254 | divisor = 100; |
| 255 | trailer = 'K'; |
| 256 | } |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | value /= divisor; |
| 260 | n = sprintf(buffer, "%ld",value); |
| 261 | if (trailer) { |
| 262 | buffer[n] = trailer; |
| 263 | n++; |
| 264 | buffer[n] = 0; |
| 265 | } |
| 266 | if (divisor != 1) { |
| 267 | memmove(buffer + n - 2, buffer + n - 3, 4); |
| 268 | buffer[n-2] = '.'; |
| 269 | n++; |
| 270 | } |
| 271 | return n; |
| 272 | } |
| 273 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 274 | static void decode_numa_list(int *numa, char *t) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 275 | { |
| 276 | int node; |
| 277 | int nr; |
| 278 | |
| 279 | memset(numa, 0, MAX_NODES * sizeof(int)); |
| 280 | |
Christoph Lameter | eefaca9 | 2007-05-16 22:10:55 -0700 | [diff] [blame] | 281 | if (!t) |
| 282 | return; |
| 283 | |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 284 | while (*t == 'N') { |
| 285 | t++; |
| 286 | node = strtoul(t, &t, 10); |
| 287 | if (*t == '=') { |
| 288 | t++; |
| 289 | nr = strtoul(t, &t, 10); |
| 290 | numa[node] = nr; |
| 291 | if (node > highest_node) |
| 292 | highest_node = node; |
| 293 | } |
| 294 | while (*t == ' ') |
| 295 | t++; |
| 296 | } |
| 297 | } |
| 298 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 299 | static void slab_validate(struct slabinfo *s) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 300 | { |
Christoph Lameter | 32f9306 | 2007-05-18 00:36:43 -0700 | [diff] [blame] | 301 | if (strcmp(s->name, "*") == 0) |
| 302 | return; |
| 303 | |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 304 | set_obj(s, "validate", 1); |
| 305 | } |
| 306 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 307 | static void slab_shrink(struct slabinfo *s) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 308 | { |
Christoph Lameter | 32f9306 | 2007-05-18 00:36:43 -0700 | [diff] [blame] | 309 | if (strcmp(s->name, "*") == 0) |
| 310 | return; |
| 311 | |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 312 | set_obj(s, "shrink", 1); |
| 313 | } |
| 314 | |
| 315 | int line = 0; |
| 316 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 317 | static void first_line(void) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 318 | { |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 319 | if (show_activity) |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 320 | printf("Name Objects Alloc Free" |
| 321 | " %%Fast Fallb O CmpX UL\n"); |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 322 | else |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 323 | printf("Name Objects Objsize %s " |
Sergey Senozhatsky | 2651f6e | 2015-11-05 18:45:22 -0800 | [diff] [blame] | 324 | "Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n", |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 325 | sort_loss ? " Loss" : "Space"); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* |
| 329 | * Find the shortest alias of a slab |
| 330 | */ |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 331 | static struct aliasinfo *find_one_alias(struct slabinfo *find) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 332 | { |
| 333 | struct aliasinfo *a; |
| 334 | struct aliasinfo *best = NULL; |
| 335 | |
| 336 | for(a = aliasinfo;a < aliasinfo + aliases; a++) { |
| 337 | if (a->slab == find && |
| 338 | (!best || strlen(best->name) < strlen(a->name))) { |
| 339 | best = a; |
| 340 | if (strncmp(a->name,"kmall", 5) == 0) |
| 341 | return best; |
| 342 | } |
| 343 | } |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 344 | return best; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 347 | static unsigned long slab_size(struct slabinfo *s) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 348 | { |
| 349 | return s->slabs * (page_size << s->order); |
| 350 | } |
| 351 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 352 | static unsigned long slab_activity(struct slabinfo *s) |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 353 | { |
| 354 | return s->alloc_fastpath + s->free_fastpath + |
| 355 | s->alloc_slowpath + s->free_slowpath; |
| 356 | } |
| 357 | |
Sergey Senozhatsky | 2651f6e | 2015-11-05 18:45:22 -0800 | [diff] [blame] | 358 | static unsigned long slab_waste(struct slabinfo *s) |
| 359 | { |
| 360 | return slab_size(s) - s->objects * s->object_size; |
| 361 | } |
| 362 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 363 | static void slab_numa(struct slabinfo *s, int mode) |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 364 | { |
| 365 | int node; |
| 366 | |
| 367 | if (strcmp(s->name, "*") == 0) |
| 368 | return; |
| 369 | |
| 370 | if (!highest_node) { |
| 371 | printf("\n%s: No NUMA information available.\n", s->name); |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | if (skip_zero && !s->slabs) |
| 376 | return; |
| 377 | |
| 378 | if (!line) { |
| 379 | printf("\n%-21s:", mode ? "NUMA nodes" : "Slab"); |
| 380 | for(node = 0; node <= highest_node; node++) |
| 381 | printf(" %4d", node); |
| 382 | printf("\n----------------------"); |
| 383 | for(node = 0; node <= highest_node; node++) |
| 384 | printf("-----"); |
| 385 | printf("\n"); |
| 386 | } |
| 387 | printf("%-21s ", mode ? "All slabs" : s->name); |
| 388 | for(node = 0; node <= highest_node; node++) { |
| 389 | char b[20]; |
| 390 | |
| 391 | store_size(b, s->numa[node]); |
| 392 | printf(" %4s", b); |
| 393 | } |
| 394 | printf("\n"); |
| 395 | if (mode) { |
| 396 | printf("%-21s ", "Partial slabs"); |
| 397 | for(node = 0; node <= highest_node; node++) { |
| 398 | char b[20]; |
| 399 | |
| 400 | store_size(b, s->numa_partial[node]); |
| 401 | printf(" %4s", b); |
| 402 | } |
| 403 | printf("\n"); |
| 404 | } |
| 405 | line++; |
| 406 | } |
| 407 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 408 | static void show_tracking(struct slabinfo *s) |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 409 | { |
| 410 | printf("\n%s: Kernel object allocation\n", s->name); |
| 411 | printf("-----------------------------------------------------------------------\n"); |
| 412 | if (read_slab_obj(s, "alloc_calls")) |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 413 | printf("%s", buffer); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 414 | else |
| 415 | printf("No Data\n"); |
| 416 | |
| 417 | printf("\n%s: Kernel object freeing\n", s->name); |
| 418 | printf("------------------------------------------------------------------------\n"); |
| 419 | if (read_slab_obj(s, "free_calls")) |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 420 | printf("%s", buffer); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 421 | else |
| 422 | printf("No Data\n"); |
| 423 | |
| 424 | } |
| 425 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 426 | static void ops(struct slabinfo *s) |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 427 | { |
| 428 | if (strcmp(s->name, "*") == 0) |
| 429 | return; |
| 430 | |
| 431 | if (read_slab_obj(s, "ops")) { |
| 432 | printf("\n%s: kmem_cache operations\n", s->name); |
| 433 | printf("--------------------------------------------\n"); |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 434 | printf("%s", buffer); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 435 | } else |
| 436 | printf("\n%s has no kmem_cache operations\n", s->name); |
| 437 | } |
| 438 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 439 | static const char *onoff(int x) |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 440 | { |
| 441 | if (x) |
| 442 | return "On "; |
| 443 | return "Off"; |
| 444 | } |
| 445 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 446 | static void slab_stats(struct slabinfo *s) |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 447 | { |
| 448 | unsigned long total_alloc; |
| 449 | unsigned long total_free; |
| 450 | unsigned long total; |
| 451 | |
| 452 | if (!s->alloc_slab) |
| 453 | return; |
| 454 | |
| 455 | total_alloc = s->alloc_fastpath + s->alloc_slowpath; |
| 456 | total_free = s->free_fastpath + s->free_slowpath; |
| 457 | |
| 458 | if (!total_alloc) |
| 459 | return; |
| 460 | |
| 461 | printf("\n"); |
| 462 | printf("Slab Perf Counter Alloc Free %%Al %%Fr\n"); |
| 463 | printf("--------------------------------------------------\n"); |
| 464 | printf("Fastpath %8lu %8lu %3lu %3lu\n", |
| 465 | s->alloc_fastpath, s->free_fastpath, |
| 466 | s->alloc_fastpath * 100 / total_alloc, |
majianpeng | 4b57ad9 | 2012-06-26 09:30:31 +0800 | [diff] [blame] | 467 | total_free ? s->free_fastpath * 100 / total_free : 0); |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 468 | printf("Slowpath %8lu %8lu %3lu %3lu\n", |
| 469 | total_alloc - s->alloc_fastpath, s->free_slowpath, |
| 470 | (total_alloc - s->alloc_fastpath) * 100 / total_alloc, |
majianpeng | 4b57ad9 | 2012-06-26 09:30:31 +0800 | [diff] [blame] | 471 | total_free ? s->free_slowpath * 100 / total_free : 0); |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 472 | printf("Page Alloc %8lu %8lu %3lu %3lu\n", |
| 473 | s->alloc_slab, s->free_slab, |
| 474 | s->alloc_slab * 100 / total_alloc, |
majianpeng | 4b57ad9 | 2012-06-26 09:30:31 +0800 | [diff] [blame] | 475 | total_free ? s->free_slab * 100 / total_free : 0); |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 476 | printf("Add partial %8lu %8lu %3lu %3lu\n", |
| 477 | s->deactivate_to_head + s->deactivate_to_tail, |
| 478 | s->free_add_partial, |
| 479 | (s->deactivate_to_head + s->deactivate_to_tail) * 100 / total_alloc, |
majianpeng | 4b57ad9 | 2012-06-26 09:30:31 +0800 | [diff] [blame] | 480 | total_free ? s->free_add_partial * 100 / total_free : 0); |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 481 | printf("Remove partial %8lu %8lu %3lu %3lu\n", |
| 482 | s->alloc_from_partial, s->free_remove_partial, |
| 483 | s->alloc_from_partial * 100 / total_alloc, |
majianpeng | 4b57ad9 | 2012-06-26 09:30:31 +0800 | [diff] [blame] | 484 | total_free ? s->free_remove_partial * 100 / total_free : 0); |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 485 | |
Christoph Lameter | aca726a | 2011-08-09 16:12:28 -0500 | [diff] [blame] | 486 | printf("Cpu partial list %8lu %8lu %3lu %3lu\n", |
| 487 | s->cpu_partial_alloc, s->cpu_partial_free, |
| 488 | s->cpu_partial_alloc * 100 / total_alloc, |
majianpeng | 4b57ad9 | 2012-06-26 09:30:31 +0800 | [diff] [blame] | 489 | total_free ? s->cpu_partial_free * 100 / total_free : 0); |
Christoph Lameter | aca726a | 2011-08-09 16:12:28 -0500 | [diff] [blame] | 490 | |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 491 | printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n", |
| 492 | s->deactivate_remote_frees, s->free_frozen, |
| 493 | s->deactivate_remote_frees * 100 / total_alloc, |
majianpeng | 4b57ad9 | 2012-06-26 09:30:31 +0800 | [diff] [blame] | 494 | total_free ? s->free_frozen * 100 / total_free : 0); |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 495 | |
| 496 | printf("Total %8lu %8lu\n\n", total_alloc, total_free); |
| 497 | |
| 498 | if (s->cpuslab_flush) |
| 499 | printf("Flushes %8lu\n", s->cpuslab_flush); |
| 500 | |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 501 | total = s->deactivate_full + s->deactivate_empty + |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 502 | s->deactivate_to_head + s->deactivate_to_tail + s->deactivate_bypass; |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 503 | |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 504 | if (total) { |
Colin Ian King | 7c5b723 | 2016-06-24 14:50:21 -0700 | [diff] [blame] | 505 | printf("\nSlab Deactivation Occurrences %%\n"); |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 506 | printf("-------------------------------------------------\n"); |
| 507 | printf("Slab full %7lu %3lu%%\n", |
| 508 | s->deactivate_full, (s->deactivate_full * 100) / total); |
| 509 | printf("Slab empty %7lu %3lu%%\n", |
| 510 | s->deactivate_empty, (s->deactivate_empty * 100) / total); |
| 511 | printf("Moved to head of partial list %7lu %3lu%%\n", |
| 512 | s->deactivate_to_head, (s->deactivate_to_head * 100) / total); |
| 513 | printf("Moved to tail of partial list %7lu %3lu%%\n", |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 514 | s->deactivate_to_tail, (s->deactivate_to_tail * 100) / total); |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 515 | printf("Deactivation bypass %7lu %3lu%%\n", |
| 516 | s->deactivate_bypass, (s->deactivate_bypass * 100) / total); |
| 517 | printf("Refilled from foreign frees %7lu %3lu%%\n", |
| 518 | s->alloc_refill, (s->alloc_refill * 100) / total); |
| 519 | printf("Node mismatch %7lu %3lu%%\n", |
| 520 | s->alloc_node_mismatch, (s->alloc_node_mismatch * 100) / total); |
| 521 | } |
| 522 | |
Dan Carpenter | 2d6a4d6 | 2016-07-20 15:45:05 -0700 | [diff] [blame] | 523 | if (s->cmpxchg_double_fail || s->cmpxchg_double_cpu_fail) { |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 524 | printf("\nCmpxchg_double Looping\n------------------------\n"); |
| 525 | printf("Locked Cmpxchg Double redos %lu\nUnlocked Cmpxchg Double redos %lu\n", |
| 526 | s->cmpxchg_double_fail, s->cmpxchg_double_cpu_fail); |
Dan Carpenter | 2d6a4d6 | 2016-07-20 15:45:05 -0700 | [diff] [blame] | 527 | } |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 530 | static void report(struct slabinfo *s) |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 531 | { |
| 532 | if (strcmp(s->name, "*") == 0) |
| 533 | return; |
Christoph Lameter | eefaca9 | 2007-05-16 22:10:55 -0700 | [diff] [blame] | 534 | |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 535 | printf("\nSlabcache: %-15s Aliases: %2d Order : %2d Objects: %lu\n", |
Christoph Lameter | eefaca9 | 2007-05-16 22:10:55 -0700 | [diff] [blame] | 536 | s->name, s->aliases, s->order, s->objects); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 537 | if (s->hwcache_align) |
| 538 | printf("** Hardware cacheline aligned\n"); |
| 539 | if (s->cache_dma) |
| 540 | printf("** Memory is allocated in a special DMA zone\n"); |
| 541 | if (s->destroy_by_rcu) |
| 542 | printf("** Slabs are destroyed via RCU\n"); |
| 543 | if (s->reclaim_account) |
| 544 | printf("** Reclaim accounting active\n"); |
| 545 | |
| 546 | printf("\nSizes (bytes) Slabs Debug Memory\n"); |
| 547 | printf("------------------------------------------------------------------------\n"); |
| 548 | printf("Object : %7d Total : %7ld Sanity Checks : %s Total: %7ld\n", |
| 549 | s->object_size, s->slabs, onoff(s->sanity_checks), |
| 550 | s->slabs * (page_size << s->order)); |
| 551 | printf("SlabObj: %7d Full : %7ld Redzoning : %s Used : %7ld\n", |
| 552 | s->slab_size, s->slabs - s->partial - s->cpu_slabs, |
| 553 | onoff(s->red_zone), s->objects * s->object_size); |
| 554 | printf("SlabSiz: %7d Partial: %7ld Poisoning : %s Loss : %7ld\n", |
| 555 | page_size << s->order, s->partial, onoff(s->poison), |
| 556 | s->slabs * (page_size << s->order) - s->objects * s->object_size); |
| 557 | printf("Loss : %7d CpuSlab: %7d Tracking : %s Lalig: %7ld\n", |
| 558 | s->slab_size - s->object_size, s->cpu_slabs, onoff(s->store_user), |
| 559 | (s->slab_size - s->object_size) * s->objects); |
| 560 | printf("Align : %7d Objects: %7d Tracing : %s Lpadd: %7ld\n", |
| 561 | s->align, s->objs_per_slab, onoff(s->trace), |
| 562 | ((page_size << s->order) - s->objs_per_slab * s->slab_size) * |
| 563 | s->slabs); |
| 564 | |
| 565 | ops(s); |
| 566 | show_tracking(s); |
| 567 | slab_numa(s, 1); |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 568 | slab_stats(s); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 569 | } |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 570 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 571 | static void slabcache(struct slabinfo *s) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 572 | { |
| 573 | char size_str[20]; |
| 574 | char dist_str[40]; |
| 575 | char flags[20]; |
| 576 | char *p = flags; |
| 577 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 578 | if (strcmp(s->name, "*") == 0) |
| 579 | return; |
| 580 | |
Yang Shi | 7ad3f18 | 2017-11-15 17:31:59 -0800 | [diff] [blame] | 581 | if (unreclaim_only && s->reclaim_account) |
| 582 | return; |
| 583 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 584 | if (actual_slabs == 1) { |
| 585 | report(s); |
| 586 | return; |
| 587 | } |
| 588 | |
| 589 | if (skip_zero && !show_empty && !s->slabs) |
| 590 | return; |
| 591 | |
| 592 | if (show_empty && s->slabs) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 593 | return; |
| 594 | |
Sergey Senozhatsky | 2651f6e | 2015-11-05 18:45:22 -0800 | [diff] [blame] | 595 | if (sort_loss == 0) |
| 596 | store_size(size_str, slab_size(s)); |
| 597 | else |
| 598 | store_size(size_str, slab_waste(s)); |
Christoph Lameter | 205ab99 | 2008-04-14 19:11:40 +0300 | [diff] [blame] | 599 | snprintf(dist_str, 40, "%lu/%lu/%d", s->slabs - s->cpu_slabs, |
| 600 | s->partial, s->cpu_slabs); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 601 | |
| 602 | if (!line++) |
| 603 | first_line(); |
| 604 | |
| 605 | if (s->aliases) |
| 606 | *p++ = '*'; |
| 607 | if (s->cache_dma) |
| 608 | *p++ = 'd'; |
| 609 | if (s->hwcache_align) |
| 610 | *p++ = 'A'; |
| 611 | if (s->poison) |
| 612 | *p++ = 'P'; |
| 613 | if (s->reclaim_account) |
| 614 | *p++ = 'a'; |
| 615 | if (s->red_zone) |
| 616 | *p++ = 'Z'; |
| 617 | if (s->sanity_checks) |
| 618 | *p++ = 'F'; |
| 619 | if (s->store_user) |
| 620 | *p++ = 'U'; |
| 621 | if (s->trace) |
| 622 | *p++ = 'T'; |
| 623 | |
| 624 | *p = 0; |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 625 | if (show_activity) { |
| 626 | unsigned long total_alloc; |
| 627 | unsigned long total_free; |
| 628 | |
| 629 | total_alloc = s->alloc_fastpath + s->alloc_slowpath; |
| 630 | total_free = s->free_fastpath + s->free_slowpath; |
| 631 | |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 632 | printf("%-21s %8ld %10ld %10ld %3ld %3ld %5ld %1d %4ld %4ld\n", |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 633 | s->name, s->objects, |
| 634 | total_alloc, total_free, |
| 635 | total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0, |
Christoph Lameter | f715e6f | 2008-04-29 16:14:46 -0700 | [diff] [blame] | 636 | total_free ? (s->free_fastpath * 100 / total_free) : 0, |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 637 | s->order_fallback, s->order, s->cmpxchg_double_fail, |
| 638 | s->cmpxchg_double_cpu_fail); |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 639 | } else { |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 640 | printf("%-21s %8ld %7d %15s %14s %4d %1d %3ld %3ld %s\n", |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 641 | s->name, s->objects, s->object_size, size_str, dist_str, |
| 642 | s->objs_per_slab, s->order, |
| 643 | s->slabs ? (s->partial * 100) / s->slabs : 100, |
| 644 | s->slabs ? (s->objects * s->object_size * 100) / |
| 645 | (s->slabs * (page_size << s->order)) : 100, |
| 646 | flags); |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 647 | } |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 650 | /* |
| 651 | * Analyze debug options. Return false if something is amiss. |
| 652 | */ |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 653 | static int debug_opt_scan(char *opt) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 654 | { |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 655 | if (!opt || !opt[0] || strcmp(opt, "-") == 0) |
| 656 | return 1; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 657 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 658 | if (strcasecmp(opt, "a") == 0) { |
| 659 | sanity = 1; |
| 660 | poison = 1; |
| 661 | redzone = 1; |
| 662 | tracking = 1; |
| 663 | return 1; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 664 | } |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 665 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 666 | for ( ; *opt; opt++) |
Christoph Lameter | 0d24db3 | 2010-10-21 13:01:56 -0500 | [diff] [blame] | 667 | switch (*opt) { |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 668 | case 'F' : case 'f': |
| 669 | if (sanity) |
| 670 | return 0; |
| 671 | sanity = 1; |
| 672 | break; |
| 673 | case 'P' : case 'p': |
| 674 | if (poison) |
| 675 | return 0; |
| 676 | poison = 1; |
| 677 | break; |
| 678 | |
| 679 | case 'Z' : case 'z': |
| 680 | if (redzone) |
| 681 | return 0; |
| 682 | redzone = 1; |
| 683 | break; |
| 684 | |
| 685 | case 'U' : case 'u': |
| 686 | if (tracking) |
| 687 | return 0; |
| 688 | tracking = 1; |
| 689 | break; |
| 690 | |
| 691 | case 'T' : case 't': |
| 692 | if (tracing) |
| 693 | return 0; |
| 694 | tracing = 1; |
| 695 | break; |
| 696 | default: |
| 697 | return 0; |
| 698 | } |
| 699 | return 1; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 702 | static int slab_empty(struct slabinfo *s) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 703 | { |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 704 | if (s->objects > 0) |
| 705 | return 0; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 706 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 707 | /* |
| 708 | * We may still have slabs even if there are no objects. Shrinking will |
| 709 | * remove them. |
| 710 | */ |
| 711 | if (s->slabs != 0) |
| 712 | set_obj(s, "shrink", 1); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 713 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 714 | return 1; |
| 715 | } |
| 716 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 717 | static void slab_debug(struct slabinfo *s) |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 718 | { |
Christoph Lameter | 32f9306 | 2007-05-18 00:36:43 -0700 | [diff] [blame] | 719 | if (strcmp(s->name, "*") == 0) |
| 720 | return; |
| 721 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 722 | if (sanity && !s->sanity_checks) { |
Daniel Wagner | e25974aa | 2020-01-30 22:14:17 -0800 | [diff] [blame] | 723 | set_obj(s, "sanity_checks", 1); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 724 | } |
| 725 | if (!sanity && s->sanity_checks) { |
| 726 | if (slab_empty(s)) |
Daniel Wagner | e25974aa | 2020-01-30 22:14:17 -0800 | [diff] [blame] | 727 | set_obj(s, "sanity_checks", 0); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 728 | else |
| 729 | fprintf(stderr, "%s not empty cannot disable sanity checks\n", s->name); |
| 730 | } |
| 731 | if (redzone && !s->red_zone) { |
| 732 | if (slab_empty(s)) |
| 733 | set_obj(s, "red_zone", 1); |
| 734 | else |
| 735 | fprintf(stderr, "%s not empty cannot enable redzoning\n", s->name); |
| 736 | } |
| 737 | if (!redzone && s->red_zone) { |
| 738 | if (slab_empty(s)) |
| 739 | set_obj(s, "red_zone", 0); |
| 740 | else |
| 741 | fprintf(stderr, "%s not empty cannot disable redzoning\n", s->name); |
| 742 | } |
| 743 | if (poison && !s->poison) { |
| 744 | if (slab_empty(s)) |
| 745 | set_obj(s, "poison", 1); |
| 746 | else |
| 747 | fprintf(stderr, "%s not empty cannot enable poisoning\n", s->name); |
| 748 | } |
| 749 | if (!poison && s->poison) { |
| 750 | if (slab_empty(s)) |
| 751 | set_obj(s, "poison", 0); |
| 752 | else |
| 753 | fprintf(stderr, "%s not empty cannot disable poisoning\n", s->name); |
| 754 | } |
| 755 | if (tracking && !s->store_user) { |
| 756 | if (slab_empty(s)) |
| 757 | set_obj(s, "store_user", 1); |
| 758 | else |
| 759 | fprintf(stderr, "%s not empty cannot enable tracking\n", s->name); |
| 760 | } |
| 761 | if (!tracking && s->store_user) { |
| 762 | if (slab_empty(s)) |
| 763 | set_obj(s, "store_user", 0); |
| 764 | else |
| 765 | fprintf(stderr, "%s not empty cannot disable tracking\n", s->name); |
| 766 | } |
| 767 | if (tracing && !s->trace) { |
| 768 | if (slabs == 1) |
| 769 | set_obj(s, "trace", 1); |
| 770 | else |
| 771 | fprintf(stderr, "%s can only enable trace for one slab at a time\n", s->name); |
| 772 | } |
| 773 | if (!tracing && s->trace) |
| 774 | set_obj(s, "trace", 1); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 777 | static void totals(void) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 778 | { |
| 779 | struct slabinfo *s; |
| 780 | |
| 781 | int used_slabs = 0; |
| 782 | char b1[20], b2[20], b3[20], b4[20]; |
| 783 | unsigned long long max = 1ULL << 63; |
| 784 | |
| 785 | /* Object size */ |
| 786 | unsigned long long min_objsize = max, max_objsize = 0, avg_objsize; |
| 787 | |
| 788 | /* Number of partial slabs in a slabcache */ |
| 789 | unsigned long long min_partial = max, max_partial = 0, |
| 790 | avg_partial, total_partial = 0; |
| 791 | |
| 792 | /* Number of slabs in a slab cache */ |
| 793 | unsigned long long min_slabs = max, max_slabs = 0, |
| 794 | avg_slabs, total_slabs = 0; |
| 795 | |
| 796 | /* Size of the whole slab */ |
| 797 | unsigned long long min_size = max, max_size = 0, |
| 798 | avg_size, total_size = 0; |
| 799 | |
| 800 | /* Bytes used for object storage in a slab */ |
| 801 | unsigned long long min_used = max, max_used = 0, |
| 802 | avg_used, total_used = 0; |
| 803 | |
| 804 | /* Waste: Bytes used for alignment and padding */ |
| 805 | unsigned long long min_waste = max, max_waste = 0, |
| 806 | avg_waste, total_waste = 0; |
| 807 | /* Number of objects in a slab */ |
| 808 | unsigned long long min_objects = max, max_objects = 0, |
| 809 | avg_objects, total_objects = 0; |
| 810 | /* Waste per object */ |
| 811 | unsigned long long min_objwaste = max, |
| 812 | max_objwaste = 0, avg_objwaste, |
| 813 | total_objwaste = 0; |
| 814 | |
| 815 | /* Memory per object */ |
| 816 | unsigned long long min_memobj = max, |
| 817 | max_memobj = 0, avg_memobj, |
| 818 | total_objsize = 0; |
| 819 | |
| 820 | /* Percentage of partial slabs per slab */ |
| 821 | unsigned long min_ppart = 100, max_ppart = 0, |
| 822 | avg_ppart, total_ppart = 0; |
| 823 | |
| 824 | /* Number of objects in partial slabs */ |
| 825 | unsigned long min_partobj = max, max_partobj = 0, |
| 826 | avg_partobj, total_partobj = 0; |
| 827 | |
| 828 | /* Percentage of partial objects of all objects in a slab */ |
| 829 | unsigned long min_ppartobj = 100, max_ppartobj = 0, |
| 830 | avg_ppartobj, total_ppartobj = 0; |
| 831 | |
| 832 | |
| 833 | for (s = slabinfo; s < slabinfo + slabs; s++) { |
| 834 | unsigned long long size; |
| 835 | unsigned long used; |
| 836 | unsigned long long wasted; |
| 837 | unsigned long long objwaste; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 838 | unsigned long percentage_partial_slabs; |
| 839 | unsigned long percentage_partial_objs; |
| 840 | |
| 841 | if (!s->slabs || !s->objects) |
| 842 | continue; |
| 843 | |
| 844 | used_slabs++; |
| 845 | |
| 846 | size = slab_size(s); |
| 847 | used = s->objects * s->object_size; |
| 848 | wasted = size - used; |
| 849 | objwaste = s->slab_size - s->object_size; |
| 850 | |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 851 | percentage_partial_slabs = s->partial * 100 / s->slabs; |
| 852 | if (percentage_partial_slabs > 100) |
| 853 | percentage_partial_slabs = 100; |
| 854 | |
Christoph Lameter | 205ab99 | 2008-04-14 19:11:40 +0300 | [diff] [blame] | 855 | percentage_partial_objs = s->objects_partial * 100 |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 856 | / s->objects; |
| 857 | |
| 858 | if (percentage_partial_objs > 100) |
| 859 | percentage_partial_objs = 100; |
| 860 | |
| 861 | if (s->object_size < min_objsize) |
| 862 | min_objsize = s->object_size; |
| 863 | if (s->partial < min_partial) |
| 864 | min_partial = s->partial; |
| 865 | if (s->slabs < min_slabs) |
| 866 | min_slabs = s->slabs; |
| 867 | if (size < min_size) |
| 868 | min_size = size; |
| 869 | if (wasted < min_waste) |
| 870 | min_waste = wasted; |
| 871 | if (objwaste < min_objwaste) |
| 872 | min_objwaste = objwaste; |
| 873 | if (s->objects < min_objects) |
| 874 | min_objects = s->objects; |
| 875 | if (used < min_used) |
| 876 | min_used = used; |
Christoph Lameter | 205ab99 | 2008-04-14 19:11:40 +0300 | [diff] [blame] | 877 | if (s->objects_partial < min_partobj) |
| 878 | min_partobj = s->objects_partial; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 879 | if (percentage_partial_slabs < min_ppart) |
| 880 | min_ppart = percentage_partial_slabs; |
| 881 | if (percentage_partial_objs < min_ppartobj) |
| 882 | min_ppartobj = percentage_partial_objs; |
| 883 | if (s->slab_size < min_memobj) |
| 884 | min_memobj = s->slab_size; |
| 885 | |
| 886 | if (s->object_size > max_objsize) |
| 887 | max_objsize = s->object_size; |
| 888 | if (s->partial > max_partial) |
| 889 | max_partial = s->partial; |
| 890 | if (s->slabs > max_slabs) |
| 891 | max_slabs = s->slabs; |
| 892 | if (size > max_size) |
| 893 | max_size = size; |
| 894 | if (wasted > max_waste) |
| 895 | max_waste = wasted; |
| 896 | if (objwaste > max_objwaste) |
| 897 | max_objwaste = objwaste; |
| 898 | if (s->objects > max_objects) |
| 899 | max_objects = s->objects; |
| 900 | if (used > max_used) |
| 901 | max_used = used; |
Christoph Lameter | 205ab99 | 2008-04-14 19:11:40 +0300 | [diff] [blame] | 902 | if (s->objects_partial > max_partobj) |
| 903 | max_partobj = s->objects_partial; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 904 | if (percentage_partial_slabs > max_ppart) |
| 905 | max_ppart = percentage_partial_slabs; |
| 906 | if (percentage_partial_objs > max_ppartobj) |
| 907 | max_ppartobj = percentage_partial_objs; |
| 908 | if (s->slab_size > max_memobj) |
| 909 | max_memobj = s->slab_size; |
| 910 | |
| 911 | total_partial += s->partial; |
| 912 | total_slabs += s->slabs; |
| 913 | total_size += size; |
| 914 | total_waste += wasted; |
| 915 | |
| 916 | total_objects += s->objects; |
| 917 | total_used += used; |
Christoph Lameter | 205ab99 | 2008-04-14 19:11:40 +0300 | [diff] [blame] | 918 | total_partobj += s->objects_partial; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 919 | total_ppart += percentage_partial_slabs; |
| 920 | total_ppartobj += percentage_partial_objs; |
| 921 | |
| 922 | total_objwaste += s->objects * objwaste; |
| 923 | total_objsize += s->objects * s->slab_size; |
| 924 | } |
| 925 | |
| 926 | if (!total_objects) { |
| 927 | printf("No objects\n"); |
| 928 | return; |
| 929 | } |
| 930 | if (!used_slabs) { |
| 931 | printf("No slabs\n"); |
| 932 | return; |
| 933 | } |
| 934 | |
| 935 | /* Per slab averages */ |
| 936 | avg_partial = total_partial / used_slabs; |
| 937 | avg_slabs = total_slabs / used_slabs; |
| 938 | avg_size = total_size / used_slabs; |
| 939 | avg_waste = total_waste / used_slabs; |
| 940 | |
| 941 | avg_objects = total_objects / used_slabs; |
| 942 | avg_used = total_used / used_slabs; |
| 943 | avg_partobj = total_partobj / used_slabs; |
| 944 | avg_ppart = total_ppart / used_slabs; |
| 945 | avg_ppartobj = total_ppartobj / used_slabs; |
| 946 | |
| 947 | /* Per object object sizes */ |
| 948 | avg_objsize = total_used / total_objects; |
| 949 | avg_objwaste = total_objwaste / total_objects; |
| 950 | avg_partobj = total_partobj * 100 / total_objects; |
| 951 | avg_memobj = total_objsize / total_objects; |
| 952 | |
| 953 | printf("Slabcache Totals\n"); |
| 954 | printf("----------------\n"); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 955 | printf("Slabcaches : %15d Aliases : %11d->%-3d Active: %3d\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 956 | slabs, aliases, alias_targets, used_slabs); |
| 957 | |
| 958 | store_size(b1, total_size);store_size(b2, total_waste); |
| 959 | store_size(b3, total_waste * 100 / total_used); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 960 | printf("Memory used: %15s # Loss : %15s MRatio:%6s%%\n", b1, b2, b3); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 961 | |
| 962 | store_size(b1, total_objects);store_size(b2, total_partobj); |
| 963 | store_size(b3, total_partobj * 100 / total_objects); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 964 | printf("# Objects : %15s # PartObj: %15s ORatio:%6s%%\n", b1, b2, b3); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 965 | |
| 966 | printf("\n"); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 967 | printf("Per Cache Average " |
| 968 | "Min Max Total\n"); |
| 969 | printf("---------------------------------------" |
| 970 | "-------------------------------------\n"); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 971 | |
| 972 | store_size(b1, avg_objects);store_size(b2, min_objects); |
| 973 | store_size(b3, max_objects);store_size(b4, total_objects); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 974 | printf("#Objects %15s %15s %15s %15s\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 975 | b1, b2, b3, b4); |
| 976 | |
| 977 | store_size(b1, avg_slabs);store_size(b2, min_slabs); |
| 978 | store_size(b3, max_slabs);store_size(b4, total_slabs); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 979 | printf("#Slabs %15s %15s %15s %15s\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 980 | b1, b2, b3, b4); |
| 981 | |
| 982 | store_size(b1, avg_partial);store_size(b2, min_partial); |
| 983 | store_size(b3, max_partial);store_size(b4, total_partial); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 984 | printf("#PartSlab %15s %15s %15s %15s\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 985 | b1, b2, b3, b4); |
| 986 | store_size(b1, avg_ppart);store_size(b2, min_ppart); |
| 987 | store_size(b3, max_ppart); |
| 988 | store_size(b4, total_partial * 100 / total_slabs); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 989 | printf("%%PartSlab%15s%% %15s%% %15s%% %15s%%\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 990 | b1, b2, b3, b4); |
| 991 | |
| 992 | store_size(b1, avg_partobj);store_size(b2, min_partobj); |
| 993 | store_size(b3, max_partobj); |
| 994 | store_size(b4, total_partobj); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 995 | printf("PartObjs %15s %15s %15s %15s\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 996 | b1, b2, b3, b4); |
| 997 | |
| 998 | store_size(b1, avg_ppartobj);store_size(b2, min_ppartobj); |
| 999 | store_size(b3, max_ppartobj); |
| 1000 | store_size(b4, total_partobj * 100 / total_objects); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 1001 | printf("%% PartObj%15s%% %15s%% %15s%% %15s%%\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1002 | b1, b2, b3, b4); |
| 1003 | |
| 1004 | store_size(b1, avg_size);store_size(b2, min_size); |
| 1005 | store_size(b3, max_size);store_size(b4, total_size); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 1006 | printf("Memory %15s %15s %15s %15s\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1007 | b1, b2, b3, b4); |
| 1008 | |
| 1009 | store_size(b1, avg_used);store_size(b2, min_used); |
| 1010 | store_size(b3, max_used);store_size(b4, total_used); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 1011 | printf("Used %15s %15s %15s %15s\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1012 | b1, b2, b3, b4); |
| 1013 | |
| 1014 | store_size(b1, avg_waste);store_size(b2, min_waste); |
| 1015 | store_size(b3, max_waste);store_size(b4, total_waste); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 1016 | printf("Loss %15s %15s %15s %15s\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1017 | b1, b2, b3, b4); |
| 1018 | |
| 1019 | printf("\n"); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 1020 | printf("Per Object Average " |
| 1021 | "Min Max\n"); |
| 1022 | printf("---------------------------------------" |
| 1023 | "--------------------\n"); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1024 | |
| 1025 | store_size(b1, avg_memobj);store_size(b2, min_memobj); |
| 1026 | store_size(b3, max_memobj); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 1027 | printf("Memory %15s %15s %15s\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1028 | b1, b2, b3); |
| 1029 | store_size(b1, avg_objsize);store_size(b2, min_objsize); |
| 1030 | store_size(b3, max_objsize); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 1031 | printf("User %15s %15s %15s\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1032 | b1, b2, b3); |
| 1033 | |
| 1034 | store_size(b1, avg_objwaste);store_size(b2, min_objwaste); |
| 1035 | store_size(b3, max_objwaste); |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 1036 | printf("Loss %15s %15s %15s\n", |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1037 | b1, b2, b3); |
| 1038 | } |
| 1039 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 1040 | static void sort_slabs(void) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1041 | { |
| 1042 | struct slabinfo *s1,*s2; |
| 1043 | |
| 1044 | for (s1 = slabinfo; s1 < slabinfo + slabs; s1++) { |
| 1045 | for (s2 = s1 + 1; s2 < slabinfo + slabs; s2++) { |
| 1046 | int result; |
| 1047 | |
| 1048 | if (sort_size) |
| 1049 | result = slab_size(s1) < slab_size(s2); |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 1050 | else if (sort_active) |
| 1051 | result = slab_activity(s1) < slab_activity(s2); |
Sergey Senozhatsky | 2651f6e | 2015-11-05 18:45:22 -0800 | [diff] [blame] | 1052 | else if (sort_loss) |
| 1053 | result = slab_waste(s1) < slab_waste(s2); |
Tobin C. Harding | 1106b20 | 2019-07-11 20:59:38 -0700 | [diff] [blame] | 1054 | else if (sort_partial) |
| 1055 | result = s1->partial < s2->partial; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1056 | else |
| 1057 | result = strcasecmp(s1->name, s2->name); |
| 1058 | |
| 1059 | if (show_inverted) |
| 1060 | result = -result; |
| 1061 | |
| 1062 | if (result > 0) { |
| 1063 | struct slabinfo t; |
| 1064 | |
| 1065 | memcpy(&t, s1, sizeof(struct slabinfo)); |
| 1066 | memcpy(s1, s2, sizeof(struct slabinfo)); |
| 1067 | memcpy(s2, &t, sizeof(struct slabinfo)); |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 1073 | static void sort_aliases(void) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1074 | { |
| 1075 | struct aliasinfo *a1,*a2; |
| 1076 | |
| 1077 | for (a1 = aliasinfo; a1 < aliasinfo + aliases; a1++) { |
| 1078 | for (a2 = a1 + 1; a2 < aliasinfo + aliases; a2++) { |
| 1079 | char *n1, *n2; |
| 1080 | |
| 1081 | n1 = a1->name; |
| 1082 | n2 = a2->name; |
| 1083 | if (show_alias && !show_inverted) { |
| 1084 | n1 = a1->ref; |
| 1085 | n2 = a2->ref; |
| 1086 | } |
| 1087 | if (strcasecmp(n1, n2) > 0) { |
| 1088 | struct aliasinfo t; |
| 1089 | |
| 1090 | memcpy(&t, a1, sizeof(struct aliasinfo)); |
| 1091 | memcpy(a1, a2, sizeof(struct aliasinfo)); |
| 1092 | memcpy(a2, &t, sizeof(struct aliasinfo)); |
| 1093 | } |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 1098 | static void link_slabs(void) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1099 | { |
| 1100 | struct aliasinfo *a; |
| 1101 | struct slabinfo *s; |
| 1102 | |
| 1103 | for (a = aliasinfo; a < aliasinfo + aliases; a++) { |
| 1104 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1105 | for (s = slabinfo; s < slabinfo + slabs; s++) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1106 | if (strcmp(a->ref, s->name) == 0) { |
| 1107 | a->slab = s; |
| 1108 | s->refs++; |
| 1109 | break; |
| 1110 | } |
| 1111 | if (s == slabinfo + slabs) |
| 1112 | fatal("Unresolved alias %s\n", a->ref); |
| 1113 | } |
| 1114 | } |
| 1115 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 1116 | static void alias(void) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1117 | { |
| 1118 | struct aliasinfo *a; |
| 1119 | char *active = NULL; |
| 1120 | |
| 1121 | sort_aliases(); |
| 1122 | link_slabs(); |
| 1123 | |
| 1124 | for(a = aliasinfo; a < aliasinfo + aliases; a++) { |
| 1125 | |
| 1126 | if (!show_single_ref && a->slab->refs == 1) |
| 1127 | continue; |
| 1128 | |
| 1129 | if (!show_inverted) { |
| 1130 | if (active) { |
| 1131 | if (strcmp(a->slab->name, active) == 0) { |
| 1132 | printf(" %s", a->name); |
| 1133 | continue; |
| 1134 | } |
| 1135 | } |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1136 | printf("\n%-12s <- %s", a->slab->name, a->name); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1137 | active = a->slab->name; |
| 1138 | } |
| 1139 | else |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 1140 | printf("%-15s -> %s\n", a->name, a->slab->name); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1141 | } |
| 1142 | if (active) |
| 1143 | printf("\n"); |
| 1144 | } |
| 1145 | |
| 1146 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 1147 | static void rename_slabs(void) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1148 | { |
| 1149 | struct slabinfo *s; |
| 1150 | struct aliasinfo *a; |
| 1151 | |
| 1152 | for (s = slabinfo; s < slabinfo + slabs; s++) { |
| 1153 | if (*s->name != ':') |
| 1154 | continue; |
| 1155 | |
| 1156 | if (s->refs > 1 && !show_first_alias) |
| 1157 | continue; |
| 1158 | |
| 1159 | a = find_one_alias(s); |
| 1160 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1161 | if (a) |
| 1162 | s->name = a->name; |
| 1163 | else { |
| 1164 | s->name = "*"; |
| 1165 | actual_slabs--; |
| 1166 | } |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 1170 | static int slab_mismatch(char *slab) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1171 | { |
| 1172 | return regexec(&pattern, slab, 0, NULL, 0); |
| 1173 | } |
| 1174 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 1175 | static void read_slab_dir(void) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1176 | { |
| 1177 | DIR *dir; |
| 1178 | struct dirent *de; |
| 1179 | struct slabinfo *slab = slabinfo; |
| 1180 | struct aliasinfo *alias = aliasinfo; |
| 1181 | char *p; |
| 1182 | char *t; |
| 1183 | int count; |
| 1184 | |
Christoph Lameter | b6c24de | 2008-02-04 23:35:48 -0800 | [diff] [blame] | 1185 | if (chdir("/sys/kernel/slab") && chdir("/sys/slab")) |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1186 | fatal("SYSFS support for SLUB not active\n"); |
| 1187 | |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1188 | dir = opendir("."); |
| 1189 | while ((de = readdir(dir))) { |
| 1190 | if (de->d_name[0] == '.' || |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1191 | (de->d_name[0] != ':' && slab_mismatch(de->d_name))) |
| 1192 | continue; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1193 | switch (de->d_type) { |
| 1194 | case DT_LNK: |
Christoph Lameter | 0d24db3 | 2010-10-21 13:01:56 -0500 | [diff] [blame] | 1195 | alias->name = strdup(de->d_name); |
Thomas Jarosch | fe35317 | 2011-10-17 16:48:10 +0200 | [diff] [blame] | 1196 | count = readlink(de->d_name, buffer, sizeof(buffer)-1); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1197 | |
| 1198 | if (count < 0) |
| 1199 | fatal("Cannot read symlink %s\n", de->d_name); |
| 1200 | |
| 1201 | buffer[count] = 0; |
| 1202 | p = buffer + count; |
| 1203 | while (p > buffer && p[-1] != '/') |
| 1204 | p--; |
| 1205 | alias->ref = strdup(p); |
| 1206 | alias++; |
| 1207 | break; |
| 1208 | case DT_DIR: |
| 1209 | if (chdir(de->d_name)) |
| 1210 | fatal("Unable to access slab %s\n", slab->name); |
Christoph Lameter | 0d24db3 | 2010-10-21 13:01:56 -0500 | [diff] [blame] | 1211 | slab->name = strdup(de->d_name); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1212 | slab->alias = 0; |
| 1213 | slab->refs = 0; |
| 1214 | slab->aliases = get_obj("aliases"); |
| 1215 | slab->align = get_obj("align"); |
| 1216 | slab->cache_dma = get_obj("cache_dma"); |
| 1217 | slab->cpu_slabs = get_obj("cpu_slabs"); |
| 1218 | slab->destroy_by_rcu = get_obj("destroy_by_rcu"); |
| 1219 | slab->hwcache_align = get_obj("hwcache_align"); |
| 1220 | slab->object_size = get_obj("object_size"); |
| 1221 | slab->objects = get_obj("objects"); |
Christoph Lameter | 205ab99 | 2008-04-14 19:11:40 +0300 | [diff] [blame] | 1222 | slab->objects_partial = get_obj("objects_partial"); |
| 1223 | slab->objects_total = get_obj("objects_total"); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1224 | slab->objs_per_slab = get_obj("objs_per_slab"); |
| 1225 | slab->order = get_obj("order"); |
| 1226 | slab->partial = get_obj("partial"); |
| 1227 | slab->partial = get_obj_and_str("partial", &t); |
| 1228 | decode_numa_list(slab->numa_partial, t); |
WANG Cong | f32143a | 2007-10-16 23:31:29 -0700 | [diff] [blame] | 1229 | free(t); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1230 | slab->poison = get_obj("poison"); |
| 1231 | slab->reclaim_account = get_obj("reclaim_account"); |
| 1232 | slab->red_zone = get_obj("red_zone"); |
| 1233 | slab->sanity_checks = get_obj("sanity_checks"); |
| 1234 | slab->slab_size = get_obj("slab_size"); |
| 1235 | slab->slabs = get_obj_and_str("slabs", &t); |
| 1236 | decode_numa_list(slab->numa, t); |
WANG Cong | f32143a | 2007-10-16 23:31:29 -0700 | [diff] [blame] | 1237 | free(t); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1238 | slab->store_user = get_obj("store_user"); |
| 1239 | slab->trace = get_obj("trace"); |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 1240 | slab->alloc_fastpath = get_obj("alloc_fastpath"); |
| 1241 | slab->alloc_slowpath = get_obj("alloc_slowpath"); |
| 1242 | slab->free_fastpath = get_obj("free_fastpath"); |
| 1243 | slab->free_slowpath = get_obj("free_slowpath"); |
| 1244 | slab->free_frozen= get_obj("free_frozen"); |
| 1245 | slab->free_add_partial = get_obj("free_add_partial"); |
| 1246 | slab->free_remove_partial = get_obj("free_remove_partial"); |
| 1247 | slab->alloc_from_partial = get_obj("alloc_from_partial"); |
| 1248 | slab->alloc_slab = get_obj("alloc_slab"); |
| 1249 | slab->alloc_refill = get_obj("alloc_refill"); |
| 1250 | slab->free_slab = get_obj("free_slab"); |
| 1251 | slab->cpuslab_flush = get_obj("cpuslab_flush"); |
| 1252 | slab->deactivate_full = get_obj("deactivate_full"); |
| 1253 | slab->deactivate_empty = get_obj("deactivate_empty"); |
| 1254 | slab->deactivate_to_head = get_obj("deactivate_to_head"); |
| 1255 | slab->deactivate_to_tail = get_obj("deactivate_to_tail"); |
| 1256 | slab->deactivate_remote_frees = get_obj("deactivate_remote_frees"); |
Christoph Lameter | f715e6f | 2008-04-29 16:14:46 -0700 | [diff] [blame] | 1257 | slab->order_fallback = get_obj("order_fallback"); |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 1258 | slab->cmpxchg_double_cpu_fail = get_obj("cmpxchg_double_cpu_fail"); |
| 1259 | slab->cmpxchg_double_fail = get_obj("cmpxchg_double_fail"); |
Christoph Lameter | aca726a | 2011-08-09 16:12:28 -0500 | [diff] [blame] | 1260 | slab->cpu_partial_alloc = get_obj("cpu_partial_alloc"); |
| 1261 | slab->cpu_partial_free = get_obj("cpu_partial_free"); |
Christoph Lameter | 9da4714 | 2011-06-01 12:26:00 -0500 | [diff] [blame] | 1262 | slab->alloc_node_mismatch = get_obj("alloc_node_mismatch"); |
| 1263 | slab->deactivate_bypass = get_obj("deactivate_bypass"); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1264 | chdir(".."); |
| 1265 | if (slab->name[0] == ':') |
| 1266 | alias_targets++; |
| 1267 | slab++; |
| 1268 | break; |
| 1269 | default : |
| 1270 | fatal("Unknown file type %lx\n", de->d_type); |
| 1271 | } |
| 1272 | } |
| 1273 | closedir(dir); |
| 1274 | slabs = slab - slabinfo; |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1275 | actual_slabs = slabs; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1276 | aliases = alias - aliasinfo; |
| 1277 | if (slabs > MAX_SLABS) |
| 1278 | fatal("Too many slabs\n"); |
| 1279 | if (aliases > MAX_ALIASES) |
| 1280 | fatal("Too many aliases\n"); |
| 1281 | } |
| 1282 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 1283 | static void output_slabs(void) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1284 | { |
| 1285 | struct slabinfo *slab; |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1286 | int lines = output_lines; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1287 | |
Sergey Senozhatsky | 4980a96 | 2015-11-05 18:45:20 -0800 | [diff] [blame] | 1288 | for (slab = slabinfo; (slab < slabinfo + slabs) && |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1289 | lines != 0; slab++) { |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1290 | |
| 1291 | if (slab->alias) |
| 1292 | continue; |
| 1293 | |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1294 | if (lines != -1) |
| 1295 | lines--; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1296 | |
| 1297 | if (show_numa) |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1298 | slab_numa(slab, 0); |
| 1299 | else if (show_track) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1300 | show_tracking(slab); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1301 | else if (validate) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1302 | slab_validate(slab); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1303 | else if (shrink) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1304 | slab_shrink(slab); |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1305 | else if (set_debug) |
| 1306 | slab_debug(slab); |
| 1307 | else if (show_ops) |
| 1308 | ops(slab); |
| 1309 | else if (show_slab) |
| 1310 | slabcache(slab); |
Christoph Lameter | eefaca9 | 2007-05-16 22:10:55 -0700 | [diff] [blame] | 1311 | else if (show_report) |
| 1312 | report(slab); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | |
Tobin C. Harding | 1106b20 | 2019-07-11 20:59:38 -0700 | [diff] [blame] | 1316 | static void _xtotals(char *heading, char *underline, |
| 1317 | int loss, int size, int partial) |
| 1318 | { |
| 1319 | printf("%s%s", heading, underline); |
| 1320 | line = 0; |
| 1321 | sort_loss = loss; |
| 1322 | sort_size = size; |
| 1323 | sort_partial = partial; |
| 1324 | sort_slabs(); |
| 1325 | output_slabs(); |
| 1326 | } |
| 1327 | |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1328 | static void xtotals(void) |
| 1329 | { |
Tobin C. Harding | 1106b20 | 2019-07-11 20:59:38 -0700 | [diff] [blame] | 1330 | char *heading, *underline; |
| 1331 | |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1332 | totals(); |
| 1333 | |
| 1334 | link_slabs(); |
| 1335 | rename_slabs(); |
| 1336 | |
Tobin C. Harding | 1106b20 | 2019-07-11 20:59:38 -0700 | [diff] [blame] | 1337 | heading = "\nSlabs sorted by size\n"; |
| 1338 | underline = "--------------------\n"; |
| 1339 | _xtotals(heading, underline, 0, 1, 0); |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1340 | |
Tobin C. Harding | 1106b20 | 2019-07-11 20:59:38 -0700 | [diff] [blame] | 1341 | heading = "\nSlabs sorted by loss\n"; |
| 1342 | underline = "--------------------\n"; |
| 1343 | _xtotals(heading, underline, 1, 0, 0); |
| 1344 | |
| 1345 | heading = "\nSlabs sorted by number of partial slabs\n"; |
| 1346 | underline = "---------------------------------------\n"; |
| 1347 | _xtotals(heading, underline, 0, 0, 1); |
| 1348 | |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1349 | printf("\n"); |
| 1350 | } |
| 1351 | |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1352 | struct option opts[] = { |
Sergey Senozhatsky | 2b10075 | 2015-11-05 18:45:17 -0800 | [diff] [blame] | 1353 | { "aliases", no_argument, NULL, 'a' }, |
| 1354 | { "activity", no_argument, NULL, 'A' }, |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1355 | { "Bytes", no_argument, NULL, 'B'}, |
Sergey Senozhatsky | 2b10075 | 2015-11-05 18:45:17 -0800 | [diff] [blame] | 1356 | { "debug", optional_argument, NULL, 'd' }, |
| 1357 | { "display-activity", no_argument, NULL, 'D' }, |
| 1358 | { "empty", no_argument, NULL, 'e' }, |
| 1359 | { "first-alias", no_argument, NULL, 'f' }, |
| 1360 | { "help", no_argument, NULL, 'h' }, |
| 1361 | { "inverted", no_argument, NULL, 'i'}, |
Sergey Senozhatsky | 0d00bf5 | 2015-11-05 18:45:25 -0800 | [diff] [blame] | 1362 | { "slabs", no_argument, NULL, 'l' }, |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1363 | { "Loss", no_argument, NULL, 'L'}, |
Sergey Senozhatsky | 2b10075 | 2015-11-05 18:45:17 -0800 | [diff] [blame] | 1364 | { "numa", no_argument, NULL, 'n' }, |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1365 | { "lines", required_argument, NULL, 'N'}, |
Sergey Senozhatsky | 2b10075 | 2015-11-05 18:45:17 -0800 | [diff] [blame] | 1366 | { "ops", no_argument, NULL, 'o' }, |
Tobin C. Harding | 53a83f9 | 2019-07-11 20:59:42 -0700 | [diff] [blame] | 1367 | { "partial", no_argument, NULL, 'p'}, |
Sergey Senozhatsky | 0d00bf5 | 2015-11-05 18:45:25 -0800 | [diff] [blame] | 1368 | { "report", no_argument, NULL, 'r' }, |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1369 | { "shrink", no_argument, NULL, 's' }, |
Sergey Senozhatsky | 0d00bf5 | 2015-11-05 18:45:25 -0800 | [diff] [blame] | 1370 | { "Size", no_argument, NULL, 'S'}, |
| 1371 | { "tracking", no_argument, NULL, 't'}, |
| 1372 | { "Totals", no_argument, NULL, 'T'}, |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1373 | { "Unreclaim", no_argument, NULL, 'U'}, |
Sergey Senozhatsky | 2b10075 | 2015-11-05 18:45:17 -0800 | [diff] [blame] | 1374 | { "validate", no_argument, NULL, 'v' }, |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1375 | { "Xtotals", no_argument, NULL, 'X'}, |
Sergey Senozhatsky | 2b10075 | 2015-11-05 18:45:17 -0800 | [diff] [blame] | 1376 | { "zero", no_argument, NULL, 'z' }, |
| 1377 | { "1ref", no_argument, NULL, '1'}, |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1378 | { NULL, 0, NULL, 0 } |
| 1379 | }; |
| 1380 | |
| 1381 | int main(int argc, char *argv[]) |
| 1382 | { |
| 1383 | int c; |
| 1384 | int err; |
| 1385 | char *pattern_source; |
| 1386 | |
| 1387 | page_size = getpagesize(); |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1388 | |
Tobin C. Harding | 53a83f9 | 2019-07-11 20:59:42 -0700 | [diff] [blame] | 1389 | while ((c = getopt_long(argc, argv, "aABd::DefhilLnN:oPrsStTUvXz1", |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1390 | opts, NULL)) != -1) |
WANG Cong | f32143a | 2007-10-16 23:31:29 -0700 | [diff] [blame] | 1391 | switch (c) { |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1392 | case 'a': |
| 1393 | show_alias = 1; |
| 1394 | break; |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 1395 | case 'A': |
| 1396 | sort_active = 1; |
| 1397 | break; |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1398 | case 'B': |
| 1399 | show_bytes = 1; |
| 1400 | break; |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1401 | case 'd': |
| 1402 | set_debug = 1; |
| 1403 | if (!debug_opt_scan(optarg)) |
| 1404 | fatal("Invalid debug option '%s'\n", optarg); |
| 1405 | break; |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 1406 | case 'D': |
| 1407 | show_activity = 1; |
| 1408 | break; |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1409 | case 'e': |
| 1410 | show_empty = 1; |
| 1411 | break; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1412 | case 'f': |
| 1413 | show_first_alias = 1; |
| 1414 | break; |
| 1415 | case 'h': |
| 1416 | usage(); |
| 1417 | return 0; |
| 1418 | case 'i': |
| 1419 | show_inverted = 1; |
| 1420 | break; |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1421 | case 'l': |
| 1422 | show_slab = 1; |
| 1423 | break; |
| 1424 | case 'L': |
| 1425 | sort_loss = 1; |
| 1426 | break; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1427 | case 'n': |
| 1428 | show_numa = 1; |
| 1429 | break; |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1430 | case 'N': |
| 1431 | if (optarg) { |
| 1432 | output_lines = atoi(optarg); |
| 1433 | if (output_lines < 1) |
| 1434 | output_lines = 1; |
| 1435 | } |
| 1436 | break; |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1437 | case 'o': |
| 1438 | show_ops = 1; |
| 1439 | break; |
| 1440 | case 'r': |
| 1441 | show_report = 1; |
| 1442 | break; |
Tobin C. Harding | 53a83f9 | 2019-07-11 20:59:42 -0700 | [diff] [blame] | 1443 | case 'P': |
| 1444 | sort_partial = 1; |
| 1445 | break; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1446 | case 's': |
| 1447 | shrink = 1; |
| 1448 | break; |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1449 | case 'S': |
| 1450 | sort_size = 1; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1451 | break; |
| 1452 | case 't': |
| 1453 | show_track = 1; |
| 1454 | break; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1455 | case 'T': |
| 1456 | show_totals = 1; |
| 1457 | break; |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1458 | case 'U': |
| 1459 | unreclaim_only = 1; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1460 | break; |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1461 | case 'v': |
| 1462 | validate = 1; |
Sergey Senozhatsky | 2651f6e | 2015-11-05 18:45:22 -0800 | [diff] [blame] | 1463 | break; |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1464 | case 'X': |
| 1465 | if (output_lines == -1) |
| 1466 | output_lines = 1; |
| 1467 | extended_totals = 1; |
Sergey Senozhatsky | a8ea0bf | 2015-11-05 18:45:31 -0800 | [diff] [blame] | 1468 | show_bytes = 1; |
| 1469 | break; |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1470 | case 'z': |
| 1471 | skip_zero = 0; |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1472 | break; |
Tobin C. Harding | d914999 | 2019-07-11 20:59:34 -0700 | [diff] [blame] | 1473 | case '1': |
| 1474 | show_single_ref = 1; |
Yang Shi | 7ad3f18 | 2017-11-15 17:31:59 -0800 | [diff] [blame] | 1475 | break; |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1476 | default: |
| 1477 | fatal("%s: Invalid option '%c'\n", argv[0], optopt); |
| 1478 | |
| 1479 | } |
| 1480 | |
Christoph Lameter | a87615b | 2007-05-09 02:32:37 -0700 | [diff] [blame] | 1481 | if (!show_slab && !show_alias && !show_track && !show_report |
| 1482 | && !validate && !shrink && !set_debug && !show_ops) |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1483 | show_slab = 1; |
| 1484 | |
| 1485 | if (argc > optind) |
| 1486 | pattern_source = argv[optind]; |
| 1487 | else |
| 1488 | pattern_source = ".*"; |
| 1489 | |
| 1490 | err = regcomp(&pattern, pattern_source, REG_ICASE|REG_NOSUB); |
| 1491 | if (err) |
| 1492 | fatal("%s: Invalid pattern '%s' code %d\n", |
| 1493 | argv[0], pattern_source, err); |
| 1494 | read_slab_dir(); |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1495 | if (show_alias) { |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1496 | alias(); |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1497 | } else if (extended_totals) { |
| 1498 | xtotals(); |
| 1499 | } else if (show_totals) { |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1500 | totals(); |
Sergey Senozhatsky | 016c6cd | 2015-11-05 18:45:28 -0800 | [diff] [blame] | 1501 | } else { |
Christoph Lameter | c09d875 | 2007-05-06 14:49:48 -0700 | [diff] [blame] | 1502 | link_slabs(); |
| 1503 | rename_slabs(); |
| 1504 | sort_slabs(); |
| 1505 | output_slabs(); |
| 1506 | } |
| 1507 | return 0; |
| 1508 | } |