blob: 9b68658b6bb859a5390ac29bbfd35520c79e633c [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"
Tobin C. Hardingcbf800d2019-07-11 20:59:46 -0700151
152 "\nSorting options (--Loss, --Size, --Partial) are mutually exclusive\n"
Christoph Lameterc09d8752007-05-06 14:49:48 -0700153 );
154}
155
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700156static unsigned long read_obj(const char *name)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700157{
158 FILE *f = fopen(name, "r");
159
160 if (!f)
161 buffer[0] = 0;
162 else {
WANG Congf32143a2007-10-16 23:31:29 -0700163 if (!fgets(buffer, sizeof(buffer), f))
Christoph Lameterc09d8752007-05-06 14:49:48 -0700164 buffer[0] = 0;
165 fclose(f);
166 if (buffer[strlen(buffer)] == '\n')
167 buffer[strlen(buffer)] = 0;
168 }
169 return strlen(buffer);
170}
171
172
173/*
174 * Get the contents of an attribute
175 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700176static unsigned long get_obj(const char *name)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700177{
178 if (!read_obj(name))
179 return 0;
180
181 return atol(buffer);
182}
183
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700184static unsigned long get_obj_and_str(const char *name, char **x)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700185{
186 unsigned long result = 0;
187 char *p;
188
189 *x = NULL;
190
191 if (!read_obj(name)) {
192 x = NULL;
193 return 0;
194 }
195 result = strtoul(buffer, &p, 10);
196 while (*p == ' ')
197 p++;
198 if (*p)
199 *x = strdup(p);
200 return result;
201}
202
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700203static void set_obj(struct slabinfo *s, const char *name, int n)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700204{
205 char x[100];
Christoph Lametera87615b2007-05-09 02:32:37 -0700206 FILE *f;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700207
WANG Congf32143a2007-10-16 23:31:29 -0700208 snprintf(x, 100, "%s/%s", s->name, name);
Christoph Lametera87615b2007-05-09 02:32:37 -0700209 f = fopen(x, "w");
Christoph Lameterc09d8752007-05-06 14:49:48 -0700210 if (!f)
211 fatal("Cannot write to %s\n", x);
212
213 fprintf(f, "%d\n", n);
214 fclose(f);
215}
216
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700217static unsigned long read_slab_obj(struct slabinfo *s, const char *name)
Christoph Lametera87615b2007-05-09 02:32:37 -0700218{
219 char x[100];
220 FILE *f;
WANG Congf32143a2007-10-16 23:31:29 -0700221 size_t l;
Christoph Lametera87615b2007-05-09 02:32:37 -0700222
WANG Congf32143a2007-10-16 23:31:29 -0700223 snprintf(x, 100, "%s/%s", s->name, name);
Christoph Lametera87615b2007-05-09 02:32:37 -0700224 f = fopen(x, "r");
225 if (!f) {
226 buffer[0] = 0;
227 l = 0;
228 } else {
229 l = fread(buffer, 1, sizeof(buffer), f);
230 buffer[l] = 0;
231 fclose(f);
232 }
233 return l;
234}
235
236
Christoph Lameterc09d8752007-05-06 14:49:48 -0700237/*
238 * Put a size string together
239 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700240static int store_size(char *buffer, unsigned long value)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700241{
242 unsigned long divisor = 1;
243 char trailer = 0;
244 int n;
245
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800246 if (!show_bytes) {
247 if (value > 1000000000UL) {
248 divisor = 100000000UL;
249 trailer = 'G';
250 } else if (value > 1000000UL) {
251 divisor = 100000UL;
252 trailer = 'M';
253 } else if (value > 1000UL) {
254 divisor = 100;
255 trailer = 'K';
256 }
Christoph Lameterc09d8752007-05-06 14:49:48 -0700257 }
258
259 value /= divisor;
260 n = sprintf(buffer, "%ld",value);
261 if (trailer) {
262 buffer[n] = trailer;
263 n++;
264 buffer[n] = 0;
265 }
266 if (divisor != 1) {
267 memmove(buffer + n - 2, buffer + n - 3, 4);
268 buffer[n-2] = '.';
269 n++;
270 }
271 return n;
272}
273
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700274static void decode_numa_list(int *numa, char *t)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700275{
276 int node;
277 int nr;
278
279 memset(numa, 0, MAX_NODES * sizeof(int));
280
Christoph Lametereefaca92007-05-16 22:10:55 -0700281 if (!t)
282 return;
283
Christoph Lameterc09d8752007-05-06 14:49:48 -0700284 while (*t == 'N') {
285 t++;
286 node = strtoul(t, &t, 10);
287 if (*t == '=') {
288 t++;
289 nr = strtoul(t, &t, 10);
290 numa[node] = nr;
291 if (node > highest_node)
292 highest_node = node;
293 }
294 while (*t == ' ')
295 t++;
296 }
297}
298
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700299static void slab_validate(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700300{
Christoph Lameter32f93062007-05-18 00:36:43 -0700301 if (strcmp(s->name, "*") == 0)
302 return;
303
Christoph Lameterc09d8752007-05-06 14:49:48 -0700304 set_obj(s, "validate", 1);
305}
306
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700307static void slab_shrink(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700308{
Christoph Lameter32f93062007-05-18 00:36:43 -0700309 if (strcmp(s->name, "*") == 0)
310 return;
311
Christoph Lameterc09d8752007-05-06 14:49:48 -0700312 set_obj(s, "shrink", 1);
313}
314
315int line = 0;
316
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700317static void first_line(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700318{
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800319 if (show_activity)
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800320 printf("Name Objects Alloc Free"
321 " %%Fast Fallb O CmpX UL\n");
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800322 else
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800323 printf("Name Objects Objsize %s "
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -0800324 "Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n",
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800325 sort_loss ? " Loss" : "Space");
Christoph Lameterc09d8752007-05-06 14:49:48 -0700326}
327
328/*
329 * Find the shortest alias of a slab
330 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700331static struct aliasinfo *find_one_alias(struct slabinfo *find)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700332{
333 struct aliasinfo *a;
334 struct aliasinfo *best = NULL;
335
336 for(a = aliasinfo;a < aliasinfo + aliases; a++) {
337 if (a->slab == find &&
338 (!best || strlen(best->name) < strlen(a->name))) {
339 best = a;
340 if (strncmp(a->name,"kmall", 5) == 0)
341 return best;
342 }
343 }
Christoph Lametera87615b2007-05-09 02:32:37 -0700344 return best;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700345}
346
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700347static unsigned long slab_size(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700348{
349 return s->slabs * (page_size << s->order);
350}
351
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700352static unsigned long slab_activity(struct slabinfo *s)
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800353{
354 return s->alloc_fastpath + s->free_fastpath +
355 s->alloc_slowpath + s->free_slowpath;
356}
357
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -0800358static unsigned long slab_waste(struct slabinfo *s)
359{
360 return slab_size(s) - s->objects * s->object_size;
361}
362
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700363static void slab_numa(struct slabinfo *s, int mode)
Christoph Lametera87615b2007-05-09 02:32:37 -0700364{
365 int node;
366
367 if (strcmp(s->name, "*") == 0)
368 return;
369
370 if (!highest_node) {
371 printf("\n%s: No NUMA information available.\n", s->name);
372 return;
373 }
374
375 if (skip_zero && !s->slabs)
376 return;
377
378 if (!line) {
379 printf("\n%-21s:", mode ? "NUMA nodes" : "Slab");
380 for(node = 0; node <= highest_node; node++)
381 printf(" %4d", node);
382 printf("\n----------------------");
383 for(node = 0; node <= highest_node; node++)
384 printf("-----");
385 printf("\n");
386 }
387 printf("%-21s ", mode ? "All slabs" : s->name);
388 for(node = 0; node <= highest_node; node++) {
389 char b[20];
390
391 store_size(b, s->numa[node]);
392 printf(" %4s", b);
393 }
394 printf("\n");
395 if (mode) {
396 printf("%-21s ", "Partial slabs");
397 for(node = 0; node <= highest_node; node++) {
398 char b[20];
399
400 store_size(b, s->numa_partial[node]);
401 printf(" %4s", b);
402 }
403 printf("\n");
404 }
405 line++;
406}
407
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700408static void show_tracking(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700409{
410 printf("\n%s: Kernel object allocation\n", s->name);
411 printf("-----------------------------------------------------------------------\n");
412 if (read_slab_obj(s, "alloc_calls"))
Christoph Lameter9da47142011-06-01 12:26:00 -0500413 printf("%s", buffer);
Christoph Lametera87615b2007-05-09 02:32:37 -0700414 else
415 printf("No Data\n");
416
417 printf("\n%s: Kernel object freeing\n", s->name);
418 printf("------------------------------------------------------------------------\n");
419 if (read_slab_obj(s, "free_calls"))
Christoph Lameter9da47142011-06-01 12:26:00 -0500420 printf("%s", buffer);
Christoph Lametera87615b2007-05-09 02:32:37 -0700421 else
422 printf("No Data\n");
423
424}
425
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700426static void ops(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700427{
428 if (strcmp(s->name, "*") == 0)
429 return;
430
431 if (read_slab_obj(s, "ops")) {
432 printf("\n%s: kmem_cache operations\n", s->name);
433 printf("--------------------------------------------\n");
Christoph Lameter9da47142011-06-01 12:26:00 -0500434 printf("%s", buffer);
Christoph Lametera87615b2007-05-09 02:32:37 -0700435 } else
436 printf("\n%s has no kmem_cache operations\n", s->name);
437}
438
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700439static const char *onoff(int x)
Christoph Lametera87615b2007-05-09 02:32:37 -0700440{
441 if (x)
442 return "On ";
443 return "Off";
444}
445
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700446static void slab_stats(struct slabinfo *s)
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800447{
448 unsigned long total_alloc;
449 unsigned long total_free;
450 unsigned long total;
451
452 if (!s->alloc_slab)
453 return;
454
455 total_alloc = s->alloc_fastpath + s->alloc_slowpath;
456 total_free = s->free_fastpath + s->free_slowpath;
457
458 if (!total_alloc)
459 return;
460
461 printf("\n");
462 printf("Slab Perf Counter Alloc Free %%Al %%Fr\n");
463 printf("--------------------------------------------------\n");
464 printf("Fastpath %8lu %8lu %3lu %3lu\n",
465 s->alloc_fastpath, s->free_fastpath,
466 s->alloc_fastpath * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800467 total_free ? s->free_fastpath * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800468 printf("Slowpath %8lu %8lu %3lu %3lu\n",
469 total_alloc - s->alloc_fastpath, s->free_slowpath,
470 (total_alloc - s->alloc_fastpath) * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800471 total_free ? s->free_slowpath * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800472 printf("Page Alloc %8lu %8lu %3lu %3lu\n",
473 s->alloc_slab, s->free_slab,
474 s->alloc_slab * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800475 total_free ? s->free_slab * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800476 printf("Add partial %8lu %8lu %3lu %3lu\n",
477 s->deactivate_to_head + s->deactivate_to_tail,
478 s->free_add_partial,
479 (s->deactivate_to_head + s->deactivate_to_tail) * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800480 total_free ? s->free_add_partial * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800481 printf("Remove partial %8lu %8lu %3lu %3lu\n",
482 s->alloc_from_partial, s->free_remove_partial,
483 s->alloc_from_partial * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800484 total_free ? s->free_remove_partial * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800485
Christoph Lameteraca726a2011-08-09 16:12:28 -0500486 printf("Cpu partial list %8lu %8lu %3lu %3lu\n",
487 s->cpu_partial_alloc, s->cpu_partial_free,
488 s->cpu_partial_alloc * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800489 total_free ? s->cpu_partial_free * 100 / total_free : 0);
Christoph Lameteraca726a2011-08-09 16:12:28 -0500490
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800491 printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n",
492 s->deactivate_remote_frees, s->free_frozen,
493 s->deactivate_remote_frees * 100 / total_alloc,
majianpeng4b57ad92012-06-26 09:30:31 +0800494 total_free ? s->free_frozen * 100 / total_free : 0);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800495
496 printf("Total %8lu %8lu\n\n", total_alloc, total_free);
497
498 if (s->cpuslab_flush)
499 printf("Flushes %8lu\n", s->cpuslab_flush);
500
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800501 total = s->deactivate_full + s->deactivate_empty +
Christoph Lameter9da47142011-06-01 12:26:00 -0500502 s->deactivate_to_head + s->deactivate_to_tail + s->deactivate_bypass;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800503
Christoph Lameter9da47142011-06-01 12:26:00 -0500504 if (total) {
Colin Ian King7c5b7232016-06-24 14:50:21 -0700505 printf("\nSlab Deactivation Occurrences %%\n");
Christoph Lameter9da47142011-06-01 12:26:00 -0500506 printf("-------------------------------------------------\n");
507 printf("Slab full %7lu %3lu%%\n",
508 s->deactivate_full, (s->deactivate_full * 100) / total);
509 printf("Slab empty %7lu %3lu%%\n",
510 s->deactivate_empty, (s->deactivate_empty * 100) / total);
511 printf("Moved to head of partial list %7lu %3lu%%\n",
512 s->deactivate_to_head, (s->deactivate_to_head * 100) / total);
513 printf("Moved to tail of partial list %7lu %3lu%%\n",
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800514 s->deactivate_to_tail, (s->deactivate_to_tail * 100) / total);
Christoph Lameter9da47142011-06-01 12:26:00 -0500515 printf("Deactivation bypass %7lu %3lu%%\n",
516 s->deactivate_bypass, (s->deactivate_bypass * 100) / total);
517 printf("Refilled from foreign frees %7lu %3lu%%\n",
518 s->alloc_refill, (s->alloc_refill * 100) / total);
519 printf("Node mismatch %7lu %3lu%%\n",
520 s->alloc_node_mismatch, (s->alloc_node_mismatch * 100) / total);
521 }
522
Dan Carpenter2d6a4d62016-07-20 15:45:05 -0700523 if (s->cmpxchg_double_fail || s->cmpxchg_double_cpu_fail) {
Christoph Lameter9da47142011-06-01 12:26:00 -0500524 printf("\nCmpxchg_double Looping\n------------------------\n");
525 printf("Locked Cmpxchg Double redos %lu\nUnlocked Cmpxchg Double redos %lu\n",
526 s->cmpxchg_double_fail, s->cmpxchg_double_cpu_fail);
Dan Carpenter2d6a4d62016-07-20 15:45:05 -0700527 }
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800528}
529
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700530static void report(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700531{
532 if (strcmp(s->name, "*") == 0)
533 return;
Christoph Lametereefaca92007-05-16 22:10:55 -0700534
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800535 printf("\nSlabcache: %-15s Aliases: %2d Order : %2d Objects: %lu\n",
Christoph Lametereefaca92007-05-16 22:10:55 -0700536 s->name, s->aliases, s->order, s->objects);
Christoph Lametera87615b2007-05-09 02:32:37 -0700537 if (s->hwcache_align)
538 printf("** Hardware cacheline aligned\n");
539 if (s->cache_dma)
540 printf("** Memory is allocated in a special DMA zone\n");
541 if (s->destroy_by_rcu)
542 printf("** Slabs are destroyed via RCU\n");
543 if (s->reclaim_account)
544 printf("** Reclaim accounting active\n");
545
546 printf("\nSizes (bytes) Slabs Debug Memory\n");
547 printf("------------------------------------------------------------------------\n");
548 printf("Object : %7d Total : %7ld Sanity Checks : %s Total: %7ld\n",
549 s->object_size, s->slabs, onoff(s->sanity_checks),
550 s->slabs * (page_size << s->order));
551 printf("SlabObj: %7d Full : %7ld Redzoning : %s Used : %7ld\n",
552 s->slab_size, s->slabs - s->partial - s->cpu_slabs,
553 onoff(s->red_zone), s->objects * s->object_size);
554 printf("SlabSiz: %7d Partial: %7ld Poisoning : %s Loss : %7ld\n",
555 page_size << s->order, s->partial, onoff(s->poison),
556 s->slabs * (page_size << s->order) - s->objects * s->object_size);
557 printf("Loss : %7d CpuSlab: %7d Tracking : %s Lalig: %7ld\n",
558 s->slab_size - s->object_size, s->cpu_slabs, onoff(s->store_user),
559 (s->slab_size - s->object_size) * s->objects);
560 printf("Align : %7d Objects: %7d Tracing : %s Lpadd: %7ld\n",
561 s->align, s->objs_per_slab, onoff(s->trace),
562 ((page_size << s->order) - s->objs_per_slab * s->slab_size) *
563 s->slabs);
564
565 ops(s);
566 show_tracking(s);
567 slab_numa(s, 1);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800568 slab_stats(s);
Christoph Lametera87615b2007-05-09 02:32:37 -0700569}
Christoph Lameterc09d8752007-05-06 14:49:48 -0700570
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700571static void slabcache(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700572{
573 char size_str[20];
574 char dist_str[40];
575 char flags[20];
576 char *p = flags;
577
Christoph Lametera87615b2007-05-09 02:32:37 -0700578 if (strcmp(s->name, "*") == 0)
579 return;
580
Yang Shi7ad3f182017-11-15 17:31:59 -0800581 if (unreclaim_only && s->reclaim_account)
582 return;
583
Christoph Lametera87615b2007-05-09 02:32:37 -0700584 if (actual_slabs == 1) {
585 report(s);
586 return;
587 }
588
589 if (skip_zero && !show_empty && !s->slabs)
590 return;
591
592 if (show_empty && s->slabs)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700593 return;
594
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -0800595 if (sort_loss == 0)
596 store_size(size_str, slab_size(s));
597 else
598 store_size(size_str, slab_waste(s));
Christoph Lameter205ab992008-04-14 19:11:40 +0300599 snprintf(dist_str, 40, "%lu/%lu/%d", s->slabs - s->cpu_slabs,
600 s->partial, s->cpu_slabs);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700601
602 if (!line++)
603 first_line();
604
605 if (s->aliases)
606 *p++ = '*';
607 if (s->cache_dma)
608 *p++ = 'd';
609 if (s->hwcache_align)
610 *p++ = 'A';
611 if (s->poison)
612 *p++ = 'P';
613 if (s->reclaim_account)
614 *p++ = 'a';
615 if (s->red_zone)
616 *p++ = 'Z';
617 if (s->sanity_checks)
618 *p++ = 'F';
619 if (s->store_user)
620 *p++ = 'U';
621 if (s->trace)
622 *p++ = 'T';
623
624 *p = 0;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800625 if (show_activity) {
626 unsigned long total_alloc;
627 unsigned long total_free;
628
629 total_alloc = s->alloc_fastpath + s->alloc_slowpath;
630 total_free = s->free_fastpath + s->free_slowpath;
631
Christoph Lameter9da47142011-06-01 12:26:00 -0500632 printf("%-21s %8ld %10ld %10ld %3ld %3ld %5ld %1d %4ld %4ld\n",
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800633 s->name, s->objects,
634 total_alloc, total_free,
635 total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0,
Christoph Lameterf715e6f2008-04-29 16:14:46 -0700636 total_free ? (s->free_fastpath * 100 / total_free) : 0,
Christoph Lameter9da47142011-06-01 12:26:00 -0500637 s->order_fallback, s->order, s->cmpxchg_double_fail,
638 s->cmpxchg_double_cpu_fail);
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -0800639 } else {
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800640 printf("%-21s %8ld %7d %15s %14s %4d %1d %3ld %3ld %s\n",
Christoph Lameter8ff12cf2008-02-07 17:47:41 -0800641 s->name, s->objects, s->object_size, size_str, dist_str,
642 s->objs_per_slab, s->order,
643 s->slabs ? (s->partial * 100) / s->slabs : 100,
644 s->slabs ? (s->objects * s->object_size * 100) /
645 (s->slabs * (page_size << s->order)) : 100,
646 flags);
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -0800647 }
Christoph Lameterc09d8752007-05-06 14:49:48 -0700648}
649
Christoph Lametera87615b2007-05-09 02:32:37 -0700650/*
651 * Analyze debug options. Return false if something is amiss.
652 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700653static int debug_opt_scan(char *opt)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700654{
Christoph Lametera87615b2007-05-09 02:32:37 -0700655 if (!opt || !opt[0] || strcmp(opt, "-") == 0)
656 return 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700657
Christoph Lametera87615b2007-05-09 02:32:37 -0700658 if (strcasecmp(opt, "a") == 0) {
659 sanity = 1;
660 poison = 1;
661 redzone = 1;
662 tracking = 1;
663 return 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700664 }
Christoph Lameterc09d8752007-05-06 14:49:48 -0700665
Christoph Lametera87615b2007-05-09 02:32:37 -0700666 for ( ; *opt; opt++)
Christoph Lameter0d24db32010-10-21 13:01:56 -0500667 switch (*opt) {
Christoph Lametera87615b2007-05-09 02:32:37 -0700668 case 'F' : case 'f':
669 if (sanity)
670 return 0;
671 sanity = 1;
672 break;
673 case 'P' : case 'p':
674 if (poison)
675 return 0;
676 poison = 1;
677 break;
678
679 case 'Z' : case 'z':
680 if (redzone)
681 return 0;
682 redzone = 1;
683 break;
684
685 case 'U' : case 'u':
686 if (tracking)
687 return 0;
688 tracking = 1;
689 break;
690
691 case 'T' : case 't':
692 if (tracing)
693 return 0;
694 tracing = 1;
695 break;
696 default:
697 return 0;
698 }
699 return 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700700}
701
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700702static int slab_empty(struct slabinfo *s)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700703{
Christoph Lametera87615b2007-05-09 02:32:37 -0700704 if (s->objects > 0)
705 return 0;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700706
Christoph Lametera87615b2007-05-09 02:32:37 -0700707 /*
708 * We may still have slabs even if there are no objects. Shrinking will
709 * remove them.
710 */
711 if (s->slabs != 0)
712 set_obj(s, "shrink", 1);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700713
Christoph Lametera87615b2007-05-09 02:32:37 -0700714 return 1;
715}
716
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700717static void slab_debug(struct slabinfo *s)
Christoph Lametera87615b2007-05-09 02:32:37 -0700718{
Christoph Lameter32f93062007-05-18 00:36:43 -0700719 if (strcmp(s->name, "*") == 0)
720 return;
721
Christoph Lametera87615b2007-05-09 02:32:37 -0700722 if (sanity && !s->sanity_checks) {
Daniel Wagnere25974aa2020-01-30 22:14:17 -0800723 set_obj(s, "sanity_checks", 1);
Christoph Lametera87615b2007-05-09 02:32:37 -0700724 }
725 if (!sanity && s->sanity_checks) {
726 if (slab_empty(s))
Daniel Wagnere25974aa2020-01-30 22:14:17 -0800727 set_obj(s, "sanity_checks", 0);
Christoph Lametera87615b2007-05-09 02:32:37 -0700728 else
729 fprintf(stderr, "%s not empty cannot disable sanity checks\n", s->name);
730 }
731 if (redzone && !s->red_zone) {
732 if (slab_empty(s))
733 set_obj(s, "red_zone", 1);
734 else
735 fprintf(stderr, "%s not empty cannot enable redzoning\n", s->name);
736 }
737 if (!redzone && s->red_zone) {
738 if (slab_empty(s))
739 set_obj(s, "red_zone", 0);
740 else
741 fprintf(stderr, "%s not empty cannot disable redzoning\n", s->name);
742 }
743 if (poison && !s->poison) {
744 if (slab_empty(s))
745 set_obj(s, "poison", 1);
746 else
747 fprintf(stderr, "%s not empty cannot enable poisoning\n", s->name);
748 }
749 if (!poison && s->poison) {
750 if (slab_empty(s))
751 set_obj(s, "poison", 0);
752 else
753 fprintf(stderr, "%s not empty cannot disable poisoning\n", s->name);
754 }
755 if (tracking && !s->store_user) {
756 if (slab_empty(s))
757 set_obj(s, "store_user", 1);
758 else
759 fprintf(stderr, "%s not empty cannot enable tracking\n", s->name);
760 }
761 if (!tracking && s->store_user) {
762 if (slab_empty(s))
763 set_obj(s, "store_user", 0);
764 else
765 fprintf(stderr, "%s not empty cannot disable tracking\n", s->name);
766 }
767 if (tracing && !s->trace) {
768 if (slabs == 1)
769 set_obj(s, "trace", 1);
770 else
771 fprintf(stderr, "%s can only enable trace for one slab at a time\n", s->name);
772 }
773 if (!tracing && s->trace)
774 set_obj(s, "trace", 1);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700775}
776
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -0700777static void totals(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -0700778{
779 struct slabinfo *s;
780
781 int used_slabs = 0;
782 char b1[20], b2[20], b3[20], b4[20];
783 unsigned long long max = 1ULL << 63;
784
785 /* Object size */
786 unsigned long long min_objsize = max, max_objsize = 0, avg_objsize;
787
788 /* Number of partial slabs in a slabcache */
789 unsigned long long min_partial = max, max_partial = 0,
790 avg_partial, total_partial = 0;
791
792 /* Number of slabs in a slab cache */
793 unsigned long long min_slabs = max, max_slabs = 0,
794 avg_slabs, total_slabs = 0;
795
796 /* Size of the whole slab */
797 unsigned long long min_size = max, max_size = 0,
798 avg_size, total_size = 0;
799
800 /* Bytes used for object storage in a slab */
801 unsigned long long min_used = max, max_used = 0,
802 avg_used, total_used = 0;
803
804 /* Waste: Bytes used for alignment and padding */
805 unsigned long long min_waste = max, max_waste = 0,
806 avg_waste, total_waste = 0;
807 /* Number of objects in a slab */
808 unsigned long long min_objects = max, max_objects = 0,
809 avg_objects, total_objects = 0;
810 /* Waste per object */
811 unsigned long long min_objwaste = max,
812 max_objwaste = 0, avg_objwaste,
813 total_objwaste = 0;
814
815 /* Memory per object */
816 unsigned long long min_memobj = max,
817 max_memobj = 0, avg_memobj,
818 total_objsize = 0;
819
820 /* Percentage of partial slabs per slab */
821 unsigned long min_ppart = 100, max_ppart = 0,
822 avg_ppart, total_ppart = 0;
823
824 /* Number of objects in partial slabs */
825 unsigned long min_partobj = max, max_partobj = 0,
826 avg_partobj, total_partobj = 0;
827
828 /* Percentage of partial objects of all objects in a slab */
829 unsigned long min_ppartobj = 100, max_ppartobj = 0,
830 avg_ppartobj, total_ppartobj = 0;
831
832
833 for (s = slabinfo; s < slabinfo + slabs; s++) {
834 unsigned long long size;
835 unsigned long used;
836 unsigned long long wasted;
837 unsigned long long objwaste;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700838 unsigned long percentage_partial_slabs;
839 unsigned long percentage_partial_objs;
840
841 if (!s->slabs || !s->objects)
842 continue;
843
844 used_slabs++;
845
846 size = slab_size(s);
847 used = s->objects * s->object_size;
848 wasted = size - used;
849 objwaste = s->slab_size - s->object_size;
850
Christoph Lameterc09d8752007-05-06 14:49:48 -0700851 percentage_partial_slabs = s->partial * 100 / s->slabs;
852 if (percentage_partial_slabs > 100)
853 percentage_partial_slabs = 100;
854
Christoph Lameter205ab992008-04-14 19:11:40 +0300855 percentage_partial_objs = s->objects_partial * 100
Christoph Lameterc09d8752007-05-06 14:49:48 -0700856 / s->objects;
857
858 if (percentage_partial_objs > 100)
859 percentage_partial_objs = 100;
860
861 if (s->object_size < min_objsize)
862 min_objsize = s->object_size;
863 if (s->partial < min_partial)
864 min_partial = s->partial;
865 if (s->slabs < min_slabs)
866 min_slabs = s->slabs;
867 if (size < min_size)
868 min_size = size;
869 if (wasted < min_waste)
870 min_waste = wasted;
871 if (objwaste < min_objwaste)
872 min_objwaste = objwaste;
873 if (s->objects < min_objects)
874 min_objects = s->objects;
875 if (used < min_used)
876 min_used = used;
Christoph Lameter205ab992008-04-14 19:11:40 +0300877 if (s->objects_partial < min_partobj)
878 min_partobj = s->objects_partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700879 if (percentage_partial_slabs < min_ppart)
880 min_ppart = percentage_partial_slabs;
881 if (percentage_partial_objs < min_ppartobj)
882 min_ppartobj = percentage_partial_objs;
883 if (s->slab_size < min_memobj)
884 min_memobj = s->slab_size;
885
886 if (s->object_size > max_objsize)
887 max_objsize = s->object_size;
888 if (s->partial > max_partial)
889 max_partial = s->partial;
890 if (s->slabs > max_slabs)
891 max_slabs = s->slabs;
892 if (size > max_size)
893 max_size = size;
894 if (wasted > max_waste)
895 max_waste = wasted;
896 if (objwaste > max_objwaste)
897 max_objwaste = objwaste;
898 if (s->objects > max_objects)
899 max_objects = s->objects;
900 if (used > max_used)
901 max_used = used;
Christoph Lameter205ab992008-04-14 19:11:40 +0300902 if (s->objects_partial > max_partobj)
903 max_partobj = s->objects_partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700904 if (percentage_partial_slabs > max_ppart)
905 max_ppart = percentage_partial_slabs;
906 if (percentage_partial_objs > max_ppartobj)
907 max_ppartobj = percentage_partial_objs;
908 if (s->slab_size > max_memobj)
909 max_memobj = s->slab_size;
910
911 total_partial += s->partial;
912 total_slabs += s->slabs;
913 total_size += size;
914 total_waste += wasted;
915
916 total_objects += s->objects;
917 total_used += used;
Christoph Lameter205ab992008-04-14 19:11:40 +0300918 total_partobj += s->objects_partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -0700919 total_ppart += percentage_partial_slabs;
920 total_ppartobj += percentage_partial_objs;
921
922 total_objwaste += s->objects * objwaste;
923 total_objsize += s->objects * s->slab_size;
924 }
925
926 if (!total_objects) {
927 printf("No objects\n");
928 return;
929 }
930 if (!used_slabs) {
931 printf("No slabs\n");
932 return;
933 }
934
935 /* Per slab averages */
936 avg_partial = total_partial / used_slabs;
937 avg_slabs = total_slabs / used_slabs;
938 avg_size = total_size / used_slabs;
939 avg_waste = total_waste / used_slabs;
940
941 avg_objects = total_objects / used_slabs;
942 avg_used = total_used / used_slabs;
943 avg_partobj = total_partobj / used_slabs;
944 avg_ppart = total_ppart / used_slabs;
945 avg_ppartobj = total_ppartobj / used_slabs;
946
947 /* Per object object sizes */
948 avg_objsize = total_used / total_objects;
949 avg_objwaste = total_objwaste / total_objects;
950 avg_partobj = total_partobj * 100 / total_objects;
951 avg_memobj = total_objsize / total_objects;
952
953 printf("Slabcache Totals\n");
954 printf("----------------\n");
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800955 printf("Slabcaches : %15d Aliases : %11d->%-3d Active: %3d\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700956 slabs, aliases, alias_targets, used_slabs);
957
958 store_size(b1, total_size);store_size(b2, total_waste);
959 store_size(b3, total_waste * 100 / total_used);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800960 printf("Memory used: %15s # Loss : %15s MRatio:%6s%%\n", b1, b2, b3);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700961
962 store_size(b1, total_objects);store_size(b2, total_partobj);
963 store_size(b3, total_partobj * 100 / total_objects);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800964 printf("# Objects : %15s # PartObj: %15s ORatio:%6s%%\n", b1, b2, b3);
Christoph Lameterc09d8752007-05-06 14:49:48 -0700965
966 printf("\n");
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800967 printf("Per Cache Average "
968 "Min Max Total\n");
969 printf("---------------------------------------"
970 "-------------------------------------\n");
Christoph Lameterc09d8752007-05-06 14:49:48 -0700971
972 store_size(b1, avg_objects);store_size(b2, min_objects);
973 store_size(b3, max_objects);store_size(b4, total_objects);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800974 printf("#Objects %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700975 b1, b2, b3, b4);
976
977 store_size(b1, avg_slabs);store_size(b2, min_slabs);
978 store_size(b3, max_slabs);store_size(b4, total_slabs);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800979 printf("#Slabs %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700980 b1, b2, b3, b4);
981
982 store_size(b1, avg_partial);store_size(b2, min_partial);
983 store_size(b3, max_partial);store_size(b4, total_partial);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800984 printf("#PartSlab %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700985 b1, b2, b3, b4);
986 store_size(b1, avg_ppart);store_size(b2, min_ppart);
987 store_size(b3, max_ppart);
988 store_size(b4, total_partial * 100 / total_slabs);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800989 printf("%%PartSlab%15s%% %15s%% %15s%% %15s%%\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700990 b1, b2, b3, b4);
991
992 store_size(b1, avg_partobj);store_size(b2, min_partobj);
993 store_size(b3, max_partobj);
994 store_size(b4, total_partobj);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -0800995 printf("PartObjs %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -0700996 b1, b2, b3, b4);
997
998 store_size(b1, avg_ppartobj);store_size(b2, min_ppartobj);
999 store_size(b3, max_ppartobj);
1000 store_size(b4, total_partobj * 100 / total_objects);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001001 printf("%% PartObj%15s%% %15s%% %15s%% %15s%%\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001002 b1, b2, b3, b4);
1003
1004 store_size(b1, avg_size);store_size(b2, min_size);
1005 store_size(b3, max_size);store_size(b4, total_size);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001006 printf("Memory %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001007 b1, b2, b3, b4);
1008
1009 store_size(b1, avg_used);store_size(b2, min_used);
1010 store_size(b3, max_used);store_size(b4, total_used);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001011 printf("Used %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001012 b1, b2, b3, b4);
1013
1014 store_size(b1, avg_waste);store_size(b2, min_waste);
1015 store_size(b3, max_waste);store_size(b4, total_waste);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001016 printf("Loss %15s %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001017 b1, b2, b3, b4);
1018
1019 printf("\n");
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001020 printf("Per Object Average "
1021 "Min Max\n");
1022 printf("---------------------------------------"
1023 "--------------------\n");
Christoph Lameterc09d8752007-05-06 14:49:48 -07001024
1025 store_size(b1, avg_memobj);store_size(b2, min_memobj);
1026 store_size(b3, max_memobj);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001027 printf("Memory %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001028 b1, b2, b3);
1029 store_size(b1, avg_objsize);store_size(b2, min_objsize);
1030 store_size(b3, max_objsize);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001031 printf("User %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001032 b1, b2, b3);
1033
1034 store_size(b1, avg_objwaste);store_size(b2, min_objwaste);
1035 store_size(b3, max_objwaste);
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001036 printf("Loss %15s %15s %15s\n",
Christoph Lameterc09d8752007-05-06 14:49:48 -07001037 b1, b2, b3);
1038}
1039
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001040static void sort_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001041{
1042 struct slabinfo *s1,*s2;
1043
1044 for (s1 = slabinfo; s1 < slabinfo + slabs; s1++) {
1045 for (s2 = s1 + 1; s2 < slabinfo + slabs; s2++) {
1046 int result;
1047
1048 if (sort_size)
1049 result = slab_size(s1) < slab_size(s2);
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001050 else if (sort_active)
1051 result = slab_activity(s1) < slab_activity(s2);
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -08001052 else if (sort_loss)
1053 result = slab_waste(s1) < slab_waste(s2);
Tobin C. Harding1106b202019-07-11 20:59:38 -07001054 else if (sort_partial)
1055 result = s1->partial < s2->partial;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001056 else
1057 result = strcasecmp(s1->name, s2->name);
1058
1059 if (show_inverted)
1060 result = -result;
1061
1062 if (result > 0) {
1063 struct slabinfo t;
1064
1065 memcpy(&t, s1, sizeof(struct slabinfo));
1066 memcpy(s1, s2, sizeof(struct slabinfo));
1067 memcpy(s2, &t, sizeof(struct slabinfo));
1068 }
1069 }
1070 }
1071}
1072
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001073static void sort_aliases(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001074{
1075 struct aliasinfo *a1,*a2;
1076
1077 for (a1 = aliasinfo; a1 < aliasinfo + aliases; a1++) {
1078 for (a2 = a1 + 1; a2 < aliasinfo + aliases; a2++) {
1079 char *n1, *n2;
1080
1081 n1 = a1->name;
1082 n2 = a2->name;
1083 if (show_alias && !show_inverted) {
1084 n1 = a1->ref;
1085 n2 = a2->ref;
1086 }
1087 if (strcasecmp(n1, n2) > 0) {
1088 struct aliasinfo t;
1089
1090 memcpy(&t, a1, sizeof(struct aliasinfo));
1091 memcpy(a1, a2, sizeof(struct aliasinfo));
1092 memcpy(a2, &t, sizeof(struct aliasinfo));
1093 }
1094 }
1095 }
1096}
1097
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001098static void link_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001099{
1100 struct aliasinfo *a;
1101 struct slabinfo *s;
1102
1103 for (a = aliasinfo; a < aliasinfo + aliases; a++) {
1104
Christoph Lametera87615b2007-05-09 02:32:37 -07001105 for (s = slabinfo; s < slabinfo + slabs; s++)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001106 if (strcmp(a->ref, s->name) == 0) {
1107 a->slab = s;
1108 s->refs++;
1109 break;
1110 }
1111 if (s == slabinfo + slabs)
1112 fatal("Unresolved alias %s\n", a->ref);
1113 }
1114}
1115
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001116static void alias(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001117{
1118 struct aliasinfo *a;
1119 char *active = NULL;
1120
1121 sort_aliases();
1122 link_slabs();
1123
1124 for(a = aliasinfo; a < aliasinfo + aliases; a++) {
1125
1126 if (!show_single_ref && a->slab->refs == 1)
1127 continue;
1128
1129 if (!show_inverted) {
1130 if (active) {
1131 if (strcmp(a->slab->name, active) == 0) {
1132 printf(" %s", a->name);
1133 continue;
1134 }
1135 }
Christoph Lametera87615b2007-05-09 02:32:37 -07001136 printf("\n%-12s <- %s", a->slab->name, a->name);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001137 active = a->slab->name;
1138 }
1139 else
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001140 printf("%-15s -> %s\n", a->name, a->slab->name);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001141 }
1142 if (active)
1143 printf("\n");
1144}
1145
1146
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001147static void rename_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001148{
1149 struct slabinfo *s;
1150 struct aliasinfo *a;
1151
1152 for (s = slabinfo; s < slabinfo + slabs; s++) {
1153 if (*s->name != ':')
1154 continue;
1155
1156 if (s->refs > 1 && !show_first_alias)
1157 continue;
1158
1159 a = find_one_alias(s);
1160
Christoph Lametera87615b2007-05-09 02:32:37 -07001161 if (a)
1162 s->name = a->name;
1163 else {
1164 s->name = "*";
1165 actual_slabs--;
1166 }
Christoph Lameterc09d8752007-05-06 14:49:48 -07001167 }
1168}
1169
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001170static int slab_mismatch(char *slab)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001171{
1172 return regexec(&pattern, slab, 0, NULL, 0);
1173}
1174
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001175static void read_slab_dir(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001176{
1177 DIR *dir;
1178 struct dirent *de;
1179 struct slabinfo *slab = slabinfo;
1180 struct aliasinfo *alias = aliasinfo;
1181 char *p;
1182 char *t;
1183 int count;
1184
Christoph Lameterb6c24de2008-02-04 23:35:48 -08001185 if (chdir("/sys/kernel/slab") && chdir("/sys/slab"))
Christoph Lametera87615b2007-05-09 02:32:37 -07001186 fatal("SYSFS support for SLUB not active\n");
1187
Christoph Lameterc09d8752007-05-06 14:49:48 -07001188 dir = opendir(".");
1189 while ((de = readdir(dir))) {
1190 if (de->d_name[0] == '.' ||
Christoph Lametera87615b2007-05-09 02:32:37 -07001191 (de->d_name[0] != ':' && slab_mismatch(de->d_name)))
1192 continue;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001193 switch (de->d_type) {
1194 case DT_LNK:
Christoph Lameter0d24db32010-10-21 13:01:56 -05001195 alias->name = strdup(de->d_name);
Thomas Jaroschfe353172011-10-17 16:48:10 +02001196 count = readlink(de->d_name, buffer, sizeof(buffer)-1);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001197
1198 if (count < 0)
1199 fatal("Cannot read symlink %s\n", de->d_name);
1200
1201 buffer[count] = 0;
1202 p = buffer + count;
1203 while (p > buffer && p[-1] != '/')
1204 p--;
1205 alias->ref = strdup(p);
1206 alias++;
1207 break;
1208 case DT_DIR:
1209 if (chdir(de->d_name))
1210 fatal("Unable to access slab %s\n", slab->name);
Christoph Lameter0d24db32010-10-21 13:01:56 -05001211 slab->name = strdup(de->d_name);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001212 slab->alias = 0;
1213 slab->refs = 0;
1214 slab->aliases = get_obj("aliases");
1215 slab->align = get_obj("align");
1216 slab->cache_dma = get_obj("cache_dma");
1217 slab->cpu_slabs = get_obj("cpu_slabs");
1218 slab->destroy_by_rcu = get_obj("destroy_by_rcu");
1219 slab->hwcache_align = get_obj("hwcache_align");
1220 slab->object_size = get_obj("object_size");
1221 slab->objects = get_obj("objects");
Christoph Lameter205ab992008-04-14 19:11:40 +03001222 slab->objects_partial = get_obj("objects_partial");
1223 slab->objects_total = get_obj("objects_total");
Christoph Lameterc09d8752007-05-06 14:49:48 -07001224 slab->objs_per_slab = get_obj("objs_per_slab");
1225 slab->order = get_obj("order");
1226 slab->partial = get_obj("partial");
1227 slab->partial = get_obj_and_str("partial", &t);
1228 decode_numa_list(slab->numa_partial, t);
WANG Congf32143a2007-10-16 23:31:29 -07001229 free(t);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001230 slab->poison = get_obj("poison");
1231 slab->reclaim_account = get_obj("reclaim_account");
1232 slab->red_zone = get_obj("red_zone");
1233 slab->sanity_checks = get_obj("sanity_checks");
1234 slab->slab_size = get_obj("slab_size");
1235 slab->slabs = get_obj_and_str("slabs", &t);
1236 decode_numa_list(slab->numa, t);
WANG Congf32143a2007-10-16 23:31:29 -07001237 free(t);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001238 slab->store_user = get_obj("store_user");
1239 slab->trace = get_obj("trace");
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001240 slab->alloc_fastpath = get_obj("alloc_fastpath");
1241 slab->alloc_slowpath = get_obj("alloc_slowpath");
1242 slab->free_fastpath = get_obj("free_fastpath");
1243 slab->free_slowpath = get_obj("free_slowpath");
1244 slab->free_frozen= get_obj("free_frozen");
1245 slab->free_add_partial = get_obj("free_add_partial");
1246 slab->free_remove_partial = get_obj("free_remove_partial");
1247 slab->alloc_from_partial = get_obj("alloc_from_partial");
1248 slab->alloc_slab = get_obj("alloc_slab");
1249 slab->alloc_refill = get_obj("alloc_refill");
1250 slab->free_slab = get_obj("free_slab");
1251 slab->cpuslab_flush = get_obj("cpuslab_flush");
1252 slab->deactivate_full = get_obj("deactivate_full");
1253 slab->deactivate_empty = get_obj("deactivate_empty");
1254 slab->deactivate_to_head = get_obj("deactivate_to_head");
1255 slab->deactivate_to_tail = get_obj("deactivate_to_tail");
1256 slab->deactivate_remote_frees = get_obj("deactivate_remote_frees");
Christoph Lameterf715e6f2008-04-29 16:14:46 -07001257 slab->order_fallback = get_obj("order_fallback");
Christoph Lameter9da47142011-06-01 12:26:00 -05001258 slab->cmpxchg_double_cpu_fail = get_obj("cmpxchg_double_cpu_fail");
1259 slab->cmpxchg_double_fail = get_obj("cmpxchg_double_fail");
Christoph Lameteraca726a2011-08-09 16:12:28 -05001260 slab->cpu_partial_alloc = get_obj("cpu_partial_alloc");
1261 slab->cpu_partial_free = get_obj("cpu_partial_free");
Christoph Lameter9da47142011-06-01 12:26:00 -05001262 slab->alloc_node_mismatch = get_obj("alloc_node_mismatch");
1263 slab->deactivate_bypass = get_obj("deactivate_bypass");
Christoph Lameterc09d8752007-05-06 14:49:48 -07001264 chdir("..");
1265 if (slab->name[0] == ':')
1266 alias_targets++;
1267 slab++;
1268 break;
1269 default :
1270 fatal("Unknown file type %lx\n", de->d_type);
1271 }
1272 }
1273 closedir(dir);
1274 slabs = slab - slabinfo;
Christoph Lametera87615b2007-05-09 02:32:37 -07001275 actual_slabs = slabs;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001276 aliases = alias - aliasinfo;
1277 if (slabs > MAX_SLABS)
1278 fatal("Too many slabs\n");
1279 if (aliases > MAX_ALIASES)
1280 fatal("Too many aliases\n");
1281}
1282
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -07001283static void output_slabs(void)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001284{
1285 struct slabinfo *slab;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001286 int lines = output_lines;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001287
Sergey Senozhatsky4980a962015-11-05 18:45:20 -08001288 for (slab = slabinfo; (slab < slabinfo + slabs) &&
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001289 lines != 0; slab++) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001290
1291 if (slab->alias)
1292 continue;
1293
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001294 if (lines != -1)
1295 lines--;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001296
1297 if (show_numa)
Christoph Lametera87615b2007-05-09 02:32:37 -07001298 slab_numa(slab, 0);
1299 else if (show_track)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001300 show_tracking(slab);
Christoph Lametera87615b2007-05-09 02:32:37 -07001301 else if (validate)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001302 slab_validate(slab);
Christoph Lametera87615b2007-05-09 02:32:37 -07001303 else if (shrink)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001304 slab_shrink(slab);
Christoph Lametera87615b2007-05-09 02:32:37 -07001305 else if (set_debug)
1306 slab_debug(slab);
1307 else if (show_ops)
1308 ops(slab);
1309 else if (show_slab)
1310 slabcache(slab);
Christoph Lametereefaca92007-05-16 22:10:55 -07001311 else if (show_report)
1312 report(slab);
Christoph Lameterc09d8752007-05-06 14:49:48 -07001313 }
1314}
1315
Tobin C. Harding1106b202019-07-11 20:59:38 -07001316static void _xtotals(char *heading, char *underline,
1317 int loss, int size, int partial)
1318{
1319 printf("%s%s", heading, underline);
1320 line = 0;
1321 sort_loss = loss;
1322 sort_size = size;
1323 sort_partial = partial;
1324 sort_slabs();
1325 output_slabs();
1326}
1327
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001328static void xtotals(void)
1329{
Tobin C. Harding1106b202019-07-11 20:59:38 -07001330 char *heading, *underline;
1331
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001332 totals();
1333
1334 link_slabs();
1335 rename_slabs();
1336
Tobin C. Harding1106b202019-07-11 20:59:38 -07001337 heading = "\nSlabs sorted by size\n";
1338 underline = "--------------------\n";
1339 _xtotals(heading, underline, 0, 1, 0);
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001340
Tobin C. Harding1106b202019-07-11 20:59:38 -07001341 heading = "\nSlabs sorted by loss\n";
1342 underline = "--------------------\n";
1343 _xtotals(heading, underline, 1, 0, 0);
1344
1345 heading = "\nSlabs sorted by number of partial slabs\n";
1346 underline = "---------------------------------------\n";
1347 _xtotals(heading, underline, 0, 0, 1);
1348
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001349 printf("\n");
1350}
1351
Christoph Lameterc09d8752007-05-06 14:49:48 -07001352struct option opts[] = {
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001353 { "aliases", no_argument, NULL, 'a' },
1354 { "activity", no_argument, NULL, 'A' },
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001355 { "Bytes", no_argument, NULL, 'B'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001356 { "debug", optional_argument, NULL, 'd' },
1357 { "display-activity", no_argument, NULL, 'D' },
1358 { "empty", no_argument, NULL, 'e' },
1359 { "first-alias", no_argument, NULL, 'f' },
1360 { "help", no_argument, NULL, 'h' },
1361 { "inverted", no_argument, NULL, 'i'},
Sergey Senozhatsky0d00bf52015-11-05 18:45:25 -08001362 { "slabs", no_argument, NULL, 'l' },
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001363 { "Loss", no_argument, NULL, 'L'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001364 { "numa", no_argument, NULL, 'n' },
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001365 { "lines", required_argument, NULL, 'N'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001366 { "ops", no_argument, NULL, 'o' },
Tobin C. Harding53a83f92019-07-11 20:59:42 -07001367 { "partial", no_argument, NULL, 'p'},
Sergey Senozhatsky0d00bf52015-11-05 18:45:25 -08001368 { "report", no_argument, NULL, 'r' },
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001369 { "shrink", no_argument, NULL, 's' },
Sergey Senozhatsky0d00bf52015-11-05 18:45:25 -08001370 { "Size", no_argument, NULL, 'S'},
1371 { "tracking", no_argument, NULL, 't'},
1372 { "Totals", no_argument, NULL, 'T'},
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001373 { "Unreclaim", no_argument, NULL, 'U'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001374 { "validate", no_argument, NULL, 'v' },
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001375 { "Xtotals", no_argument, NULL, 'X'},
Sergey Senozhatsky2b100752015-11-05 18:45:17 -08001376 { "zero", no_argument, NULL, 'z' },
1377 { "1ref", no_argument, NULL, '1'},
Christoph Lameterc09d8752007-05-06 14:49:48 -07001378 { NULL, 0, NULL, 0 }
1379};
1380
1381int main(int argc, char *argv[])
1382{
1383 int c;
1384 int err;
1385 char *pattern_source;
1386
1387 page_size = getpagesize();
Christoph Lameterc09d8752007-05-06 14:49:48 -07001388
Tobin C. Harding53a83f92019-07-11 20:59:42 -07001389 while ((c = getopt_long(argc, argv, "aABd::DefhilLnN:oPrsStTUvXz1",
Christoph Lametera87615b2007-05-09 02:32:37 -07001390 opts, NULL)) != -1)
WANG Congf32143a2007-10-16 23:31:29 -07001391 switch (c) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001392 case 'a':
1393 show_alias = 1;
1394 break;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001395 case 'A':
1396 sort_active = 1;
1397 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001398 case 'B':
1399 show_bytes = 1;
1400 break;
Christoph Lametera87615b2007-05-09 02:32:37 -07001401 case 'd':
1402 set_debug = 1;
1403 if (!debug_opt_scan(optarg))
1404 fatal("Invalid debug option '%s'\n", optarg);
1405 break;
Christoph Lameter8ff12cf2008-02-07 17:47:41 -08001406 case 'D':
1407 show_activity = 1;
1408 break;
Christoph Lametera87615b2007-05-09 02:32:37 -07001409 case 'e':
1410 show_empty = 1;
1411 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001412 case 'f':
1413 show_first_alias = 1;
1414 break;
1415 case 'h':
1416 usage();
1417 return 0;
1418 case 'i':
1419 show_inverted = 1;
1420 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001421 case 'l':
1422 show_slab = 1;
1423 break;
1424 case 'L':
1425 sort_loss = 1;
1426 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001427 case 'n':
1428 show_numa = 1;
1429 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001430 case 'N':
1431 if (optarg) {
1432 output_lines = atoi(optarg);
1433 if (output_lines < 1)
1434 output_lines = 1;
1435 }
1436 break;
Christoph Lametera87615b2007-05-09 02:32:37 -07001437 case 'o':
1438 show_ops = 1;
1439 break;
1440 case 'r':
1441 show_report = 1;
1442 break;
Tobin C. Harding53a83f92019-07-11 20:59:42 -07001443 case 'P':
1444 sort_partial = 1;
1445 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001446 case 's':
1447 shrink = 1;
1448 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001449 case 'S':
1450 sort_size = 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001451 break;
1452 case 't':
1453 show_track = 1;
1454 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001455 case 'T':
1456 show_totals = 1;
1457 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001458 case 'U':
1459 unreclaim_only = 1;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001460 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001461 case 'v':
1462 validate = 1;
Sergey Senozhatsky2651f6e2015-11-05 18:45:22 -08001463 break;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001464 case 'X':
1465 if (output_lines == -1)
1466 output_lines = 1;
1467 extended_totals = 1;
Sergey Senozhatskya8ea0bf2015-11-05 18:45:31 -08001468 show_bytes = 1;
1469 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001470 case 'z':
1471 skip_zero = 0;
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001472 break;
Tobin C. Hardingd9149992019-07-11 20:59:34 -07001473 case '1':
1474 show_single_ref = 1;
Yang Shi7ad3f182017-11-15 17:31:59 -08001475 break;
Christoph Lameterc09d8752007-05-06 14:49:48 -07001476 default:
1477 fatal("%s: Invalid option '%c'\n", argv[0], optopt);
1478
1479 }
1480
Christoph Lametera87615b2007-05-09 02:32:37 -07001481 if (!show_slab && !show_alias && !show_track && !show_report
1482 && !validate && !shrink && !set_debug && !show_ops)
Christoph Lameterc09d8752007-05-06 14:49:48 -07001483 show_slab = 1;
1484
1485 if (argc > optind)
1486 pattern_source = argv[optind];
1487 else
1488 pattern_source = ".*";
1489
1490 err = regcomp(&pattern, pattern_source, REG_ICASE|REG_NOSUB);
1491 if (err)
1492 fatal("%s: Invalid pattern '%s' code %d\n",
1493 argv[0], pattern_source, err);
1494 read_slab_dir();
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001495 if (show_alias) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001496 alias();
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001497 } else if (extended_totals) {
1498 xtotals();
1499 } else if (show_totals) {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001500 totals();
Sergey Senozhatsky016c6cd2015-11-05 18:45:28 -08001501 } else {
Christoph Lameterc09d8752007-05-06 14:49:48 -07001502 link_slabs();
1503 rename_slabs();
1504 sort_slabs();
1505 output_slabs();
1506 }
1507 return 0;
1508}