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