blob: 469ff6157986c9e8ea17f2fc5fd48476bbfa75a0 [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;
Tobin C. Harding1106b202019-07-11 20:59:38 -070082int sort_partial;
Sergey Senozhatsky2cee6112015-11-05 18:45:34 -080083int show_activity;
Sergey Senozhatsky4980a962015-11-05 18:45:20 -080084int output_lines = -1;
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -080085int sort_loss;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -080086int extended_totals;
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -080087int show_bytes;
Yang Shi7ad3f182017-11-15 17:31:59 -080088int unreclaim_only;
Christoph Lametera87615b2007-05-09 02:32:37 -070089
90/* Debug options */
Sergey Senozhatsky2cee6112015-11-05 18:45:34 -080091int sanity;
92int redzone;
93int poison;
94int tracking;
95int tracing;
Christoph Lameterc09d8752007-05-06 14:49:48 -070096
97int page_size;
98
99regex_t pattern;
100
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700101static void fatal(const char *x, ...)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700102{
103 va_list ap;
104
105 va_start(ap, x);
106 vfprintf(stderr, x, ap);
107 va_end(ap);
WANG Congf32143a2007-10-16 23:31:29 -0700108 exit(EXIT_FAILURE);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700109}
110
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700111static void usage(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700112{
Christoph Lameter9da47142011-06-01 12:26:00 -0500113 printf("slabinfo 4/15/2011. (c) 2007 sgi/(c) 2011 Linux Foundation.\n\n"
Tobin C. Harding53a83f92019-07-11 20:59:42 -0700114 "slabinfo [-aABDefhilLnoPrsStTUvXz1] [N=K] [-dafzput] [slab-regexp]\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700115 "-a|--aliases Show aliases\n"
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800116 "-A|--activity Most active slabs first\n"
Tobin C. Hardingb80fd302019-03-05 15:49:03 -0800117 "-B|--Bytes Show size in bytes\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"
Tobin C. Harding53a83f92019-07-11 20:59:42 -0700128 "-P|--partial Sort by number of partial slabs\n"
Tobin C. Harding3c89ff92019-03-05 15:49:07 -0800129 "-r|--report Detailed report on single slabs\n"
Tobin C. Hardingb80fd302019-03-05 15:49:03 -0800130 "-s|--shrink Shrink slabs\n"
Christoph Lametera87615b2007-05-09 02:32:37 -0700131 "-S|--Size Sort by size\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700132 "-t|--tracking Show alloc/free information\n"
133 "-T|--Totals Show summary information\n"
Tobin C. Harding3c89ff92019-03-05 15:49:07 -0800134 "-U|--Unreclaim Show unreclaimable slabs only\n"
Christoph Lametera87615b2007-05-09 02:32:37 -0700135 "-v|--validate Validate slabs\n"
Tobin C. Hardingd9149992019-07-11 20:59:34 -0700136 "-X|--Xtotals Show extended summary information\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700137 "-z|--zero Include empty slabs\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700138 "-1|--1ref Single reference\n"
Tobin C. Hardingb80fd302019-03-05 15:49:03 -0800139
Tobin C. Hardingb2f02462019-03-05 15:49:10 -0800140 "\n"
141 "-d | --debug Switch off all debug options\n"
142 "-da | --debug=a Switch on all debug options (--debug=FZPU)\n"
143
144 "\n"
145 "-d[afzput] | --debug=[afzput]\n"
146 " f | F Sanity Checks (SLAB_CONSISTENCY_CHECKS)\n"
147 " z | Z Redzoning\n"
148 " p | P Poisoning\n"
149 " u | U Tracking\n"
150 " t | T Tracing\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700151 );
152}
153
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700154static unsigned long read_obj(const char *name)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700155{
156 FILE *f = fopen(name, "r");
157
158 if (!f)
159 buffer[0] = 0;
160 else {
WANG Congf32143a2007-10-16 23:31:29 -0700161 if (!fgets(buffer, sizeof(buffer), f))
Christoph Lameterc09d8752007-05-06 14:49:48 -0700162 buffer[0] = 0;
163 fclose(f);
164 if (buffer[strlen(buffer)] == '\n')
165 buffer[strlen(buffer)] = 0;
166 }
167 return strlen(buffer);
168}
169
170
171/*
172 * Get the contents of an attribute
173 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700174static unsigned long get_obj(const char *name)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700175{
176 if (!read_obj(name))
177 return 0;
178
179 return atol(buffer);
180}
181
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700182static unsigned long get_obj_and_str(const char *name, char **x)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700183{
184 unsigned long result = 0;
185 char *p;
186
187 *x = NULL;
188
189 if (!read_obj(name)) {
190 x = NULL;
191 return 0;
192 }
193 result = strtoul(buffer, &p, 10);
194 while (*p == ' ')
195 p++;
196 if (*p)
197 *x = strdup(p);
198 return result;
199}
200
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700201static void set_obj(struct slabinfo *s, const char *name, int n)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700202{
203 char x[100];
Christoph Lametera87615b2007-05-09 02:32:37 -0700204 FILE *f;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700205
WANG Congf32143a2007-10-16 23:31:29 -0700206 snprintf(x, 100, "%s/%s", s->name, name);
Christoph Lametera87615b2007-05-09 02:32:37 -0700207 f = fopen(x, "w");
Christoph Lameterc09d8752007-05-06 14:49:48 -0700208 if (!f)
209 fatal("Cannot write to %s\n", x);
210
211 fprintf(f, "%d\n", n);
212 fclose(f);
213}
214
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700215static unsigned long read_slab_obj(struct slabinfo *s, const char *name)
Christoph Lametera87615b2007-05-09 02:32:37 -0700216{
217 char x[100];
218 FILE *f;
WANG Congf32143a2007-10-16 23:31:29 -0700219 size_t l;
Christoph Lametera87615b2007-05-09 02:32:37 -0700220
WANG Congf32143a2007-10-16 23:31:29 -0700221 snprintf(x, 100, "%s/%s", s->name, name);
Christoph Lametera87615b2007-05-09 02:32:37 -0700222 f = fopen(x, "r");
223 if (!f) {
224 buffer[0] = 0;
225 l = 0;
226 } else {
227 l = fread(buffer, 1, sizeof(buffer), f);
228 buffer[l] = 0;
229 fclose(f);
230 }
231 return l;
232}
233
234
Christoph Lameterc09d8752007-05-06 14:49:48 -0700235/*
236 * Put a size string together
237 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700238static int store_size(char *buffer, unsigned long value)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700239{
240 unsigned long divisor = 1;
241 char trailer = 0;
242 int n;
243
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800244 if (!show_bytes) {
245 if (value > 1000000000UL) {
246 divisor = 100000000UL;
247 trailer = 'G';
248 } else if (value > 1000000UL) {
249 divisor = 100000UL;
250 trailer = 'M';
251 } else if (value > 1000UL) {
252 divisor = 100;
253 trailer = 'K';
254 }
Christoph Lameterc09d8752007-05-06 14:49:48 -0700255 }
256
257 value /= divisor;
258 n = sprintf(buffer, "%ld",value);
259 if (trailer) {
260 buffer[n] = trailer;
261 n++;
262 buffer[n] = 0;
263 }
264 if (divisor != 1) {
265 memmove(buffer + n - 2, buffer + n - 3, 4);
266 buffer[n-2] = '.';
267 n++;
268 }
269 return n;
270}
271
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700272static void decode_numa_list(int *numa, char *t)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700273{
274 int node;
275 int nr;
276
277 memset(numa, 0, MAX_NODES * sizeof(int));
278
Christoph Lametereefaca92007-05-16 22:10:55 -0700279 if (!t)
280 return;
281
Christoph Lameterc09d8752007-05-06 14:49:48 -0700282 while (*t == 'N') {
283 t++;
284 node = strtoul(t, &t, 10);
285 if (*t == '=') {
286 t++;
287 nr = strtoul(t, &t, 10);
288 numa[node] = nr;
289 if (node > highest_node)
290 highest_node = node;
291 }
292 while (*t == ' ')
293 t++;
294 }
295}
296
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700297static void slab_validate(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700298{
Christoph Lameter32f93062007-05-18 00:36:43 -0700299 if (strcmp(s->name, "*") == 0)
300 return;
301
Christoph Lameterc09d8752007-05-06 14:49:48 -0700302 set_obj(s, "validate", 1);
303}
304
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700305static void slab_shrink(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700306{
Christoph Lameter32f93062007-05-18 00:36:43 -0700307 if (strcmp(s->name, "*") == 0)
308 return;
309
Christoph Lameterc09d8752007-05-06 14:49:48 -0700310 set_obj(s, "shrink", 1);
311}
312
313int line = 0;
314
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700315static void first_line(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700316{
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800317 if (show_activity)
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800318 printf("Name Objects Alloc Free"
319 " %%Fast Fallb O CmpX UL\n");
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800320 else
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800321 printf("Name Objects Objsize %s "
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -0800322 "Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n",
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800323 sort_loss ? " Loss" : "Space");
Christoph Lameterc09d8752007-05-06 14:49:48 -0700324}
325
326/*
327 * Find the shortest alias of a slab
328 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700329static struct aliasinfo *find_one_alias(struct slabinfo *find)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700330{
331 struct aliasinfo *a;
332 struct aliasinfo *best = NULL;
333
334 for(a = aliasinfo;a < aliasinfo + aliases; a++) {
335 if (a->slab == find &&
336 (!best || strlen(best->name) < strlen(a->name))) {
337 best = a;
338 if (strncmp(a->name,"kmall", 5) == 0)
339 return best;
340 }
341 }
Christoph Lametera87615b2007-05-09 02:32:37 -0700342 return best;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700343}
344
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700345static unsigned long slab_size(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700346{
347 return s->slabs * (page_size << s->order);
348}
349
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700350static unsigned long slab_activity(struct slabinfo *s)
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800351{
352 return s->alloc_fastpath + s->free_fastpath +
353 s->alloc_slowpath + s->free_slowpath;
354}
355
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -0800356static unsigned long slab_waste(struct slabinfo *s)
357{
358 return slab_size(s) - s->objects * s->object_size;
359}
360
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700361static void slab_numa(struct slabinfo *s, int mode)
Christoph Lametera87615b2007-05-09 02:32:37 -0700362{
363 int node;
364
365 if (strcmp(s->name, "*") == 0)
366 return;
367
368 if (!highest_node) {
369 printf("\n%s: No NUMA information available.\n", s->name);
370 return;
371 }
372
373 if (skip_zero && !s->slabs)
374 return;
375
376 if (!line) {
377 printf("\n%-21s:", mode ? "NUMA nodes" : "Slab");
378 for(node = 0; node <= highest_node; node++)
379 printf(" %4d", node);
380 printf("\n----------------------");
381 for(node = 0; node <= highest_node; node++)
382 printf("-----");
383 printf("\n");
384 }
385 printf("%-21s ", mode ? "All slabs" : s->name);
386 for(node = 0; node <= highest_node; node++) {
387 char b[20];
388
389 store_size(b, s->numa[node]);
390 printf(" %4s", b);
391 }
392 printf("\n");
393 if (mode) {
394 printf("%-21s ", "Partial slabs");
395 for(node = 0; node <= highest_node; node++) {
396 char b[20];
397
398 store_size(b, s->numa_partial[node]);
399 printf(" %4s", b);
400 }
401 printf("\n");
402 }
403 line++;
404}
405
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700406static void show_tracking(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700407{
408 printf("\n%s: Kernel object allocation\n", s->name);
409 printf("-----------------------------------------------------------------------\n");
410 if (read_slab_obj(s, "alloc_calls"))
Christoph Lameter9da47142011-06-01 12:26:00 -0500411 printf("%s", buffer);
Christoph Lametera87615b2007-05-09 02:32:37 -0700412 else
413 printf("No Data\n");
414
415 printf("\n%s: Kernel object freeing\n", s->name);
416 printf("------------------------------------------------------------------------\n");
417 if (read_slab_obj(s, "free_calls"))
Christoph Lameter9da47142011-06-01 12:26:00 -0500418 printf("%s", buffer);
Christoph Lametera87615b2007-05-09 02:32:37 -0700419 else
420 printf("No Data\n");
421
422}
423
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700424static void ops(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700425{
426 if (strcmp(s->name, "*") == 0)
427 return;
428
429 if (read_slab_obj(s, "ops")) {
430 printf("\n%s: kmem_cache operations\n", s->name);
431 printf("--------------------------------------------\n");
Christoph Lameter9da47142011-06-01 12:26:00 -0500432 printf("%s", buffer);
Christoph Lametera87615b2007-05-09 02:32:37 -0700433 } else
434 printf("\n%s has no kmem_cache operations\n", s->name);
435}
436
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700437static const char *onoff(int x)
Christoph Lametera87615b2007-05-09 02:32:37 -0700438{
439 if (x)
440 return "On ";
441 return "Off";
442}
443
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700444static void slab_stats(struct slabinfo *s)
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800445{
446 unsigned long total_alloc;
447 unsigned long total_free;
448 unsigned long total;
449
450 if (!s->alloc_slab)
451 return;
452
453 total_alloc = s->alloc_fastpath + s->alloc_slowpath;
454 total_free = s->free_fastpath + s->free_slowpath;
455
456 if (!total_alloc)
457 return;
458
459 printf("\n");
460 printf("Slab Perf Counter Alloc Free %%Al %%Fr\n");
461 printf("--------------------------------------------------\n");
462 printf("Fastpath %8lu %8lu %3lu %3lu\n",
463 s->alloc_fastpath, s->free_fastpath,
464 s->alloc_fastpath * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800465 total_free ? s->free_fastpath * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800466 printf("Slowpath %8lu %8lu %3lu %3lu\n",
467 total_alloc - s->alloc_fastpath, s->free_slowpath,
468 (total_alloc - s->alloc_fastpath) * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800469 total_free ? s->free_slowpath * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800470 printf("Page Alloc %8lu %8lu %3lu %3lu\n",
471 s->alloc_slab, s->free_slab,
472 s->alloc_slab * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800473 total_free ? s->free_slab * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800474 printf("Add partial %8lu %8lu %3lu %3lu\n",
475 s->deactivate_to_head + s->deactivate_to_tail,
476 s->free_add_partial,
477 (s->deactivate_to_head + s->deactivate_to_tail) * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800478 total_free ? s->free_add_partial * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800479 printf("Remove partial %8lu %8lu %3lu %3lu\n",
480 s->alloc_from_partial, s->free_remove_partial,
481 s->alloc_from_partial * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800482 total_free ? s->free_remove_partial * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800483
Christoph Lameteraca726a2011-08-09 16:12:28 -0500484 printf("Cpu partial list %8lu %8lu %3lu %3lu\n",
485 s->cpu_partial_alloc, s->cpu_partial_free,
486 s->cpu_partial_alloc * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800487 total_free ? s->cpu_partial_free * 100 / total_free : 0);
Christoph Lameteraca726a2011-08-09 16:12:28 -0500488
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800489 printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n",
490 s->deactivate_remote_frees, s->free_frozen,
491 s->deactivate_remote_frees * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800492 total_free ? s->free_frozen * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800493
494 printf("Total %8lu %8lu\n\n", total_alloc, total_free);
495
496 if (s->cpuslab_flush)
497 printf("Flushes %8lu\n", s->cpuslab_flush);
498
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800499 total = s->deactivate_full + s->deactivate_empty +
Christoph Lameter9da47142011-06-01 12:26:00 -0500500 s->deactivate_to_head + s->deactivate_to_tail + s->deactivate_bypass;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800501
Christoph Lameter9da47142011-06-01 12:26:00 -0500502 if (total) {
Colin Ian King7c5b7232016-06-24 14:50:21 -0700503 printf("\nSlab Deactivation Occurrences %%\n");
Christoph Lameter9da47142011-06-01 12:26:00 -0500504 printf("-------------------------------------------------\n");
505 printf("Slab full %7lu %3lu%%\n",
506 s->deactivate_full, (s->deactivate_full * 100) / total);
507 printf("Slab empty %7lu %3lu%%\n",
508 s->deactivate_empty, (s->deactivate_empty * 100) / total);
509 printf("Moved to head of partial list %7lu %3lu%%\n",
510 s->deactivate_to_head, (s->deactivate_to_head * 100) / total);
511 printf("Moved to tail of partial list %7lu %3lu%%\n",
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800512 s->deactivate_to_tail, (s->deactivate_to_tail * 100) / total);
Christoph Lameter9da47142011-06-01 12:26:00 -0500513 printf("Deactivation bypass %7lu %3lu%%\n",
514 s->deactivate_bypass, (s->deactivate_bypass * 100) / total);
515 printf("Refilled from foreign frees %7lu %3lu%%\n",
516 s->alloc_refill, (s->alloc_refill * 100) / total);
517 printf("Node mismatch %7lu %3lu%%\n",
518 s->alloc_node_mismatch, (s->alloc_node_mismatch * 100) / total);
519 }
520
Dan Carpenter2d6a4d62016-07-20 15:45:05 -0700521 if (s->cmpxchg_double_fail || s->cmpxchg_double_cpu_fail) {
Christoph Lameter9da47142011-06-01 12:26:00 -0500522 printf("\nCmpxchg_double Looping\n------------------------\n");
523 printf("Locked Cmpxchg Double redos %lu\nUnlocked Cmpxchg Double redos %lu\n",
524 s->cmpxchg_double_fail, s->cmpxchg_double_cpu_fail);
Dan Carpenter2d6a4d62016-07-20 15:45:05 -0700525 }
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800526}
527
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700528static void report(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700529{
530 if (strcmp(s->name, "*") == 0)
531 return;
Christoph Lametereefaca92007-05-16 22:10:55 -0700532
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800533 printf("\nSlabcache: %-15s Aliases: %2d Order : %2d Objects: %lu\n",
Christoph Lametereefaca92007-05-16 22:10:55 -0700534 s->name, s->aliases, s->order, s->objects);
Christoph Lametera87615b2007-05-09 02:32:37 -0700535 if (s->hwcache_align)
536 printf("** Hardware cacheline aligned\n");
537 if (s->cache_dma)
538 printf("** Memory is allocated in a special DMA zone\n");
539 if (s->destroy_by_rcu)
540 printf("** Slabs are destroyed via RCU\n");
541 if (s->reclaim_account)
542 printf("** Reclaim accounting active\n");
543
544 printf("\nSizes (bytes) Slabs Debug Memory\n");
545 printf("------------------------------------------------------------------------\n");
546 printf("Object : %7d Total : %7ld Sanity Checks : %s Total: %7ld\n",
547 s->object_size, s->slabs, onoff(s->sanity_checks),
548 s->slabs * (page_size << s->order));
549 printf("SlabObj: %7d Full : %7ld Redzoning : %s Used : %7ld\n",
550 s->slab_size, s->slabs - s->partial - s->cpu_slabs,
551 onoff(s->red_zone), s->objects * s->object_size);
552 printf("SlabSiz: %7d Partial: %7ld Poisoning : %s Loss : %7ld\n",
553 page_size << s->order, s->partial, onoff(s->poison),
554 s->slabs * (page_size << s->order) - s->objects * s->object_size);
555 printf("Loss : %7d CpuSlab: %7d Tracking : %s Lalig: %7ld\n",
556 s->slab_size - s->object_size, s->cpu_slabs, onoff(s->store_user),
557 (s->slab_size - s->object_size) * s->objects);
558 printf("Align : %7d Objects: %7d Tracing : %s Lpadd: %7ld\n",
559 s->align, s->objs_per_slab, onoff(s->trace),
560 ((page_size << s->order) - s->objs_per_slab * s->slab_size) *
561 s->slabs);
562
563 ops(s);
564 show_tracking(s);
565 slab_numa(s, 1);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800566 slab_stats(s);
Christoph Lametera87615b2007-05-09 02:32:37 -0700567}
Christoph Lameterc09d8752007-05-06 14:49:48 -0700568
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700569static void slabcache(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700570{
571 char size_str[20];
572 char dist_str[40];
573 char flags[20];
574 char *p = flags;
575
Christoph Lametera87615b2007-05-09 02:32:37 -0700576 if (strcmp(s->name, "*") == 0)
577 return;
578
Yang Shi7ad3f182017-11-15 17:31:59 -0800579 if (unreclaim_only && s->reclaim_account)
580 return;
581
Christoph Lametera87615b2007-05-09 02:32:37 -0700582 if (actual_slabs == 1) {
583 report(s);
584 return;
585 }
586
587 if (skip_zero && !show_empty && !s->slabs)
588 return;
589
590 if (show_empty && s->slabs)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700591 return;
592
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -0800593 if (sort_loss == 0)
594 store_size(size_str, slab_size(s));
595 else
596 store_size(size_str, slab_waste(s));
Christoph Lameter205ab992008-04-14 19:11:40 +0300597 snprintf(dist_str, 40, "%lu/%lu/%d", s->slabs - s->cpu_slabs,
598 s->partial, s->cpu_slabs);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700599
600 if (!line++)
601 first_line();
602
603 if (s->aliases)
604 *p++ = '*';
605 if (s->cache_dma)
606 *p++ = 'd';
607 if (s->hwcache_align)
608 *p++ = 'A';
609 if (s->poison)
610 *p++ = 'P';
611 if (s->reclaim_account)
612 *p++ = 'a';
613 if (s->red_zone)
614 *p++ = 'Z';
615 if (s->sanity_checks)
616 *p++ = 'F';
617 if (s->store_user)
618 *p++ = 'U';
619 if (s->trace)
620 *p++ = 'T';
621
622 *p = 0;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800623 if (show_activity) {
624 unsigned long total_alloc;
625 unsigned long total_free;
626
627 total_alloc = s->alloc_fastpath + s->alloc_slowpath;
628 total_free = s->free_fastpath + s->free_slowpath;
629
Christoph Lameter9da47142011-06-01 12:26:00 -0500630 printf("%-21s %8ld %10ld %10ld %3ld %3ld %5ld %1d %4ld %4ld\n",
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800631 s->name, s->objects,
632 total_alloc, total_free,
633 total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0,
Christoph Lameterf715e6f2008-04-29 16:14:46 -0700634 total_free ? (s->free_fastpath * 100 / total_free) : 0,
Christoph Lameter9da47142011-06-01 12:26:00 -0500635 s->order_fallback, s->order, s->cmpxchg_double_fail,
636 s->cmpxchg_double_cpu_fail);
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -0800637 } else {
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800638 printf("%-21s %8ld %7d %15s %14s %4d %1d %3ld %3ld %s\n",
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800639 s->name, s->objects, s->object_size, size_str, dist_str,
640 s->objs_per_slab, s->order,
641 s->slabs ? (s->partial * 100) / s->slabs : 100,
642 s->slabs ? (s->objects * s->object_size * 100) /
643 (s->slabs * (page_size << s->order)) : 100,
644 flags);
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -0800645 }
Christoph Lameterc09d8752007-05-06 14:49:48 -0700646}
647
Christoph Lametera87615b2007-05-09 02:32:37 -0700648/*
649 * Analyze debug options. Return false if something is amiss.
650 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700651static int debug_opt_scan(char *opt)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700652{
Christoph Lametera87615b2007-05-09 02:32:37 -0700653 if (!opt || !opt[0] || strcmp(opt, "-") == 0)
654 return 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700655
Christoph Lametera87615b2007-05-09 02:32:37 -0700656 if (strcasecmp(opt, "a") == 0) {
657 sanity = 1;
658 poison = 1;
659 redzone = 1;
660 tracking = 1;
661 return 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700662 }
Christoph Lameterc09d8752007-05-06 14:49:48 -0700663
Christoph Lametera87615b2007-05-09 02:32:37 -0700664 for ( ; *opt; opt++)
Christoph Lameter0d24db32010-10-21 13:01:56 -0500665 switch (*opt) {
Christoph Lametera87615b2007-05-09 02:32:37 -0700666 case 'F' : case 'f':
667 if (sanity)
668 return 0;
669 sanity = 1;
670 break;
671 case 'P' : case 'p':
672 if (poison)
673 return 0;
674 poison = 1;
675 break;
676
677 case 'Z' : case 'z':
678 if (redzone)
679 return 0;
680 redzone = 1;
681 break;
682
683 case 'U' : case 'u':
684 if (tracking)
685 return 0;
686 tracking = 1;
687 break;
688
689 case 'T' : case 't':
690 if (tracing)
691 return 0;
692 tracing = 1;
693 break;
694 default:
695 return 0;
696 }
697 return 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700698}
699
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700700static int slab_empty(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700701{
Christoph Lametera87615b2007-05-09 02:32:37 -0700702 if (s->objects > 0)
703 return 0;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700704
Christoph Lametera87615b2007-05-09 02:32:37 -0700705 /*
706 * We may still have slabs even if there are no objects. Shrinking will
707 * remove them.
708 */
709 if (s->slabs != 0)
710 set_obj(s, "shrink", 1);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700711
Christoph Lametera87615b2007-05-09 02:32:37 -0700712 return 1;
713}
714
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700715static void slab_debug(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700716{
Christoph Lameter32f93062007-05-18 00:36:43 -0700717 if (strcmp(s->name, "*") == 0)
718 return;
719
Christoph Lametera87615b2007-05-09 02:32:37 -0700720 if (sanity && !s->sanity_checks) {
721 set_obj(s, "sanity", 1);
722 }
723 if (!sanity && s->sanity_checks) {
724 if (slab_empty(s))
725 set_obj(s, "sanity", 0);
726 else
727 fprintf(stderr, "%s not empty cannot disable sanity checks\n", s->name);
728 }
729 if (redzone && !s->red_zone) {
730 if (slab_empty(s))
731 set_obj(s, "red_zone", 1);
732 else
733 fprintf(stderr, "%s not empty cannot enable redzoning\n", s->name);
734 }
735 if (!redzone && s->red_zone) {
736 if (slab_empty(s))
737 set_obj(s, "red_zone", 0);
738 else
739 fprintf(stderr, "%s not empty cannot disable redzoning\n", s->name);
740 }
741 if (poison && !s->poison) {
742 if (slab_empty(s))
743 set_obj(s, "poison", 1);
744 else
745 fprintf(stderr, "%s not empty cannot enable poisoning\n", s->name);
746 }
747 if (!poison && s->poison) {
748 if (slab_empty(s))
749 set_obj(s, "poison", 0);
750 else
751 fprintf(stderr, "%s not empty cannot disable poisoning\n", s->name);
752 }
753 if (tracking && !s->store_user) {
754 if (slab_empty(s))
755 set_obj(s, "store_user", 1);
756 else
757 fprintf(stderr, "%s not empty cannot enable tracking\n", s->name);
758 }
759 if (!tracking && s->store_user) {
760 if (slab_empty(s))
761 set_obj(s, "store_user", 0);
762 else
763 fprintf(stderr, "%s not empty cannot disable tracking\n", s->name);
764 }
765 if (tracing && !s->trace) {
766 if (slabs == 1)
767 set_obj(s, "trace", 1);
768 else
769 fprintf(stderr, "%s can only enable trace for one slab at a time\n", s->name);
770 }
771 if (!tracing && s->trace)
772 set_obj(s, "trace", 1);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700773}
774
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700775static void totals(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700776{
777 struct slabinfo *s;
778
779 int used_slabs = 0;
780 char b1[20], b2[20], b3[20], b4[20];
781 unsigned long long max = 1ULL << 63;
782
783 /* Object size */
784 unsigned long long min_objsize = max, max_objsize = 0, avg_objsize;
785
786 /* Number of partial slabs in a slabcache */
787 unsigned long long min_partial = max, max_partial = 0,
788 avg_partial, total_partial = 0;
789
790 /* Number of slabs in a slab cache */
791 unsigned long long min_slabs = max, max_slabs = 0,
792 avg_slabs, total_slabs = 0;
793
794 /* Size of the whole slab */
795 unsigned long long min_size = max, max_size = 0,
796 avg_size, total_size = 0;
797
798 /* Bytes used for object storage in a slab */
799 unsigned long long min_used = max, max_used = 0,
800 avg_used, total_used = 0;
801
802 /* Waste: Bytes used for alignment and padding */
803 unsigned long long min_waste = max, max_waste = 0,
804 avg_waste, total_waste = 0;
805 /* Number of objects in a slab */
806 unsigned long long min_objects = max, max_objects = 0,
807 avg_objects, total_objects = 0;
808 /* Waste per object */
809 unsigned long long min_objwaste = max,
810 max_objwaste = 0, avg_objwaste,
811 total_objwaste = 0;
812
813 /* Memory per object */
814 unsigned long long min_memobj = max,
815 max_memobj = 0, avg_memobj,
816 total_objsize = 0;
817
818 /* Percentage of partial slabs per slab */
819 unsigned long min_ppart = 100, max_ppart = 0,
820 avg_ppart, total_ppart = 0;
821
822 /* Number of objects in partial slabs */
823 unsigned long min_partobj = max, max_partobj = 0,
824 avg_partobj, total_partobj = 0;
825
826 /* Percentage of partial objects of all objects in a slab */
827 unsigned long min_ppartobj = 100, max_ppartobj = 0,
828 avg_ppartobj, total_ppartobj = 0;
829
830
831 for (s = slabinfo; s < slabinfo + slabs; s++) {
832 unsigned long long size;
833 unsigned long used;
834 unsigned long long wasted;
835 unsigned long long objwaste;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700836 unsigned long percentage_partial_slabs;
837 unsigned long percentage_partial_objs;
838
839 if (!s->slabs || !s->objects)
840 continue;
841
842 used_slabs++;
843
844 size = slab_size(s);
845 used = s->objects * s->object_size;
846 wasted = size - used;
847 objwaste = s->slab_size - s->object_size;
848
Christoph Lameterc09d8752007-05-06 14:49:48 -0700849 percentage_partial_slabs = s->partial * 100 / s->slabs;
850 if (percentage_partial_slabs > 100)
851 percentage_partial_slabs = 100;
852
Christoph Lameter205ab992008-04-14 19:11:40 +0300853 percentage_partial_objs = s->objects_partial * 100
Christoph Lameterc09d8752007-05-06 14:49:48 -0700854 / s->objects;
855
856 if (percentage_partial_objs > 100)
857 percentage_partial_objs = 100;
858
859 if (s->object_size < min_objsize)
860 min_objsize = s->object_size;
861 if (s->partial < min_partial)
862 min_partial = s->partial;
863 if (s->slabs < min_slabs)
864 min_slabs = s->slabs;
865 if (size < min_size)
866 min_size = size;
867 if (wasted < min_waste)
868 min_waste = wasted;
869 if (objwaste < min_objwaste)
870 min_objwaste = objwaste;
871 if (s->objects < min_objects)
872 min_objects = s->objects;
873 if (used < min_used)
874 min_used = used;
Christoph Lameter205ab992008-04-14 19:11:40 +0300875 if (s->objects_partial < min_partobj)
876 min_partobj = s->objects_partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700877 if (percentage_partial_slabs < min_ppart)
878 min_ppart = percentage_partial_slabs;
879 if (percentage_partial_objs < min_ppartobj)
880 min_ppartobj = percentage_partial_objs;
881 if (s->slab_size < min_memobj)
882 min_memobj = s->slab_size;
883
884 if (s->object_size > max_objsize)
885 max_objsize = s->object_size;
886 if (s->partial > max_partial)
887 max_partial = s->partial;
888 if (s->slabs > max_slabs)
889 max_slabs = s->slabs;
890 if (size > max_size)
891 max_size = size;
892 if (wasted > max_waste)
893 max_waste = wasted;
894 if (objwaste > max_objwaste)
895 max_objwaste = objwaste;
896 if (s->objects > max_objects)
897 max_objects = s->objects;
898 if (used > max_used)
899 max_used = used;
Christoph Lameter205ab992008-04-14 19:11:40 +0300900 if (s->objects_partial > max_partobj)
901 max_partobj = s->objects_partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700902 if (percentage_partial_slabs > max_ppart)
903 max_ppart = percentage_partial_slabs;
904 if (percentage_partial_objs > max_ppartobj)
905 max_ppartobj = percentage_partial_objs;
906 if (s->slab_size > max_memobj)
907 max_memobj = s->slab_size;
908
909 total_partial += s->partial;
910 total_slabs += s->slabs;
911 total_size += size;
912 total_waste += wasted;
913
914 total_objects += s->objects;
915 total_used += used;
Christoph Lameter205ab992008-04-14 19:11:40 +0300916 total_partobj += s->objects_partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700917 total_ppart += percentage_partial_slabs;
918 total_ppartobj += percentage_partial_objs;
919
920 total_objwaste += s->objects * objwaste;
921 total_objsize += s->objects * s->slab_size;
922 }
923
924 if (!total_objects) {
925 printf("No objects\n");
926 return;
927 }
928 if (!used_slabs) {
929 printf("No slabs\n");
930 return;
931 }
932
933 /* Per slab averages */
934 avg_partial = total_partial / used_slabs;
935 avg_slabs = total_slabs / used_slabs;
936 avg_size = total_size / used_slabs;
937 avg_waste = total_waste / used_slabs;
938
939 avg_objects = total_objects / used_slabs;
940 avg_used = total_used / used_slabs;
941 avg_partobj = total_partobj / used_slabs;
942 avg_ppart = total_ppart / used_slabs;
943 avg_ppartobj = total_ppartobj / used_slabs;
944
945 /* Per object object sizes */
946 avg_objsize = total_used / total_objects;
947 avg_objwaste = total_objwaste / total_objects;
948 avg_partobj = total_partobj * 100 / total_objects;
949 avg_memobj = total_objsize / total_objects;
950
951 printf("Slabcache Totals\n");
952 printf("----------------\n");
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800953 printf("Slabcaches : %15d Aliases : %11d->%-3d Active: %3d\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700954 slabs, aliases, alias_targets, used_slabs);
955
956 store_size(b1, total_size);store_size(b2, total_waste);
957 store_size(b3, total_waste * 100 / total_used);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800958 printf("Memory used: %15s # Loss : %15s MRatio:%6s%%\n", b1, b2, b3);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700959
960 store_size(b1, total_objects);store_size(b2, total_partobj);
961 store_size(b3, total_partobj * 100 / total_objects);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800962 printf("# Objects : %15s # PartObj: %15s ORatio:%6s%%\n", b1, b2, b3);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700963
964 printf("\n");
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800965 printf("Per Cache Average "
966 "Min Max Total\n");
967 printf("---------------------------------------"
968 "-------------------------------------\n");
Christoph Lameterc09d8752007-05-06 14:49:48 -0700969
970 store_size(b1, avg_objects);store_size(b2, min_objects);
971 store_size(b3, max_objects);store_size(b4, total_objects);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800972 printf("#Objects %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700973 b1, b2, b3, b4);
974
975 store_size(b1, avg_slabs);store_size(b2, min_slabs);
976 store_size(b3, max_slabs);store_size(b4, total_slabs);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800977 printf("#Slabs %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700978 b1, b2, b3, b4);
979
980 store_size(b1, avg_partial);store_size(b2, min_partial);
981 store_size(b3, max_partial);store_size(b4, total_partial);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800982 printf("#PartSlab %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700983 b1, b2, b3, b4);
984 store_size(b1, avg_ppart);store_size(b2, min_ppart);
985 store_size(b3, max_ppart);
986 store_size(b4, total_partial * 100 / total_slabs);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800987 printf("%%PartSlab%15s%% %15s%% %15s%% %15s%%\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700988 b1, b2, b3, b4);
989
990 store_size(b1, avg_partobj);store_size(b2, min_partobj);
991 store_size(b3, max_partobj);
992 store_size(b4, total_partobj);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800993 printf("PartObjs %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700994 b1, b2, b3, b4);
995
996 store_size(b1, avg_ppartobj);store_size(b2, min_ppartobj);
997 store_size(b3, max_ppartobj);
998 store_size(b4, total_partobj * 100 / total_objects);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800999 printf("%% PartObj%15s%% %15s%% %15s%% %15s%%\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001000 b1, b2, b3, b4);
1001
1002 store_size(b1, avg_size);store_size(b2, min_size);
1003 store_size(b3, max_size);store_size(b4, total_size);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001004 printf("Memory %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001005 b1, b2, b3, b4);
1006
1007 store_size(b1, avg_used);store_size(b2, min_used);
1008 store_size(b3, max_used);store_size(b4, total_used);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001009 printf("Used %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001010 b1, b2, b3, b4);
1011
1012 store_size(b1, avg_waste);store_size(b2, min_waste);
1013 store_size(b3, max_waste);store_size(b4, total_waste);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001014 printf("Loss %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001015 b1, b2, b3, b4);
1016
1017 printf("\n");
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001018 printf("Per Object Average "
1019 "Min Max\n");
1020 printf("---------------------------------------"
1021 "--------------------\n");
Christoph Lameterc09d8752007-05-06 14:49:48 -07001022
1023 store_size(b1, avg_memobj);store_size(b2, min_memobj);
1024 store_size(b3, max_memobj);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001025 printf("Memory %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001026 b1, b2, b3);
1027 store_size(b1, avg_objsize);store_size(b2, min_objsize);
1028 store_size(b3, max_objsize);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001029 printf("User %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001030 b1, b2, b3);
1031
1032 store_size(b1, avg_objwaste);store_size(b2, min_objwaste);
1033 store_size(b3, max_objwaste);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001034 printf("Loss %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001035 b1, b2, b3);
1036}
1037
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001038static void sort_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001039{
1040 struct slabinfo *s1,*s2;
1041
1042 for (s1 = slabinfo; s1 < slabinfo + slabs; s1++) {
1043 for (s2 = s1 + 1; s2 < slabinfo + slabs; s2++) {
1044 int result;
1045
1046 if (sort_size)
1047 result = slab_size(s1) < slab_size(s2);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001048 else if (sort_active)
1049 result = slab_activity(s1) < slab_activity(s2);
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -08001050 else if (sort_loss)
1051 result = slab_waste(s1) < slab_waste(s2);
Tobin C. Harding1106b202019-07-11 20:59:38 -07001052 else if (sort_partial)
1053 result = s1->partial < s2->partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001054 else
1055 result = strcasecmp(s1->name, s2->name);
1056
1057 if (show_inverted)
1058 result = -result;
1059
1060 if (result > 0) {
1061 struct slabinfo t;
1062
1063 memcpy(&t, s1, sizeof(struct slabinfo));
1064 memcpy(s1, s2, sizeof(struct slabinfo));
1065 memcpy(s2, &t, sizeof(struct slabinfo));
1066 }
1067 }
1068 }
1069}
1070
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001071static void sort_aliases(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001072{
1073 struct aliasinfo *a1,*a2;
1074
1075 for (a1 = aliasinfo; a1 < aliasinfo + aliases; a1++) {
1076 for (a2 = a1 + 1; a2 < aliasinfo + aliases; a2++) {
1077 char *n1, *n2;
1078
1079 n1 = a1->name;
1080 n2 = a2->name;
1081 if (show_alias && !show_inverted) {
1082 n1 = a1->ref;
1083 n2 = a2->ref;
1084 }
1085 if (strcasecmp(n1, n2) > 0) {
1086 struct aliasinfo t;
1087
1088 memcpy(&t, a1, sizeof(struct aliasinfo));
1089 memcpy(a1, a2, sizeof(struct aliasinfo));
1090 memcpy(a2, &t, sizeof(struct aliasinfo));
1091 }
1092 }
1093 }
1094}
1095
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001096static void link_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001097{
1098 struct aliasinfo *a;
1099 struct slabinfo *s;
1100
1101 for (a = aliasinfo; a < aliasinfo + aliases; a++) {
1102
Christoph Lametera87615b2007-05-09 02:32:37 -07001103 for (s = slabinfo; s < slabinfo + slabs; s++)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001104 if (strcmp(a->ref, s->name) == 0) {
1105 a->slab = s;
1106 s->refs++;
1107 break;
1108 }
1109 if (s == slabinfo + slabs)
1110 fatal("Unresolved alias %s\n", a->ref);
1111 }
1112}
1113
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001114static void alias(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001115{
1116 struct aliasinfo *a;
1117 char *active = NULL;
1118
1119 sort_aliases();
1120 link_slabs();
1121
1122 for(a = aliasinfo; a < aliasinfo + aliases; a++) {
1123
1124 if (!show_single_ref && a->slab->refs == 1)
1125 continue;
1126
1127 if (!show_inverted) {
1128 if (active) {
1129 if (strcmp(a->slab->name, active) == 0) {
1130 printf(" %s", a->name);
1131 continue;
1132 }
1133 }
Christoph Lametera87615b2007-05-09 02:32:37 -07001134 printf("\n%-12s <- %s", a->slab->name, a->name);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001135 active = a->slab->name;
1136 }
1137 else
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001138 printf("%-15s -> %s\n", a->name, a->slab->name);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001139 }
1140 if (active)
1141 printf("\n");
1142}
1143
1144
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001145static void rename_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001146{
1147 struct slabinfo *s;
1148 struct aliasinfo *a;
1149
1150 for (s = slabinfo; s < slabinfo + slabs; s++) {
1151 if (*s->name != ':')
1152 continue;
1153
1154 if (s->refs > 1 && !show_first_alias)
1155 continue;
1156
1157 a = find_one_alias(s);
1158
Christoph Lametera87615b2007-05-09 02:32:37 -07001159 if (a)
1160 s->name = a->name;
1161 else {
1162 s->name = "*";
1163 actual_slabs--;
1164 }
Christoph Lameterc09d8752007-05-06 14:49:48 -07001165 }
1166}
1167
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001168static int slab_mismatch(char *slab)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001169{
1170 return regexec(&pattern, slab, 0, NULL, 0);
1171}
1172
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001173static void read_slab_dir(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001174{
1175 DIR *dir;
1176 struct dirent *de;
1177 struct slabinfo *slab = slabinfo;
1178 struct aliasinfo *alias = aliasinfo;
1179 char *p;
1180 char *t;
1181 int count;
1182
Christoph Lameterb6c24de2008-02-04 23:35:48 -08001183 if (chdir("/sys/kernel/slab") && chdir("/sys/slab"))
Christoph Lametera87615b2007-05-09 02:32:37 -07001184 fatal("SYSFS support for SLUB not active\n");
1185
Christoph Lameterc09d8752007-05-06 14:49:48 -07001186 dir = opendir(".");
1187 while ((de = readdir(dir))) {
1188 if (de->d_name[0] == '.' ||
Christoph Lametera87615b2007-05-09 02:32:37 -07001189 (de->d_name[0] != ':' && slab_mismatch(de->d_name)))
1190 continue;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001191 switch (de->d_type) {
1192 case DT_LNK:
Christoph Lameter0d24db32010-10-21 13:01:56 -05001193 alias->name = strdup(de->d_name);
Thomas Jaroschfe353172011-10-17 16:48:10 +02001194 count = readlink(de->d_name, buffer, sizeof(buffer)-1);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001195
1196 if (count < 0)
1197 fatal("Cannot read symlink %s\n", de->d_name);
1198
1199 buffer[count] = 0;
1200 p = buffer + count;
1201 while (p > buffer && p[-1] != '/')
1202 p--;
1203 alias->ref = strdup(p);
1204 alias++;
1205 break;
1206 case DT_DIR:
1207 if (chdir(de->d_name))
1208 fatal("Unable to access slab %s\n", slab->name);
Christoph Lameter0d24db32010-10-21 13:01:56 -05001209 slab->name = strdup(de->d_name);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001210 slab->alias = 0;
1211 slab->refs = 0;
1212 slab->aliases = get_obj("aliases");
1213 slab->align = get_obj("align");
1214 slab->cache_dma = get_obj("cache_dma");
1215 slab->cpu_slabs = get_obj("cpu_slabs");
1216 slab->destroy_by_rcu = get_obj("destroy_by_rcu");
1217 slab->hwcache_align = get_obj("hwcache_align");
1218 slab->object_size = get_obj("object_size");
1219 slab->objects = get_obj("objects");
Christoph Lameter205ab992008-04-14 19:11:40 +03001220 slab->objects_partial = get_obj("objects_partial");
1221 slab->objects_total = get_obj("objects_total");
Christoph Lameterc09d8752007-05-06 14:49:48 -07001222 slab->objs_per_slab = get_obj("objs_per_slab");
1223 slab->order = get_obj("order");
1224 slab->partial = get_obj("partial");
1225 slab->partial = get_obj_and_str("partial", &t);
1226 decode_numa_list(slab->numa_partial, t);
WANG Congf32143a2007-10-16 23:31:29 -07001227 free(t);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001228 slab->poison = get_obj("poison");
1229 slab->reclaim_account = get_obj("reclaim_account");
1230 slab->red_zone = get_obj("red_zone");
1231 slab->sanity_checks = get_obj("sanity_checks");
1232 slab->slab_size = get_obj("slab_size");
1233 slab->slabs = get_obj_and_str("slabs", &t);
1234 decode_numa_list(slab->numa, t);
WANG Congf32143a2007-10-16 23:31:29 -07001235 free(t);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001236 slab->store_user = get_obj("store_user");
1237 slab->trace = get_obj("trace");
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001238 slab->alloc_fastpath = get_obj("alloc_fastpath");
1239 slab->alloc_slowpath = get_obj("alloc_slowpath");
1240 slab->free_fastpath = get_obj("free_fastpath");
1241 slab->free_slowpath = get_obj("free_slowpath");
1242 slab->free_frozen= get_obj("free_frozen");
1243 slab->free_add_partial = get_obj("free_add_partial");
1244 slab->free_remove_partial = get_obj("free_remove_partial");
1245 slab->alloc_from_partial = get_obj("alloc_from_partial");
1246 slab->alloc_slab = get_obj("alloc_slab");
1247 slab->alloc_refill = get_obj("alloc_refill");
1248 slab->free_slab = get_obj("free_slab");
1249 slab->cpuslab_flush = get_obj("cpuslab_flush");
1250 slab->deactivate_full = get_obj("deactivate_full");
1251 slab->deactivate_empty = get_obj("deactivate_empty");
1252 slab->deactivate_to_head = get_obj("deactivate_to_head");
1253 slab->deactivate_to_tail = get_obj("deactivate_to_tail");
1254 slab->deactivate_remote_frees = get_obj("deactivate_remote_frees");
Christoph Lameterf715e6f2008-04-29 16:14:46 -07001255 slab->order_fallback = get_obj("order_fallback");
Christoph Lameter9da47142011-06-01 12:26:00 -05001256 slab->cmpxchg_double_cpu_fail = get_obj("cmpxchg_double_cpu_fail");
1257 slab->cmpxchg_double_fail = get_obj("cmpxchg_double_fail");
Christoph Lameteraca726a2011-08-09 16:12:28 -05001258 slab->cpu_partial_alloc = get_obj("cpu_partial_alloc");
1259 slab->cpu_partial_free = get_obj("cpu_partial_free");
Christoph Lameter9da47142011-06-01 12:26:00 -05001260 slab->alloc_node_mismatch = get_obj("alloc_node_mismatch");
1261 slab->deactivate_bypass = get_obj("deactivate_bypass");
Christoph Lameterc09d8752007-05-06 14:49:48 -07001262 chdir("..");
1263 if (slab->name[0] == ':')
1264 alias_targets++;
1265 slab++;
1266 break;
1267 default :
1268 fatal("Unknown file type %lx\n", de->d_type);
1269 }
1270 }
1271 closedir(dir);
1272 slabs = slab - slabinfo;
Christoph Lametera87615b2007-05-09 02:32:37 -07001273 actual_slabs = slabs;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001274 aliases = alias - aliasinfo;
1275 if (slabs > MAX_SLABS)
1276 fatal("Too many slabs\n");
1277 if (aliases > MAX_ALIASES)
1278 fatal("Too many aliases\n");
1279}
1280
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001281static void output_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001282{
1283 struct slabinfo *slab;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001284 int lines = output_lines;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001285
Sergey Senozhatsky4980a962015-11-05 18:45:20 -08001286 for (slab = slabinfo; (slab < slabinfo + slabs) &&
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001287 lines != 0; slab++) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001288
1289 if (slab->alias)
1290 continue;
1291
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001292 if (lines != -1)
1293 lines--;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001294
1295 if (show_numa)
Christoph Lametera87615b2007-05-09 02:32:37 -07001296 slab_numa(slab, 0);
1297 else if (show_track)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001298 show_tracking(slab);
Christoph Lametera87615b2007-05-09 02:32:37 -07001299 else if (validate)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001300 slab_validate(slab);
Christoph Lametera87615b2007-05-09 02:32:37 -07001301 else if (shrink)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001302 slab_shrink(slab);
Christoph Lametera87615b2007-05-09 02:32:37 -07001303 else if (set_debug)
1304 slab_debug(slab);
1305 else if (show_ops)
1306 ops(slab);
1307 else if (show_slab)
1308 slabcache(slab);
Christoph Lametereefaca92007-05-16 22:10:55 -07001309 else if (show_report)
1310 report(slab);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001311 }
1312}
1313
Tobin C. Harding1106b202019-07-11 20:59:38 -07001314static void _xtotals(char *heading, char *underline,
1315 int loss, int size, int partial)
1316{
1317 printf("%s%s", heading, underline);
1318 line = 0;
1319 sort_loss = loss;
1320 sort_size = size;
1321 sort_partial = partial;
1322 sort_slabs();
1323 output_slabs();
1324}
1325
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001326static void xtotals(void)
1327{
Tobin C. Harding1106b202019-07-11 20:59:38 -07001328 char *heading, *underline;
1329
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001330 totals();
1331
1332 link_slabs();
1333 rename_slabs();
1334
Tobin C. Harding1106b202019-07-11 20:59:38 -07001335 heading = "\nSlabs sorted by size\n";
1336 underline = "--------------------\n";
1337 _xtotals(heading, underline, 0, 1, 0);
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001338
Tobin C. Harding1106b202019-07-11 20:59:38 -07001339 heading = "\nSlabs sorted by loss\n";
1340 underline = "--------------------\n";
1341 _xtotals(heading, underline, 1, 0, 0);
1342
1343 heading = "\nSlabs sorted by number of partial slabs\n";
1344 underline = "---------------------------------------\n";
1345 _xtotals(heading, underline, 0, 0, 1);
1346
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001347 printf("\n");
1348}
1349
Christoph Lameterc09d8752007-05-06 14:49:48 -07001350struct option opts[] = {
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001351 { "aliases", no_argument, NULL, 'a' },
1352 { "activity", no_argument, NULL, 'A' },
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001353 { "Bytes", no_argument, NULL, 'B'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001354 { "debug", optional_argument, NULL, 'd' },
1355 { "display-activity", no_argument, NULL, 'D' },
1356 { "empty", no_argument, NULL, 'e' },
1357 { "first-alias", no_argument, NULL, 'f' },
1358 { "help", no_argument, NULL, 'h' },
1359 { "inverted", no_argument, NULL, 'i'},
Sergey Senozhatsky0d00bf52015-11-05 18:45:25 -08001360 { "slabs", no_argument, NULL, 'l' },
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001361 { "Loss", no_argument, NULL, 'L'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001362 { "numa", no_argument, NULL, 'n' },
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001363 { "lines", required_argument, NULL, 'N'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001364 { "ops", no_argument, NULL, 'o' },
Tobin C. Harding53a83f92019-07-11 20:59:42 -07001365 { "partial", no_argument, NULL, 'p'},
Sergey Senozhatsky0d00bf52015-11-05 18:45:25 -08001366 { "report", no_argument, NULL, 'r' },
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001367 { "shrink", no_argument, NULL, 's' },
Sergey Senozhatsky0d00bf52015-11-05 18:45:25 -08001368 { "Size", no_argument, NULL, 'S'},
1369 { "tracking", no_argument, NULL, 't'},
1370 { "Totals", no_argument, NULL, 'T'},
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001371 { "Unreclaim", no_argument, NULL, 'U'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001372 { "validate", no_argument, NULL, 'v' },
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001373 { "Xtotals", no_argument, NULL, 'X'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001374 { "zero", no_argument, NULL, 'z' },
1375 { "1ref", no_argument, NULL, '1'},
Christoph Lameterc09d8752007-05-06 14:49:48 -07001376 { NULL, 0, NULL, 0 }
1377};
1378
1379int main(int argc, char *argv[])
1380{
1381 int c;
1382 int err;
1383 char *pattern_source;
1384
1385 page_size = getpagesize();
Christoph Lameterc09d8752007-05-06 14:49:48 -07001386
Tobin C. Harding53a83f92019-07-11 20:59:42 -07001387 while ((c = getopt_long(argc, argv, "aABd::DefhilLnN:oPrsStTUvXz1",
Christoph Lametera87615b2007-05-09 02:32:37 -07001388 opts, NULL)) != -1)
WANG Congf32143a2007-10-16 23:31:29 -07001389 switch (c) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001390 case 'a':
1391 show_alias = 1;
1392 break;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001393 case 'A':
1394 sort_active = 1;
1395 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001396 case 'B':
1397 show_bytes = 1;
1398 break;
Christoph Lametera87615b2007-05-09 02:32:37 -07001399 case 'd':
1400 set_debug = 1;
1401 if (!debug_opt_scan(optarg))
1402 fatal("Invalid debug option '%s'\n", optarg);
1403 break;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001404 case 'D':
1405 show_activity = 1;
1406 break;
Christoph Lametera87615b2007-05-09 02:32:37 -07001407 case 'e':
1408 show_empty = 1;
1409 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001410 case 'f':
1411 show_first_alias = 1;
1412 break;
1413 case 'h':
1414 usage();
1415 return 0;
1416 case 'i':
1417 show_inverted = 1;
1418 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001419 case 'l':
1420 show_slab = 1;
1421 break;
1422 case 'L':
1423 sort_loss = 1;
1424 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001425 case 'n':
1426 show_numa = 1;
1427 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001428 case 'N':
1429 if (optarg) {
1430 output_lines = atoi(optarg);
1431 if (output_lines < 1)
1432 output_lines = 1;
1433 }
1434 break;
Christoph Lametera87615b2007-05-09 02:32:37 -07001435 case 'o':
1436 show_ops = 1;
1437 break;
1438 case 'r':
1439 show_report = 1;
1440 break;
Tobin C. Harding53a83f92019-07-11 20:59:42 -07001441 case 'P':
1442 sort_partial = 1;
1443 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001444 case 's':
1445 shrink = 1;
1446 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001447 case 'S':
1448 sort_size = 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001449 break;
1450 case 't':
1451 show_track = 1;
1452 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001453 case 'T':
1454 show_totals = 1;
1455 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001456 case 'U':
1457 unreclaim_only = 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001458 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001459 case 'v':
1460 validate = 1;
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -08001461 break;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001462 case 'X':
1463 if (output_lines == -1)
1464 output_lines = 1;
1465 extended_totals = 1;
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001466 show_bytes = 1;
1467 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001468 case 'z':
1469 skip_zero = 0;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001470 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001471 case '1':
1472 show_single_ref = 1;
Yang Shi7ad3f182017-11-15 17:31:59 -08001473 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001474 default:
1475 fatal("%s: Invalid option '%c'\n", argv[0], optopt);
1476
1477 }
1478
Christoph Lametera87615b2007-05-09 02:32:37 -07001479 if (!show_slab && !show_alias && !show_track && !show_report
1480 && !validate && !shrink && !set_debug && !show_ops)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001481 show_slab = 1;
1482
1483 if (argc > optind)
1484 pattern_source = argv[optind];
1485 else
1486 pattern_source = ".*";
1487
1488 err = regcomp(&pattern, pattern_source, REG_ICASE|REG_NOSUB);
1489 if (err)
1490 fatal("%s: Invalid pattern '%s' code %d\n",
1491 argv[0], pattern_source, err);
1492 read_slab_dir();
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001493 if (show_alias) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001494 alias();
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001495 } else if (extended_totals) {
1496 xtotals();
1497 } else if (show_totals) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001498 totals();
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001499 } else {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001500 link_slabs();
1501 rename_slabs();
1502 sort_slabs();
1503 output_slabs();
1504 }
1505 return 0;
1506}