blob: 97715b73af70e5691894df28c6878a5b89b662c4 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Christoph Lameterc09d8752007-05-06 14:49:48 -07002/*
3 * Slabinfo: Tool to get reports about slabs
4 *
Christoph Lametercde53532008-07-04 09:59:22 -07005 * (C) 2007 sgi, Christoph Lameter
Christoph Lameter9da47142011-06-01 12:26:00 -05006 * (C) 2011 Linux Foundation, Christoph Lameter
Christoph Lameterc09d8752007-05-06 14:49:48 -07007 *
Christoph Lameter9da47142011-06-01 12:26:00 -05008 * Compile with:
Christoph Lameterc09d8752007-05-06 14:49:48 -07009 *
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 Congf32143a2007-10-16 23:31:29 -070016#include <strings.h>
Christoph Lameterc09d8752007-05-06 14:49:48 -070017#include <string.h>
18#include <unistd.h>
19#include <stdarg.h>
20#include <getopt.h>
21#include <regex.h>
Christoph Lametera87615b2007-05-09 02:32:37 -070022#include <errno.h>
Christoph Lameterc09d8752007-05-06 14:49:48 -070023
24#define MAX_SLABS 500
25#define MAX_ALIASES 500
26#define MAX_NODES 1024
27
28struct slabinfo {
29 char *name;
30 int alias;
31 int refs;
32 int aliases, align, cache_dma, cpu_slabs, destroy_by_rcu;
Naoya Horiguchi90450652018-09-04 15:45:48 -070033 unsigned int hwcache_align, object_size, objs_per_slab;
34 unsigned int sanity_checks, slab_size, store_user, trace;
Christoph Lameterc09d8752007-05-06 14:49:48 -070035 int order, poison, reclaim_account, red_zone;
Christoph Lameter205ab992008-04-14 19:11:40 +030036 unsigned long partial, objects, slabs, objects_partial, objects_total;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -080037 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 Lameterf715e6f2008-04-29 16:14:46 -070043 unsigned long deactivate_remote_frees, order_fallback;
Christoph Lameter9da47142011-06-01 12:26:00 -050044 unsigned long cmpxchg_double_cpu_fail, cmpxchg_double_fail;
45 unsigned long alloc_node_mismatch, deactivate_bypass;
Christoph Lameteraca726a2011-08-09 16:12:28 -050046 unsigned long cpu_partial_alloc, cpu_partial_free;
Christoph Lameterc09d8752007-05-06 14:49:48 -070047 int numa[MAX_NODES];
48 int numa_partial[MAX_NODES];
49} slabinfo[MAX_SLABS];
50
51struct aliasinfo {
52 char *name;
53 char *ref;
54 struct slabinfo *slab;
55} aliasinfo[MAX_ALIASES];
56
Sergey Senozhatsky2cee6112015-11-05 18:45:34 -080057int slabs;
58int actual_slabs;
59int aliases;
60int alias_targets;
61int highest_node;
Christoph Lameterc09d8752007-05-06 14:49:48 -070062
63char buffer[4096];
64
Sergey Senozhatsky2cee6112015-11-05 18:45:34 -080065int show_empty;
66int show_report;
67int show_alias;
68int show_slab;
Christoph Lameterc09d8752007-05-06 14:49:48 -070069int skip_zero = 1;
Sergey Senozhatsky2cee6112015-11-05 18:45:34 -080070int show_numa;
71int show_track;
72int show_first_alias;
73int validate;
74int shrink;
75int show_inverted;
76int show_single_ref;
77int show_totals;
78int sort_size;
79int sort_active;
80int set_debug;
81int show_ops;
82int show_activity;
Sergey Senozhatsky4980a962015-11-05 18:45:20 -080083int output_lines = -1;
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -080084int sort_loss;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -080085int extended_totals;
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -080086int show_bytes;
Yang Shi7ad3f182017-11-15 17:31:59 -080087int unreclaim_only;
Christoph Lametera87615b2007-05-09 02:32:37 -070088
89/* Debug options */
Sergey Senozhatsky2cee6112015-11-05 18:45:34 -080090int sanity;
91int redzone;
92int poison;
93int tracking;
94int tracing;
Christoph Lameterc09d8752007-05-06 14:49:48 -070095
96int page_size;
97
98regex_t pattern;
99
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700100static void fatal(const char *x, ...)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700101{
102 va_list ap;
103
104 va_start(ap, x);
105 vfprintf(stderr, x, ap);
106 va_end(ap);
WANG Congf32143a2007-10-16 23:31:29 -0700107 exit(EXIT_FAILURE);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700108}
109
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700110static void usage(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700111{
Christoph Lameter9da47142011-06-01 12:26:00 -0500112 printf("slabinfo 4/15/2011. (c) 2007 sgi/(c) 2011 Linux Foundation.\n\n"
Tobin C. Harding402ad962019-03-05 15:48:59 -0800113 "slabinfo [-aADefhilnosrStTvz1LXBU] [N=K] [-dafzput] [slab-regexp]\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700114 "-a|--aliases Show aliases\n"
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800115 "-A|--activity Most active slabs first\n"
Tobin C. Hardingb80fd302019-03-05 15:49:03 -0800116 "-B|--Bytes Show size in bytes\n"
Christoph Lametera87615b2007-05-09 02:32:37 -0700117 "-d<options>|--debug=<options> Set/Clear Debug options\n"
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800118 "-D|--display-active Switch line format to activity\n"
119 "-e|--empty Show empty slabs\n"
Christoph Lametera87615b2007-05-09 02:32:37 -0700120 "-f|--first-alias Show first alias\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700121 "-h|--help Show usage information\n"
Christoph Lametera87615b2007-05-09 02:32:37 -0700122 "-i|--inverted Inverted list\n"
123 "-l|--slabs Show slabs\n"
Tobin C. Hardingb80fd302019-03-05 15:49:03 -0800124 "-L|--Loss Sort by loss\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700125 "-n|--numa Show NUMA information\n"
Tobin C. Hardingb80fd302019-03-05 15:49:03 -0800126 "-N|--lines=K Show the first K slabs\n"
Tobin C. Harding3c89ff92019-03-05 15:49:07 -0800127 "-o|--ops Show kmem_cache_ops\n"
128 "-r|--report Detailed report on single slabs\n"
Tobin C. Hardingb80fd302019-03-05 15:49:03 -0800129 "-s|--shrink Shrink slabs\n"
Christoph Lametera87615b2007-05-09 02:32:37 -0700130 "-S|--Size Sort by size\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700131 "-t|--tracking Show alloc/free information\n"
132 "-T|--Totals Show summary information\n"
Tobin C. Harding3c89ff92019-03-05 15:49:07 -0800133 "-U|--Unreclaim Show unreclaimable slabs only\n"
Christoph Lametera87615b2007-05-09 02:32:37 -0700134 "-v|--validate Validate slabs\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700135 "-z|--zero Include empty slabs\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700136 "-1|--1ref Single reference\n"
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -0800137 "-X|--Xtotals Show extended summary information\n"
Tobin C. Hardingb80fd302019-03-05 15:49:03 -0800138
Christoph Lametera87615b2007-05-09 02:32:37 -0700139 "\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 Abbottbecfda62016-03-15 14:55:06 -0700142 "f / F Sanity Checks (SLAB_CONSISTENCY_CHECKS)\n"
Christoph Lametera87615b2007-05-09 02:32:37 -0700143 "z / Z Redzoning\n"
144 "p / P Poisoning\n"
145 "u / U Tracking\n"
146 "t / T Tracing\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700147 );
148}
149
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700150static unsigned long read_obj(const char *name)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700151{
152 FILE *f = fopen(name, "r");
153
154 if (!f)
155 buffer[0] = 0;
156 else {
WANG Congf32143a2007-10-16 23:31:29 -0700157 if (!fgets(buffer, sizeof(buffer), f))
Christoph Lameterc09d8752007-05-06 14:49:48 -0700158 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 Chandrasingheb7ed6982009-09-22 16:43:42 -0700170static unsigned long get_obj(const char *name)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700171{
172 if (!read_obj(name))
173 return 0;
174
175 return atol(buffer);
176}
177
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700178static unsigned long get_obj_and_str(const char *name, char **x)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700179{
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 Chandrasingheb7ed6982009-09-22 16:43:42 -0700197static void set_obj(struct slabinfo *s, const char *name, int n)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700198{
199 char x[100];
Christoph Lametera87615b2007-05-09 02:32:37 -0700200 FILE *f;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700201
WANG Congf32143a2007-10-16 23:31:29 -0700202 snprintf(x, 100, "%s/%s", s->name, name);
Christoph Lametera87615b2007-05-09 02:32:37 -0700203 f = fopen(x, "w");
Christoph Lameterc09d8752007-05-06 14:49:48 -0700204 if (!f)
205 fatal("Cannot write to %s\n", x);
206
207 fprintf(f, "%d\n", n);
208 fclose(f);
209}
210
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700211static unsigned long read_slab_obj(struct slabinfo *s, const char *name)
Christoph Lametera87615b2007-05-09 02:32:37 -0700212{
213 char x[100];
214 FILE *f;
WANG Congf32143a2007-10-16 23:31:29 -0700215 size_t l;
Christoph Lametera87615b2007-05-09 02:32:37 -0700216
WANG Congf32143a2007-10-16 23:31:29 -0700217 snprintf(x, 100, "%s/%s", s->name, name);
Christoph Lametera87615b2007-05-09 02:32:37 -0700218 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 Lameterc09d8752007-05-06 14:49:48 -0700231/*
232 * Put a size string together
233 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700234static int store_size(char *buffer, unsigned long value)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700235{
236 unsigned long divisor = 1;
237 char trailer = 0;
238 int n;
239
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800240 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 Lameterc09d8752007-05-06 14:49:48 -0700251 }
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 Chandrasingheb7ed6982009-09-22 16:43:42 -0700268static void decode_numa_list(int *numa, char *t)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700269{
270 int node;
271 int nr;
272
273 memset(numa, 0, MAX_NODES * sizeof(int));
274
Christoph Lametereefaca92007-05-16 22:10:55 -0700275 if (!t)
276 return;
277
Christoph Lameterc09d8752007-05-06 14:49:48 -0700278 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 Chandrasingheb7ed6982009-09-22 16:43:42 -0700293static void slab_validate(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700294{
Christoph Lameter32f93062007-05-18 00:36:43 -0700295 if (strcmp(s->name, "*") == 0)
296 return;
297
Christoph Lameterc09d8752007-05-06 14:49:48 -0700298 set_obj(s, "validate", 1);
299}
300
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700301static void slab_shrink(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700302{
Christoph Lameter32f93062007-05-18 00:36:43 -0700303 if (strcmp(s->name, "*") == 0)
304 return;
305
Christoph Lameterc09d8752007-05-06 14:49:48 -0700306 set_obj(s, "shrink", 1);
307}
308
309int line = 0;
310
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700311static void first_line(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700312{
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800313 if (show_activity)
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800314 printf("Name Objects Alloc Free"
315 " %%Fast Fallb O CmpX UL\n");
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800316 else
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800317 printf("Name Objects Objsize %s "
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -0800318 "Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n",
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800319 sort_loss ? " Loss" : "Space");
Christoph Lameterc09d8752007-05-06 14:49:48 -0700320}
321
322/*
323 * Find the shortest alias of a slab
324 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700325static struct aliasinfo *find_one_alias(struct slabinfo *find)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700326{
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 Lametera87615b2007-05-09 02:32:37 -0700338 return best;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700339}
340
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700341static unsigned long slab_size(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700342{
343 return s->slabs * (page_size << s->order);
344}
345
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700346static unsigned long slab_activity(struct slabinfo *s)
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800347{
348 return s->alloc_fastpath + s->free_fastpath +
349 s->alloc_slowpath + s->free_slowpath;
350}
351
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -0800352static unsigned long slab_waste(struct slabinfo *s)
353{
354 return slab_size(s) - s->objects * s->object_size;
355}
356
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700357static void slab_numa(struct slabinfo *s, int mode)
Christoph Lametera87615b2007-05-09 02:32:37 -0700358{
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 Chandrasingheb7ed6982009-09-22 16:43:42 -0700402static void show_tracking(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700403{
404 printf("\n%s: Kernel object allocation\n", s->name);
405 printf("-----------------------------------------------------------------------\n");
406 if (read_slab_obj(s, "alloc_calls"))
Christoph Lameter9da47142011-06-01 12:26:00 -0500407 printf("%s", buffer);
Christoph Lametera87615b2007-05-09 02:32:37 -0700408 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 Lameter9da47142011-06-01 12:26:00 -0500414 printf("%s", buffer);
Christoph Lametera87615b2007-05-09 02:32:37 -0700415 else
416 printf("No Data\n");
417
418}
419
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700420static void ops(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700421{
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 Lameter9da47142011-06-01 12:26:00 -0500428 printf("%s", buffer);
Christoph Lametera87615b2007-05-09 02:32:37 -0700429 } else
430 printf("\n%s has no kmem_cache operations\n", s->name);
431}
432
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700433static const char *onoff(int x)
Christoph Lametera87615b2007-05-09 02:32:37 -0700434{
435 if (x)
436 return "On ";
437 return "Off";
438}
439
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700440static void slab_stats(struct slabinfo *s)
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800441{
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,
majianpeng4b57ad92012-06-26 09:30:31 +0800461 total_free ? s->free_fastpath * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800462 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,
majianpeng4b57ad92012-06-26 09:30:31 +0800465 total_free ? s->free_slowpath * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800466 printf("Page Alloc %8lu %8lu %3lu %3lu\n",
467 s->alloc_slab, s->free_slab,
468 s->alloc_slab * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800469 total_free ? s->free_slab * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800470 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,
majianpeng4b57ad92012-06-26 09:30:31 +0800474 total_free ? s->free_add_partial * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800475 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,
majianpeng4b57ad92012-06-26 09:30:31 +0800478 total_free ? s->free_remove_partial * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800479
Christoph Lameteraca726a2011-08-09 16:12:28 -0500480 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,
majianpeng4b57ad92012-06-26 09:30:31 +0800483 total_free ? s->cpu_partial_free * 100 / total_free : 0);
Christoph Lameteraca726a2011-08-09 16:12:28 -0500484
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800485 printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n",
486 s->deactivate_remote_frees, s->free_frozen,
487 s->deactivate_remote_frees * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800488 total_free ? s->free_frozen * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800489
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 Lameter8ff12cf2008-02-07 17:47:41 -0800495 total = s->deactivate_full + s->deactivate_empty +
Christoph Lameter9da47142011-06-01 12:26:00 -0500496 s->deactivate_to_head + s->deactivate_to_tail + s->deactivate_bypass;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800497
Christoph Lameter9da47142011-06-01 12:26:00 -0500498 if (total) {
Colin Ian King7c5b7232016-06-24 14:50:21 -0700499 printf("\nSlab Deactivation Occurrences %%\n");
Christoph Lameter9da47142011-06-01 12:26:00 -0500500 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 Lameter8ff12cf2008-02-07 17:47:41 -0800508 s->deactivate_to_tail, (s->deactivate_to_tail * 100) / total);
Christoph Lameter9da47142011-06-01 12:26:00 -0500509 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 Carpenter2d6a4d62016-07-20 15:45:05 -0700517 if (s->cmpxchg_double_fail || s->cmpxchg_double_cpu_fail) {
Christoph Lameter9da47142011-06-01 12:26:00 -0500518 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 Carpenter2d6a4d62016-07-20 15:45:05 -0700521 }
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800522}
523
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700524static void report(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700525{
526 if (strcmp(s->name, "*") == 0)
527 return;
Christoph Lametereefaca92007-05-16 22:10:55 -0700528
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800529 printf("\nSlabcache: %-15s Aliases: %2d Order : %2d Objects: %lu\n",
Christoph Lametereefaca92007-05-16 22:10:55 -0700530 s->name, s->aliases, s->order, s->objects);
Christoph Lametera87615b2007-05-09 02:32:37 -0700531 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 Lameter8ff12cf2008-02-07 17:47:41 -0800562 slab_stats(s);
Christoph Lametera87615b2007-05-09 02:32:37 -0700563}
Christoph Lameterc09d8752007-05-06 14:49:48 -0700564
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700565static void slabcache(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700566{
567 char size_str[20];
568 char dist_str[40];
569 char flags[20];
570 char *p = flags;
571
Christoph Lametera87615b2007-05-09 02:32:37 -0700572 if (strcmp(s->name, "*") == 0)
573 return;
574
Yang Shi7ad3f182017-11-15 17:31:59 -0800575 if (unreclaim_only && s->reclaim_account)
576 return;
577
Christoph Lametera87615b2007-05-09 02:32:37 -0700578 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 Lameterc09d8752007-05-06 14:49:48 -0700587 return;
588
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -0800589 if (sort_loss == 0)
590 store_size(size_str, slab_size(s));
591 else
592 store_size(size_str, slab_waste(s));
Christoph Lameter205ab992008-04-14 19:11:40 +0300593 snprintf(dist_str, 40, "%lu/%lu/%d", s->slabs - s->cpu_slabs,
594 s->partial, s->cpu_slabs);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700595
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 Lameter8ff12cf2008-02-07 17:47:41 -0800619 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 Lameter9da47142011-06-01 12:26:00 -0500626 printf("%-21s %8ld %10ld %10ld %3ld %3ld %5ld %1d %4ld %4ld\n",
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800627 s->name, s->objects,
628 total_alloc, total_free,
629 total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0,
Christoph Lameterf715e6f2008-04-29 16:14:46 -0700630 total_free ? (s->free_fastpath * 100 / total_free) : 0,
Christoph Lameter9da47142011-06-01 12:26:00 -0500631 s->order_fallback, s->order, s->cmpxchg_double_fail,
632 s->cmpxchg_double_cpu_fail);
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -0800633 } else {
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800634 printf("%-21s %8ld %7d %15s %14s %4d %1d %3ld %3ld %s\n",
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800635 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 Senozhatsky016c6cd2015-11-05 18:45:28 -0800641 }
Christoph Lameterc09d8752007-05-06 14:49:48 -0700642}
643
Christoph Lametera87615b2007-05-09 02:32:37 -0700644/*
645 * Analyze debug options. Return false if something is amiss.
646 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700647static int debug_opt_scan(char *opt)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700648{
Christoph Lametera87615b2007-05-09 02:32:37 -0700649 if (!opt || !opt[0] || strcmp(opt, "-") == 0)
650 return 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700651
Christoph Lametera87615b2007-05-09 02:32:37 -0700652 if (strcasecmp(opt, "a") == 0) {
653 sanity = 1;
654 poison = 1;
655 redzone = 1;
656 tracking = 1;
657 return 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700658 }
Christoph Lameterc09d8752007-05-06 14:49:48 -0700659
Christoph Lametera87615b2007-05-09 02:32:37 -0700660 for ( ; *opt; opt++)
Christoph Lameter0d24db32010-10-21 13:01:56 -0500661 switch (*opt) {
Christoph Lametera87615b2007-05-09 02:32:37 -0700662 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 Lameterc09d8752007-05-06 14:49:48 -0700694}
695
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700696static int slab_empty(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700697{
Christoph Lametera87615b2007-05-09 02:32:37 -0700698 if (s->objects > 0)
699 return 0;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700700
Christoph Lametera87615b2007-05-09 02:32:37 -0700701 /*
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 Lameterc09d8752007-05-06 14:49:48 -0700707
Christoph Lametera87615b2007-05-09 02:32:37 -0700708 return 1;
709}
710
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700711static void slab_debug(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700712{
Christoph Lameter32f93062007-05-18 00:36:43 -0700713 if (strcmp(s->name, "*") == 0)
714 return;
715
Christoph Lametera87615b2007-05-09 02:32:37 -0700716 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 Lameterc09d8752007-05-06 14:49:48 -0700769}
770
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700771static void totals(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700772{
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 Lameterc09d8752007-05-06 14:49:48 -0700832 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 Lameterc09d8752007-05-06 14:49:48 -0700845 percentage_partial_slabs = s->partial * 100 / s->slabs;
846 if (percentage_partial_slabs > 100)
847 percentage_partial_slabs = 100;
848
Christoph Lameter205ab992008-04-14 19:11:40 +0300849 percentage_partial_objs = s->objects_partial * 100
Christoph Lameterc09d8752007-05-06 14:49:48 -0700850 / 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 Lameter205ab992008-04-14 19:11:40 +0300871 if (s->objects_partial < min_partobj)
872 min_partobj = s->objects_partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700873 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 Lameter205ab992008-04-14 19:11:40 +0300896 if (s->objects_partial > max_partobj)
897 max_partobj = s->objects_partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700898 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 Lameter205ab992008-04-14 19:11:40 +0300912 total_partobj += s->objects_partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700913 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 Senozhatskya8ea0bf2015-11-05 18:45:31 -0800949 printf("Slabcaches : %15d Aliases : %11d->%-3d Active: %3d\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700950 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 Senozhatskya8ea0bf2015-11-05 18:45:31 -0800954 printf("Memory used: %15s # Loss : %15s MRatio:%6s%%\n", b1, b2, b3);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700955
956 store_size(b1, total_objects);store_size(b2, total_partobj);
957 store_size(b3, total_partobj * 100 / total_objects);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800958 printf("# Objects : %15s # PartObj: %15s ORatio:%6s%%\n", b1, b2, b3);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700959
960 printf("\n");
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800961 printf("Per Cache Average "
962 "Min Max Total\n");
963 printf("---------------------------------------"
964 "-------------------------------------\n");
Christoph Lameterc09d8752007-05-06 14:49:48 -0700965
966 store_size(b1, avg_objects);store_size(b2, min_objects);
967 store_size(b3, max_objects);store_size(b4, total_objects);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800968 printf("#Objects %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700969 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 Senozhatskya8ea0bf2015-11-05 18:45:31 -0800973 printf("#Slabs %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700974 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 Senozhatskya8ea0bf2015-11-05 18:45:31 -0800978 printf("#PartSlab %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700979 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 Senozhatskya8ea0bf2015-11-05 18:45:31 -0800983 printf("%%PartSlab%15s%% %15s%% %15s%% %15s%%\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700984 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 Senozhatskya8ea0bf2015-11-05 18:45:31 -0800989 printf("PartObjs %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700990 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 Senozhatskya8ea0bf2015-11-05 18:45:31 -0800995 printf("%% PartObj%15s%% %15s%% %15s%% %15s%%\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700996 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 Senozhatskya8ea0bf2015-11-05 18:45:31 -08001000 printf("Memory %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001001 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 Senozhatskya8ea0bf2015-11-05 18:45:31 -08001005 printf("Used %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001006 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 Senozhatskya8ea0bf2015-11-05 18:45:31 -08001010 printf("Loss %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001011 b1, b2, b3, b4);
1012
1013 printf("\n");
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001014 printf("Per Object Average "
1015 "Min Max\n");
1016 printf("---------------------------------------"
1017 "--------------------\n");
Christoph Lameterc09d8752007-05-06 14:49:48 -07001018
1019 store_size(b1, avg_memobj);store_size(b2, min_memobj);
1020 store_size(b3, max_memobj);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001021 printf("Memory %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001022 b1, b2, b3);
1023 store_size(b1, avg_objsize);store_size(b2, min_objsize);
1024 store_size(b3, max_objsize);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001025 printf("User %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001026 b1, b2, b3);
1027
1028 store_size(b1, avg_objwaste);store_size(b2, min_objwaste);
1029 store_size(b3, max_objwaste);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001030 printf("Loss %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001031 b1, b2, b3);
1032}
1033
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001034static void sort_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001035{
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 Lameter8ff12cf2008-02-07 17:47:41 -08001044 else if (sort_active)
1045 result = slab_activity(s1) < slab_activity(s2);
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -08001046 else if (sort_loss)
1047 result = slab_waste(s1) < slab_waste(s2);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001048 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 Chandrasingheb7ed6982009-09-22 16:43:42 -07001065static void sort_aliases(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001066{
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 Chandrasingheb7ed6982009-09-22 16:43:42 -07001090static void link_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001091{
1092 struct aliasinfo *a;
1093 struct slabinfo *s;
1094
1095 for (a = aliasinfo; a < aliasinfo + aliases; a++) {
1096
Christoph Lametera87615b2007-05-09 02:32:37 -07001097 for (s = slabinfo; s < slabinfo + slabs; s++)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001098 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 Chandrasingheb7ed6982009-09-22 16:43:42 -07001108static void alias(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001109{
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 Lametera87615b2007-05-09 02:32:37 -07001128 printf("\n%-12s <- %s", a->slab->name, a->name);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001129 active = a->slab->name;
1130 }
1131 else
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001132 printf("%-15s -> %s\n", a->name, a->slab->name);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001133 }
1134 if (active)
1135 printf("\n");
1136}
1137
1138
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001139static void rename_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001140{
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 Lametera87615b2007-05-09 02:32:37 -07001153 if (a)
1154 s->name = a->name;
1155 else {
1156 s->name = "*";
1157 actual_slabs--;
1158 }
Christoph Lameterc09d8752007-05-06 14:49:48 -07001159 }
1160}
1161
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001162static int slab_mismatch(char *slab)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001163{
1164 return regexec(&pattern, slab, 0, NULL, 0);
1165}
1166
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001167static void read_slab_dir(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001168{
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 Lameterb6c24de2008-02-04 23:35:48 -08001177 if (chdir("/sys/kernel/slab") && chdir("/sys/slab"))
Christoph Lametera87615b2007-05-09 02:32:37 -07001178 fatal("SYSFS support for SLUB not active\n");
1179
Christoph Lameterc09d8752007-05-06 14:49:48 -07001180 dir = opendir(".");
1181 while ((de = readdir(dir))) {
1182 if (de->d_name[0] == '.' ||
Christoph Lametera87615b2007-05-09 02:32:37 -07001183 (de->d_name[0] != ':' && slab_mismatch(de->d_name)))
1184 continue;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001185 switch (de->d_type) {
1186 case DT_LNK:
Christoph Lameter0d24db32010-10-21 13:01:56 -05001187 alias->name = strdup(de->d_name);
Thomas Jaroschfe353172011-10-17 16:48:10 +02001188 count = readlink(de->d_name, buffer, sizeof(buffer)-1);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001189
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 Lameter0d24db32010-10-21 13:01:56 -05001203 slab->name = strdup(de->d_name);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001204 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 Lameter205ab992008-04-14 19:11:40 +03001214 slab->objects_partial = get_obj("objects_partial");
1215 slab->objects_total = get_obj("objects_total");
Christoph Lameterc09d8752007-05-06 14:49:48 -07001216 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 Congf32143a2007-10-16 23:31:29 -07001221 free(t);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001222 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 Congf32143a2007-10-16 23:31:29 -07001229 free(t);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001230 slab->store_user = get_obj("store_user");
1231 slab->trace = get_obj("trace");
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001232 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 Lameterf715e6f2008-04-29 16:14:46 -07001249 slab->order_fallback = get_obj("order_fallback");
Christoph Lameter9da47142011-06-01 12:26:00 -05001250 slab->cmpxchg_double_cpu_fail = get_obj("cmpxchg_double_cpu_fail");
1251 slab->cmpxchg_double_fail = get_obj("cmpxchg_double_fail");
Christoph Lameteraca726a2011-08-09 16:12:28 -05001252 slab->cpu_partial_alloc = get_obj("cpu_partial_alloc");
1253 slab->cpu_partial_free = get_obj("cpu_partial_free");
Christoph Lameter9da47142011-06-01 12:26:00 -05001254 slab->alloc_node_mismatch = get_obj("alloc_node_mismatch");
1255 slab->deactivate_bypass = get_obj("deactivate_bypass");
Christoph Lameterc09d8752007-05-06 14:49:48 -07001256 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 Lametera87615b2007-05-09 02:32:37 -07001267 actual_slabs = slabs;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001268 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 Chandrasingheb7ed6982009-09-22 16:43:42 -07001275static void output_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001276{
1277 struct slabinfo *slab;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001278 int lines = output_lines;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001279
Sergey Senozhatsky4980a962015-11-05 18:45:20 -08001280 for (slab = slabinfo; (slab < slabinfo + slabs) &&
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001281 lines != 0; slab++) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001282
1283 if (slab->alias)
1284 continue;
1285
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001286 if (lines != -1)
1287 lines--;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001288
1289 if (show_numa)
Christoph Lametera87615b2007-05-09 02:32:37 -07001290 slab_numa(slab, 0);
1291 else if (show_track)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001292 show_tracking(slab);
Christoph Lametera87615b2007-05-09 02:32:37 -07001293 else if (validate)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001294 slab_validate(slab);
Christoph Lametera87615b2007-05-09 02:32:37 -07001295 else if (shrink)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001296 slab_shrink(slab);
Christoph Lametera87615b2007-05-09 02:32:37 -07001297 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 Lametereefaca92007-05-16 22:10:55 -07001303 else if (show_report)
1304 report(slab);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001305 }
1306}
1307
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001308static void xtotals(void)
1309{
1310 totals();
1311
1312 link_slabs();
1313 rename_slabs();
1314
1315 printf("\nSlabs sorted by size\n");
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001316 printf("--------------------\n");
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001317 sort_loss = 0;
1318 sort_size = 1;
1319 sort_slabs();
1320 output_slabs();
1321
1322 printf("\nSlabs sorted by loss\n");
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001323 printf("--------------------\n");
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001324 line = 0;
1325 sort_loss = 1;
1326 sort_size = 0;
1327 sort_slabs();
1328 output_slabs();
1329 printf("\n");
1330}
1331
Christoph Lameterc09d8752007-05-06 14:49:48 -07001332struct option opts[] = {
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001333 { "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 Senozhatsky0d00bf52015-11-05 18:45:25 -08001341 { "slabs", no_argument, NULL, 'l' },
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001342 { "numa", no_argument, NULL, 'n' },
1343 { "ops", no_argument, NULL, 'o' },
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001344 { "shrink", no_argument, NULL, 's' },
Sergey Senozhatsky0d00bf52015-11-05 18:45:25 -08001345 { "report", no_argument, NULL, 'r' },
1346 { "Size", no_argument, NULL, 'S'},
1347 { "tracking", no_argument, NULL, 't'},
1348 { "Totals", no_argument, NULL, 'T'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001349 { "validate", no_argument, NULL, 'v' },
1350 { "zero", no_argument, NULL, 'z' },
1351 { "1ref", no_argument, NULL, '1'},
Sergey Senozhatsky4980a962015-11-05 18:45:20 -08001352 { "lines", required_argument, NULL, 'N'},
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -08001353 { "Loss", no_argument, NULL, 'L'},
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001354 { "Xtotals", no_argument, NULL, 'X'},
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001355 { "Bytes", no_argument, NULL, 'B'},
Yang Shi7ad3f182017-11-15 17:31:59 -08001356 { "Unreclaim", no_argument, NULL, 'U'},
Christoph Lameterc09d8752007-05-06 14:49:48 -07001357 { NULL, 0, NULL, 0 }
1358};
1359
1360int main(int argc, char *argv[])
1361{
1362 int c;
1363 int err;
1364 char *pattern_source;
1365
1366 page_size = getpagesize();
Christoph Lameterc09d8752007-05-06 14:49:48 -07001367
Yang Shi7ad3f182017-11-15 17:31:59 -08001368 while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTSN:LXBU",
Christoph Lametera87615b2007-05-09 02:32:37 -07001369 opts, NULL)) != -1)
WANG Congf32143a2007-10-16 23:31:29 -07001370 switch (c) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001371 case '1':
1372 show_single_ref = 1;
1373 break;
1374 case 'a':
1375 show_alias = 1;
1376 break;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001377 case 'A':
1378 sort_active = 1;
1379 break;
Christoph Lametera87615b2007-05-09 02:32:37 -07001380 case 'd':
1381 set_debug = 1;
1382 if (!debug_opt_scan(optarg))
1383 fatal("Invalid debug option '%s'\n", optarg);
1384 break;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001385 case 'D':
1386 show_activity = 1;
1387 break;
Christoph Lametera87615b2007-05-09 02:32:37 -07001388 case 'e':
1389 show_empty = 1;
1390 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001391 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 Lametera87615b2007-05-09 02:32:37 -07001403 case 'o':
1404 show_ops = 1;
1405 break;
1406 case 'r':
1407 show_report = 1;
1408 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001409 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 Senozhatsky4980a962015-11-05 18:45:20 -08001430 case 'N':
1431 if (optarg) {
1432 output_lines = atoi(optarg);
1433 if (output_lines < 1)
1434 output_lines = 1;
1435 }
1436 break;
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -08001437 case 'L':
1438 sort_loss = 1;
1439 break;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001440 case 'X':
1441 if (output_lines == -1)
1442 output_lines = 1;
1443 extended_totals = 1;
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001444 show_bytes = 1;
1445 break;
1446 case 'B':
1447 show_bytes = 1;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001448 break;
Yang Shi7ad3f182017-11-15 17:31:59 -08001449 case 'U':
1450 unreclaim_only = 1;
1451 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001452 default:
1453 fatal("%s: Invalid option '%c'\n", argv[0], optopt);
1454
1455 }
1456
Christoph Lametera87615b2007-05-09 02:32:37 -07001457 if (!show_slab && !show_alias && !show_track && !show_report
1458 && !validate && !shrink && !set_debug && !show_ops)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001459 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 Senozhatsky016c6cd2015-11-05 18:45:28 -08001471 if (show_alias) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001472 alias();
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001473 } else if (extended_totals) {
1474 xtotals();
1475 } else if (show_totals) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001476 totals();
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001477 } else {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001478 link_slabs();
1479 rename_slabs();
1480 sort_slabs();
1481 output_slabs();
1482 }
1483 return 0;
1484}