2 * Slabinfo: Tool to get reports about slabs
4 * (C) 2007 sgi, Christoph Lameter <clameter@sgi.com>
8 * gcc -o slabinfo slabinfo.c
12 #include <sys/types.h>
23 #define MAX_ALIASES 500
24 #define MAX_NODES 1024
30 int aliases, align, cache_dma, cpu_slabs, destroy_by_rcu;
31 int hwcache_align, object_size, objs_per_slab;
32 int sanity_checks, slab_size, store_user, trace;
33 int order, poison, reclaim_account, red_zone;
34 unsigned long partial, objects, slabs, objects_partial, objects_total;
35 unsigned long alloc_fastpath, alloc_slowpath;
36 unsigned long free_fastpath, free_slowpath;
37 unsigned long free_frozen, free_add_partial, free_remove_partial;
38 unsigned long alloc_from_partial, alloc_slab, free_slab, alloc_refill;
39 unsigned long cpuslab_flush, deactivate_full, deactivate_empty;
40 unsigned long deactivate_to_head, deactivate_to_tail;
41 unsigned long deactivate_remote_frees;
43 int numa_partial[MAX_NODES];
44 } slabinfo[MAX_SLABS];
49 struct slabinfo *slab;
50 } aliasinfo[MAX_ALIASES];
55 int alias_targets = 0;
67 int show_first_alias = 0;
70 int show_inverted = 0;
71 int show_single_ref = 0;
77 int show_activity = 0;
90 void fatal(const char *x, ...)
95 vfprintf(stderr, x, ap);
102 printf("slabinfo 5/7/2007. (c) 2007 sgi. clameter@sgi.com\n\n"
103 "slabinfo [-ahnpvtsz] [-d debugopts] [slab-regexp]\n"
104 "-a|--aliases Show aliases\n"
105 "-A|--activity Most active slabs first\n"
106 "-d<options>|--debug=<options> Set/Clear Debug options\n"
107 "-D|--display-active Switch line format to activity\n"
108 "-e|--empty Show empty slabs\n"
109 "-f|--first-alias Show first alias\n"
110 "-h|--help Show usage information\n"
111 "-i|--inverted Inverted list\n"
112 "-l|--slabs Show slabs\n"
113 "-n|--numa Show NUMA information\n"
114 "-o|--ops Show kmem_cache_ops\n"
115 "-s|--shrink Shrink slabs\n"
116 "-r|--report Detailed report on single slabs\n"
117 "-S|--Size Sort by size\n"
118 "-t|--tracking Show alloc/free information\n"
119 "-T|--Totals Show summary information\n"
120 "-v|--validate Validate slabs\n"
121 "-z|--zero Include empty slabs\n"
122 "-1|--1ref Single reference\n"
123 "\nValid debug options (FZPUT may be combined)\n"
124 "a / A Switch on all debug options (=FZUP)\n"
125 "- Switch off all debug options\n"
126 "f / F Sanity Checks (SLAB_DEBUG_FREE)\n"
134 unsigned long read_obj(const char *name)
136 FILE *f = fopen(name, "r");
141 if (!fgets(buffer, sizeof(buffer), f))
144 if (buffer[strlen(buffer)] == '\n')
145 buffer[strlen(buffer)] = 0;
147 return strlen(buffer);
152 * Get the contents of an attribute
154 unsigned long get_obj(const char *name)
162 unsigned long get_obj_and_str(const char *name, char **x)
164 unsigned long result = 0;
169 if (!read_obj(name)) {
173 result = strtoul(buffer, &p, 10);
181 void set_obj(struct slabinfo *s, const char *name, int n)
186 snprintf(x, 100, "%s/%s", s->name, name);
189 fatal("Cannot write to %s\n", x);
191 fprintf(f, "%d\n", n);
195 unsigned long read_slab_obj(struct slabinfo *s, const char *name)
201 snprintf(x, 100, "%s/%s", s->name, name);
207 l = fread(buffer, 1, sizeof(buffer), f);
216 * Put a size string together
218 int store_size(char *buffer, unsigned long value)
220 unsigned long divisor = 1;
224 if (value > 1000000000UL) {
225 divisor = 100000000UL;
227 } else if (value > 1000000UL) {
230 } else if (value > 1000UL) {
236 n = sprintf(buffer, "%ld",value);
243 memmove(buffer + n - 2, buffer + n - 3, 4);
250 void decode_numa_list(int *numa, char *t)
255 memset(numa, 0, MAX_NODES * sizeof(int));
262 node = strtoul(t, &t, 10);
265 nr = strtoul(t, &t, 10);
267 if (node > highest_node)
275 void slab_validate(struct slabinfo *s)
277 if (strcmp(s->name, "*") == 0)
280 set_obj(s, "validate", 1);
283 void slab_shrink(struct slabinfo *s)
285 if (strcmp(s->name, "*") == 0)
288 set_obj(s, "shrink", 1);
293 void first_line(void)
296 printf("Name Objects Alloc Free %%Fast\n");
298 printf("Name Objects Objsize Space "
299 "Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n");
303 * Find the shortest alias of a slab
305 struct aliasinfo *find_one_alias(struct slabinfo *find)
308 struct aliasinfo *best = NULL;
310 for(a = aliasinfo;a < aliasinfo + aliases; a++) {
311 if (a->slab == find &&
312 (!best || strlen(best->name) < strlen(a->name))) {
314 if (strncmp(a->name,"kmall", 5) == 0)
321 unsigned long slab_size(struct slabinfo *s)
323 return s->slabs * (page_size << s->order);
326 unsigned long slab_activity(struct slabinfo *s)
328 return s->alloc_fastpath + s->free_fastpath +
329 s->alloc_slowpath + s->free_slowpath;
332 void slab_numa(struct slabinfo *s, int mode)
336 if (strcmp(s->name, "*") == 0)
340 printf("\n%s: No NUMA information available.\n", s->name);
344 if (skip_zero && !s->slabs)
348 printf("\n%-21s:", mode ? "NUMA nodes" : "Slab");
349 for(node = 0; node <= highest_node; node++)
350 printf(" %4d", node);
351 printf("\n----------------------");
352 for(node = 0; node <= highest_node; node++)
356 printf("%-21s ", mode ? "All slabs" : s->name);
357 for(node = 0; node <= highest_node; node++) {
360 store_size(b, s->numa[node]);
365 printf("%-21s ", "Partial slabs");
366 for(node = 0; node <= highest_node; node++) {
369 store_size(b, s->numa_partial[node]);
377 void show_tracking(struct slabinfo *s)
379 printf("\n%s: Kernel object allocation\n", s->name);
380 printf("-----------------------------------------------------------------------\n");
381 if (read_slab_obj(s, "alloc_calls"))
386 printf("\n%s: Kernel object freeing\n", s->name);
387 printf("------------------------------------------------------------------------\n");
388 if (read_slab_obj(s, "free_calls"))
395 void ops(struct slabinfo *s)
397 if (strcmp(s->name, "*") == 0)
400 if (read_slab_obj(s, "ops")) {
401 printf("\n%s: kmem_cache operations\n", s->name);
402 printf("--------------------------------------------\n");
405 printf("\n%s has no kmem_cache operations\n", s->name);
408 const char *onoff(int x)
415 void slab_stats(struct slabinfo *s)
417 unsigned long total_alloc;
418 unsigned long total_free;
424 total_alloc = s->alloc_fastpath + s->alloc_slowpath;
425 total_free = s->free_fastpath + s->free_slowpath;
431 printf("Slab Perf Counter Alloc Free %%Al %%Fr\n");
432 printf("--------------------------------------------------\n");
433 printf("Fastpath %8lu %8lu %3lu %3lu\n",
434 s->alloc_fastpath, s->free_fastpath,
435 s->alloc_fastpath * 100 / total_alloc,
436 s->free_fastpath * 100 / total_free);
437 printf("Slowpath %8lu %8lu %3lu %3lu\n",
438 total_alloc - s->alloc_fastpath, s->free_slowpath,
439 (total_alloc - s->alloc_fastpath) * 100 / total_alloc,
440 s->free_slowpath * 100 / total_free);
441 printf("Page Alloc %8lu %8lu %3lu %3lu\n",
442 s->alloc_slab, s->free_slab,
443 s->alloc_slab * 100 / total_alloc,
444 s->free_slab * 100 / total_free);
445 printf("Add partial %8lu %8lu %3lu %3lu\n",
446 s->deactivate_to_head + s->deactivate_to_tail,
448 (s->deactivate_to_head + s->deactivate_to_tail) * 100 / total_alloc,
449 s->free_add_partial * 100 / total_free);
450 printf("Remove partial %8lu %8lu %3lu %3lu\n",
451 s->alloc_from_partial, s->free_remove_partial,
452 s->alloc_from_partial * 100 / total_alloc,
453 s->free_remove_partial * 100 / total_free);
455 printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n",
456 s->deactivate_remote_frees, s->free_frozen,
457 s->deactivate_remote_frees * 100 / total_alloc,
458 s->free_frozen * 100 / total_free);
460 printf("Total %8lu %8lu\n\n", total_alloc, total_free);
462 if (s->cpuslab_flush)
463 printf("Flushes %8lu\n", s->cpuslab_flush);
466 printf("Refill %8lu\n", s->alloc_refill);
468 total = s->deactivate_full + s->deactivate_empty +
469 s->deactivate_to_head + s->deactivate_to_tail;
472 printf("Deactivate Full=%lu(%lu%%) Empty=%lu(%lu%%) "
473 "ToHead=%lu(%lu%%) ToTail=%lu(%lu%%)\n",
474 s->deactivate_full, (s->deactivate_full * 100) / total,
475 s->deactivate_empty, (s->deactivate_empty * 100) / total,
476 s->deactivate_to_head, (s->deactivate_to_head * 100) / total,
477 s->deactivate_to_tail, (s->deactivate_to_tail * 100) / total);
480 void report(struct slabinfo *s)
482 if (strcmp(s->name, "*") == 0)
485 printf("\nSlabcache: %-20s Aliases: %2d Order : %2d Objects: %lu\n",
486 s->name, s->aliases, s->order, s->objects);
487 if (s->hwcache_align)
488 printf("** Hardware cacheline aligned\n");
490 printf("** Memory is allocated in a special DMA zone\n");
491 if (s->destroy_by_rcu)
492 printf("** Slabs are destroyed via RCU\n");
493 if (s->reclaim_account)
494 printf("** Reclaim accounting active\n");
496 printf("\nSizes (bytes) Slabs Debug Memory\n");
497 printf("------------------------------------------------------------------------\n");
498 printf("Object : %7d Total : %7ld Sanity Checks : %s Total: %7ld\n",
499 s->object_size, s->slabs, onoff(s->sanity_checks),
500 s->slabs * (page_size << s->order));
501 printf("SlabObj: %7d Full : %7ld Redzoning : %s Used : %7ld\n",
502 s->slab_size, s->slabs - s->partial - s->cpu_slabs,
503 onoff(s->red_zone), s->objects * s->object_size);
504 printf("SlabSiz: %7d Partial: %7ld Poisoning : %s Loss : %7ld\n",
505 page_size << s->order, s->partial, onoff(s->poison),
506 s->slabs * (page_size << s->order) - s->objects * s->object_size);
507 printf("Loss : %7d CpuSlab: %7d Tracking : %s Lalig: %7ld\n",
508 s->slab_size - s->object_size, s->cpu_slabs, onoff(s->store_user),
509 (s->slab_size - s->object_size) * s->objects);
510 printf("Align : %7d Objects: %7d Tracing : %s Lpadd: %7ld\n",
511 s->align, s->objs_per_slab, onoff(s->trace),
512 ((page_size << s->order) - s->objs_per_slab * s->slab_size) *
521 void slabcache(struct slabinfo *s)
528 if (strcmp(s->name, "*") == 0)
531 if (actual_slabs == 1) {
536 if (skip_zero && !show_empty && !s->slabs)
539 if (show_empty && s->slabs)
542 store_size(size_str, slab_size(s));
543 snprintf(dist_str, 40, "%lu/%lu/%d", s->slabs - s->cpu_slabs,
544 s->partial, s->cpu_slabs);
553 if (s->hwcache_align)
557 if (s->reclaim_account)
561 if (s->sanity_checks)
570 unsigned long total_alloc;
571 unsigned long total_free;
573 total_alloc = s->alloc_fastpath + s->alloc_slowpath;
574 total_free = s->free_fastpath + s->free_slowpath;
576 printf("%-21s %8ld %8ld %8ld %3ld %3ld \n",
578 total_alloc, total_free,
579 total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0,
580 total_free ? (s->free_fastpath * 100 / total_free) : 0);
583 printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n",
584 s->name, s->objects, s->object_size, size_str, dist_str,
585 s->objs_per_slab, s->order,
586 s->slabs ? (s->partial * 100) / s->slabs : 100,
587 s->slabs ? (s->objects * s->object_size * 100) /
588 (s->slabs * (page_size << s->order)) : 100,
593 * Analyze debug options. Return false if something is amiss.
595 int debug_opt_scan(char *opt)
597 if (!opt || !opt[0] || strcmp(opt, "-") == 0)
600 if (strcasecmp(opt, "a") == 0) {
644 int slab_empty(struct slabinfo *s)
650 * We may still have slabs even if there are no objects. Shrinking will
654 set_obj(s, "shrink", 1);
659 void slab_debug(struct slabinfo *s)
661 if (strcmp(s->name, "*") == 0)
664 if (sanity && !s->sanity_checks) {
665 set_obj(s, "sanity", 1);
667 if (!sanity && s->sanity_checks) {
669 set_obj(s, "sanity", 0);
671 fprintf(stderr, "%s not empty cannot disable sanity checks\n", s->name);
673 if (redzone && !s->red_zone) {
675 set_obj(s, "red_zone", 1);
677 fprintf(stderr, "%s not empty cannot enable redzoning\n", s->name);
679 if (!redzone && s->red_zone) {
681 set_obj(s, "red_zone", 0);
683 fprintf(stderr, "%s not empty cannot disable redzoning\n", s->name);
685 if (poison && !s->poison) {
687 set_obj(s, "poison", 1);
689 fprintf(stderr, "%s not empty cannot enable poisoning\n", s->name);
691 if (!poison && s->poison) {
693 set_obj(s, "poison", 0);
695 fprintf(stderr, "%s not empty cannot disable poisoning\n", s->name);
697 if (tracking && !s->store_user) {
699 set_obj(s, "store_user", 1);
701 fprintf(stderr, "%s not empty cannot enable tracking\n", s->name);
703 if (!tracking && s->store_user) {
705 set_obj(s, "store_user", 0);
707 fprintf(stderr, "%s not empty cannot disable tracking\n", s->name);
709 if (tracing && !s->trace) {
711 set_obj(s, "trace", 1);
713 fprintf(stderr, "%s can only enable trace for one slab at a time\n", s->name);
715 if (!tracing && s->trace)
716 set_obj(s, "trace", 1);
724 char b1[20], b2[20], b3[20], b4[20];
725 unsigned long long max = 1ULL << 63;
728 unsigned long long min_objsize = max, max_objsize = 0, avg_objsize;
730 /* Number of partial slabs in a slabcache */
731 unsigned long long min_partial = max, max_partial = 0,
732 avg_partial, total_partial = 0;
734 /* Number of slabs in a slab cache */
735 unsigned long long min_slabs = max, max_slabs = 0,
736 avg_slabs, total_slabs = 0;
738 /* Size of the whole slab */
739 unsigned long long min_size = max, max_size = 0,
740 avg_size, total_size = 0;
742 /* Bytes used for object storage in a slab */
743 unsigned long long min_used = max, max_used = 0,
744 avg_used, total_used = 0;
746 /* Waste: Bytes used for alignment and padding */
747 unsigned long long min_waste = max, max_waste = 0,
748 avg_waste, total_waste = 0;
749 /* Number of objects in a slab */
750 unsigned long long min_objects = max, max_objects = 0,
751 avg_objects, total_objects = 0;
752 /* Waste per object */
753 unsigned long long min_objwaste = max,
754 max_objwaste = 0, avg_objwaste,
757 /* Memory per object */
758 unsigned long long min_memobj = max,
759 max_memobj = 0, avg_memobj,
762 /* Percentage of partial slabs per slab */
763 unsigned long min_ppart = 100, max_ppart = 0,
764 avg_ppart, total_ppart = 0;
766 /* Number of objects in partial slabs */
767 unsigned long min_partobj = max, max_partobj = 0,
768 avg_partobj, total_partobj = 0;
770 /* Percentage of partial objects of all objects in a slab */
771 unsigned long min_ppartobj = 100, max_ppartobj = 0,
772 avg_ppartobj, total_ppartobj = 0;
775 for (s = slabinfo; s < slabinfo + slabs; s++) {
776 unsigned long long size;
778 unsigned long long wasted;
779 unsigned long long objwaste;
780 unsigned long percentage_partial_slabs;
781 unsigned long percentage_partial_objs;
783 if (!s->slabs || !s->objects)
789 used = s->objects * s->object_size;
790 wasted = size - used;
791 objwaste = s->slab_size - s->object_size;
793 percentage_partial_slabs = s->partial * 100 / s->slabs;
794 if (percentage_partial_slabs > 100)
795 percentage_partial_slabs = 100;
797 percentage_partial_objs = s->objects_partial * 100
800 if (percentage_partial_objs > 100)
801 percentage_partial_objs = 100;
803 if (s->object_size < min_objsize)
804 min_objsize = s->object_size;
805 if (s->partial < min_partial)
806 min_partial = s->partial;
807 if (s->slabs < min_slabs)
808 min_slabs = s->slabs;
811 if (wasted < min_waste)
813 if (objwaste < min_objwaste)
814 min_objwaste = objwaste;
815 if (s->objects < min_objects)
816 min_objects = s->objects;
819 if (s->objects_partial < min_partobj)
820 min_partobj = s->objects_partial;
821 if (percentage_partial_slabs < min_ppart)
822 min_ppart = percentage_partial_slabs;
823 if (percentage_partial_objs < min_ppartobj)
824 min_ppartobj = percentage_partial_objs;
825 if (s->slab_size < min_memobj)
826 min_memobj = s->slab_size;
828 if (s->object_size > max_objsize)
829 max_objsize = s->object_size;
830 if (s->partial > max_partial)
831 max_partial = s->partial;
832 if (s->slabs > max_slabs)
833 max_slabs = s->slabs;
836 if (wasted > max_waste)
838 if (objwaste > max_objwaste)
839 max_objwaste = objwaste;
840 if (s->objects > max_objects)
841 max_objects = s->objects;
844 if (s->objects_partial > max_partobj)
845 max_partobj = s->objects_partial;
846 if (percentage_partial_slabs > max_ppart)
847 max_ppart = percentage_partial_slabs;
848 if (percentage_partial_objs > max_ppartobj)
849 max_ppartobj = percentage_partial_objs;
850 if (s->slab_size > max_memobj)
851 max_memobj = s->slab_size;
853 total_partial += s->partial;
854 total_slabs += s->slabs;
856 total_waste += wasted;
858 total_objects += s->objects;
860 total_partobj += s->objects_partial;
861 total_ppart += percentage_partial_slabs;
862 total_ppartobj += percentage_partial_objs;
864 total_objwaste += s->objects * objwaste;
865 total_objsize += s->objects * s->slab_size;
868 if (!total_objects) {
869 printf("No objects\n");
873 printf("No slabs\n");
877 /* Per slab averages */
878 avg_partial = total_partial / used_slabs;
879 avg_slabs = total_slabs / used_slabs;
880 avg_size = total_size / used_slabs;
881 avg_waste = total_waste / used_slabs;
883 avg_objects = total_objects / used_slabs;
884 avg_used = total_used / used_slabs;
885 avg_partobj = total_partobj / used_slabs;
886 avg_ppart = total_ppart / used_slabs;
887 avg_ppartobj = total_ppartobj / used_slabs;
889 /* Per object object sizes */
890 avg_objsize = total_used / total_objects;
891 avg_objwaste = total_objwaste / total_objects;
892 avg_partobj = total_partobj * 100 / total_objects;
893 avg_memobj = total_objsize / total_objects;
895 printf("Slabcache Totals\n");
896 printf("----------------\n");
897 printf("Slabcaches : %3d Aliases : %3d->%-3d Active: %3d\n",
898 slabs, aliases, alias_targets, used_slabs);
900 store_size(b1, total_size);store_size(b2, total_waste);
901 store_size(b3, total_waste * 100 / total_used);
902 printf("Memory used: %6s # Loss : %6s MRatio:%6s%%\n", b1, b2, b3);
904 store_size(b1, total_objects);store_size(b2, total_partobj);
905 store_size(b3, total_partobj * 100 / total_objects);
906 printf("# Objects : %6s # PartObj: %6s ORatio:%6s%%\n", b1, b2, b3);
909 printf("Per Cache Average Min Max Total\n");
910 printf("---------------------------------------------------------\n");
912 store_size(b1, avg_objects);store_size(b2, min_objects);
913 store_size(b3, max_objects);store_size(b4, total_objects);
914 printf("#Objects %10s %10s %10s %10s\n",
917 store_size(b1, avg_slabs);store_size(b2, min_slabs);
918 store_size(b3, max_slabs);store_size(b4, total_slabs);
919 printf("#Slabs %10s %10s %10s %10s\n",
922 store_size(b1, avg_partial);store_size(b2, min_partial);
923 store_size(b3, max_partial);store_size(b4, total_partial);
924 printf("#PartSlab %10s %10s %10s %10s\n",
926 store_size(b1, avg_ppart);store_size(b2, min_ppart);
927 store_size(b3, max_ppart);
928 store_size(b4, total_partial * 100 / total_slabs);
929 printf("%%PartSlab%10s%% %10s%% %10s%% %10s%%\n",
932 store_size(b1, avg_partobj);store_size(b2, min_partobj);
933 store_size(b3, max_partobj);
934 store_size(b4, total_partobj);
935 printf("PartObjs %10s %10s %10s %10s\n",
938 store_size(b1, avg_ppartobj);store_size(b2, min_ppartobj);
939 store_size(b3, max_ppartobj);
940 store_size(b4, total_partobj * 100 / total_objects);
941 printf("%% PartObj%10s%% %10s%% %10s%% %10s%%\n",
944 store_size(b1, avg_size);store_size(b2, min_size);
945 store_size(b3, max_size);store_size(b4, total_size);
946 printf("Memory %10s %10s %10s %10s\n",
949 store_size(b1, avg_used);store_size(b2, min_used);
950 store_size(b3, max_used);store_size(b4, total_used);
951 printf("Used %10s %10s %10s %10s\n",
954 store_size(b1, avg_waste);store_size(b2, min_waste);
955 store_size(b3, max_waste);store_size(b4, total_waste);
956 printf("Loss %10s %10s %10s %10s\n",
960 printf("Per Object Average Min Max\n");
961 printf("---------------------------------------------\n");
963 store_size(b1, avg_memobj);store_size(b2, min_memobj);
964 store_size(b3, max_memobj);
965 printf("Memory %10s %10s %10s\n",
967 store_size(b1, avg_objsize);store_size(b2, min_objsize);
968 store_size(b3, max_objsize);
969 printf("User %10s %10s %10s\n",
972 store_size(b1, avg_objwaste);store_size(b2, min_objwaste);
973 store_size(b3, max_objwaste);
974 printf("Loss %10s %10s %10s\n",
978 void sort_slabs(void)
980 struct slabinfo *s1,*s2;
982 for (s1 = slabinfo; s1 < slabinfo + slabs; s1++) {
983 for (s2 = s1 + 1; s2 < slabinfo + slabs; s2++) {
987 result = slab_size(s1) < slab_size(s2);
988 else if (sort_active)
989 result = slab_activity(s1) < slab_activity(s2);
991 result = strcasecmp(s1->name, s2->name);
999 memcpy(&t, s1, sizeof(struct slabinfo));
1000 memcpy(s1, s2, sizeof(struct slabinfo));
1001 memcpy(s2, &t, sizeof(struct slabinfo));
1007 void sort_aliases(void)
1009 struct aliasinfo *a1,*a2;
1011 for (a1 = aliasinfo; a1 < aliasinfo + aliases; a1++) {
1012 for (a2 = a1 + 1; a2 < aliasinfo + aliases; a2++) {
1017 if (show_alias && !show_inverted) {
1021 if (strcasecmp(n1, n2) > 0) {
1024 memcpy(&t, a1, sizeof(struct aliasinfo));
1025 memcpy(a1, a2, sizeof(struct aliasinfo));
1026 memcpy(a2, &t, sizeof(struct aliasinfo));
1032 void link_slabs(void)
1034 struct aliasinfo *a;
1037 for (a = aliasinfo; a < aliasinfo + aliases; a++) {
1039 for (s = slabinfo; s < slabinfo + slabs; s++)
1040 if (strcmp(a->ref, s->name) == 0) {
1045 if (s == slabinfo + slabs)
1046 fatal("Unresolved alias %s\n", a->ref);
1052 struct aliasinfo *a;
1053 char *active = NULL;
1058 for(a = aliasinfo; a < aliasinfo + aliases; a++) {
1060 if (!show_single_ref && a->slab->refs == 1)
1063 if (!show_inverted) {
1065 if (strcmp(a->slab->name, active) == 0) {
1066 printf(" %s", a->name);
1070 printf("\n%-12s <- %s", a->slab->name, a->name);
1071 active = a->slab->name;
1074 printf("%-20s -> %s\n", a->name, a->slab->name);
1081 void rename_slabs(void)
1084 struct aliasinfo *a;
1086 for (s = slabinfo; s < slabinfo + slabs; s++) {
1087 if (*s->name != ':')
1090 if (s->refs > 1 && !show_first_alias)
1093 a = find_one_alias(s);
1104 int slab_mismatch(char *slab)
1106 return regexec(&pattern, slab, 0, NULL, 0);
1109 void read_slab_dir(void)
1113 struct slabinfo *slab = slabinfo;
1114 struct aliasinfo *alias = aliasinfo;
1119 if (chdir("/sys/kernel/slab") && chdir("/sys/slab"))
1120 fatal("SYSFS support for SLUB not active\n");
1123 while ((de = readdir(dir))) {
1124 if (de->d_name[0] == '.' ||
1125 (de->d_name[0] != ':' && slab_mismatch(de->d_name)))
1127 switch (de->d_type) {
1129 alias->name = strdup(de->d_name);
1130 count = readlink(de->d_name, buffer, sizeof(buffer));
1133 fatal("Cannot read symlink %s\n", de->d_name);
1137 while (p > buffer && p[-1] != '/')
1139 alias->ref = strdup(p);
1143 if (chdir(de->d_name))
1144 fatal("Unable to access slab %s\n", slab->name);
1145 slab->name = strdup(de->d_name);
1148 slab->aliases = get_obj("aliases");
1149 slab->align = get_obj("align");
1150 slab->cache_dma = get_obj("cache_dma");
1151 slab->cpu_slabs = get_obj("cpu_slabs");
1152 slab->destroy_by_rcu = get_obj("destroy_by_rcu");
1153 slab->hwcache_align = get_obj("hwcache_align");
1154 slab->object_size = get_obj("object_size");
1155 slab->objects = get_obj("objects");
1156 slab->objects_partial = get_obj("objects_partial");
1157 slab->objects_total = get_obj("objects_total");
1158 slab->objs_per_slab = get_obj("objs_per_slab");
1159 slab->order = get_obj("order");
1160 slab->partial = get_obj("partial");
1161 slab->partial = get_obj_and_str("partial", &t);
1162 decode_numa_list(slab->numa_partial, t);
1164 slab->poison = get_obj("poison");
1165 slab->reclaim_account = get_obj("reclaim_account");
1166 slab->red_zone = get_obj("red_zone");
1167 slab->sanity_checks = get_obj("sanity_checks");
1168 slab->slab_size = get_obj("slab_size");
1169 slab->slabs = get_obj_and_str("slabs", &t);
1170 decode_numa_list(slab->numa, t);
1172 slab->store_user = get_obj("store_user");
1173 slab->trace = get_obj("trace");
1174 slab->alloc_fastpath = get_obj("alloc_fastpath");
1175 slab->alloc_slowpath = get_obj("alloc_slowpath");
1176 slab->free_fastpath = get_obj("free_fastpath");
1177 slab->free_slowpath = get_obj("free_slowpath");
1178 slab->free_frozen= get_obj("free_frozen");
1179 slab->free_add_partial = get_obj("free_add_partial");
1180 slab->free_remove_partial = get_obj("free_remove_partial");
1181 slab->alloc_from_partial = get_obj("alloc_from_partial");
1182 slab->alloc_slab = get_obj("alloc_slab");
1183 slab->alloc_refill = get_obj("alloc_refill");
1184 slab->free_slab = get_obj("free_slab");
1185 slab->cpuslab_flush = get_obj("cpuslab_flush");
1186 slab->deactivate_full = get_obj("deactivate_full");
1187 slab->deactivate_empty = get_obj("deactivate_empty");
1188 slab->deactivate_to_head = get_obj("deactivate_to_head");
1189 slab->deactivate_to_tail = get_obj("deactivate_to_tail");
1190 slab->deactivate_remote_frees = get_obj("deactivate_remote_frees");
1192 if (slab->name[0] == ':')
1197 fatal("Unknown file type %lx\n", de->d_type);
1201 slabs = slab - slabinfo;
1202 actual_slabs = slabs;
1203 aliases = alias - aliasinfo;
1204 if (slabs > MAX_SLABS)
1205 fatal("Too many slabs\n");
1206 if (aliases > MAX_ALIASES)
1207 fatal("Too many aliases\n");
1210 void output_slabs(void)
1212 struct slabinfo *slab;
1214 for (slab = slabinfo; slab < slabinfo + slabs; slab++) {
1222 else if (show_track)
1223 show_tracking(slab);
1225 slab_validate(slab);
1234 else if (show_report)
1239 struct option opts[] = {
1240 { "aliases", 0, NULL, 'a' },
1241 { "activity", 0, NULL, 'A' },
1242 { "debug", 2, NULL, 'd' },
1243 { "display-activity", 0, NULL, 'D' },
1244 { "empty", 0, NULL, 'e' },
1245 { "first-alias", 0, NULL, 'f' },
1246 { "help", 0, NULL, 'h' },
1247 { "inverted", 0, NULL, 'i'},
1248 { "numa", 0, NULL, 'n' },
1249 { "ops", 0, NULL, 'o' },
1250 { "report", 0, NULL, 'r' },
1251 { "shrink", 0, NULL, 's' },
1252 { "slabs", 0, NULL, 'l' },
1253 { "track", 0, NULL, 't'},
1254 { "validate", 0, NULL, 'v' },
1255 { "zero", 0, NULL, 'z' },
1256 { "1ref", 0, NULL, '1'},
1257 { NULL, 0, NULL, 0 }
1260 int main(int argc, char *argv[])
1264 char *pattern_source;
1266 page_size = getpagesize();
1268 while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTS",
1272 show_single_ref = 1;
1282 if (!debug_opt_scan(optarg))
1283 fatal("Invalid debug option '%s'\n", optarg);
1292 show_first_alias = 1;
1332 fatal("%s: Invalid option '%c'\n", argv[0], optopt);
1336 if (!show_slab && !show_alias && !show_track && !show_report
1337 && !validate && !shrink && !set_debug && !show_ops)
1341 pattern_source = argv[optind];
1343 pattern_source = ".*";
1345 err = regcomp(&pattern, pattern_source, REG_ICASE|REG_NOSUB);
1347 fatal("%s: Invalid pattern '%s' code %d\n",
1348 argv[0], pattern_source, err);