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>
22 #define MAX_ALIASES 500
23 #define MAX_NODES 1024
29 int aliases
, align
, cache_dma
, cpu_slabs
, destroy_by_rcu
;
30 int hwcache_align
, object_size
, objs_per_slab
;
31 int sanity_checks
, slab_size
, store_user
, trace
;
32 int order
, poison
, reclaim_account
, red_zone
;
33 unsigned long partial
, objects
, slabs
;
35 int numa_partial
[MAX_NODES
];
36 } slabinfo
[MAX_SLABS
];
41 struct slabinfo
*slab
;
42 } aliasinfo
[MAX_ALIASES
];
47 int alias_targets
= 0;
59 int show_first_alias
= 0;
62 int show_inverted
= 0;
63 int show_single_ref
= 0;
80 void fatal(const char *x
, ...)
85 vfprintf(stderr
, x
, ap
);
92 printf("slabinfo 5/7/2007. (c) 2007 sgi. clameter@sgi.com\n\n"
93 "slabinfo [-ahnpvtsz] [-d debugopts] [slab-regexp]\n"
94 "-a|--aliases Show aliases\n"
95 "-d<options>|--debug=<options> Set/Clear Debug options\n"
96 "-e|--empty Show empty slabs\n"
97 "-f|--first-alias Show first alias\n"
98 "-h|--help Show usage information\n"
99 "-i|--inverted Inverted list\n"
100 "-l|--slabs Show slabs\n"
101 "-n|--numa Show NUMA information\n"
102 "-o|--ops Show kmem_cache_ops\n"
103 "-s|--shrink Shrink slabs\n"
104 "-r|--report Detailed report on single slabs\n"
105 "-S|--Size Sort by size\n"
106 "-t|--tracking Show alloc/free information\n"
107 "-T|--Totals Show summary information\n"
108 "-v|--validate Validate slabs\n"
109 "-z|--zero Include empty slabs\n"
110 "-1|--1ref Single reference\n"
111 "\nValid debug options (FZPUT may be combined)\n"
112 "a / A Switch on all debug options (=FZUP)\n"
113 "- Switch off all debug options\n"
114 "f / F Sanity Checks (SLAB_DEBUG_FREE)\n"
122 unsigned long read_obj(char *name
)
124 FILE *f
= fopen(name
, "r");
129 if (!fgets(buffer
,sizeof(buffer
), f
))
132 if (buffer
[strlen(buffer
)] == '\n')
133 buffer
[strlen(buffer
)] = 0;
135 return strlen(buffer
);
140 * Get the contents of an attribute
142 unsigned long get_obj(char *name
)
150 unsigned long get_obj_and_str(char *name
, char **x
)
152 unsigned long result
= 0;
157 if (!read_obj(name
)) {
161 result
= strtoul(buffer
, &p
, 10);
169 void set_obj(struct slabinfo
*s
, char *name
, int n
)
174 sprintf(x
, "%s/%s", s
->name
, name
);
177 fatal("Cannot write to %s\n", x
);
179 fprintf(f
, "%d\n", n
);
183 unsigned long read_slab_obj(struct slabinfo
*s
, char *name
)
189 sprintf(x
, "%s/%s", s
->name
, name
);
195 l
= fread(buffer
, 1, sizeof(buffer
), f
);
204 * Put a size string together
206 int store_size(char *buffer
, unsigned long value
)
208 unsigned long divisor
= 1;
212 if (value
> 1000000000UL) {
213 divisor
= 100000000UL;
215 } else if (value
> 1000000UL) {
218 } else if (value
> 1000UL) {
224 n
= sprintf(buffer
, "%ld",value
);
231 memmove(buffer
+ n
- 2, buffer
+ n
- 3, 4);
238 void decode_numa_list(int *numa
, char *t
)
243 memset(numa
, 0, MAX_NODES
* sizeof(int));
250 node
= strtoul(t
, &t
, 10);
253 nr
= strtoul(t
, &t
, 10);
255 if (node
> highest_node
)
263 void slab_validate(struct slabinfo
*s
)
265 if (strcmp(s
->name
, "*") == 0)
268 set_obj(s
, "validate", 1);
271 void slab_shrink(struct slabinfo
*s
)
273 if (strcmp(s
->name
, "*") == 0)
276 set_obj(s
, "shrink", 1);
281 void first_line(void)
283 printf("Name Objects Objsize Space "
284 "Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n");
288 * Find the shortest alias of a slab
290 struct aliasinfo
*find_one_alias(struct slabinfo
*find
)
293 struct aliasinfo
*best
= NULL
;
295 for(a
= aliasinfo
;a
< aliasinfo
+ aliases
; a
++) {
296 if (a
->slab
== find
&&
297 (!best
|| strlen(best
->name
) < strlen(a
->name
))) {
299 if (strncmp(a
->name
,"kmall", 5) == 0)
306 unsigned long slab_size(struct slabinfo
*s
)
308 return s
->slabs
* (page_size
<< s
->order
);
311 void slab_numa(struct slabinfo
*s
, int mode
)
315 if (strcmp(s
->name
, "*") == 0)
319 printf("\n%s: No NUMA information available.\n", s
->name
);
323 if (skip_zero
&& !s
->slabs
)
327 printf("\n%-21s:", mode
? "NUMA nodes" : "Slab");
328 for(node
= 0; node
<= highest_node
; node
++)
329 printf(" %4d", node
);
330 printf("\n----------------------");
331 for(node
= 0; node
<= highest_node
; node
++)
335 printf("%-21s ", mode
? "All slabs" : s
->name
);
336 for(node
= 0; node
<= highest_node
; node
++) {
339 store_size(b
, s
->numa
[node
]);
344 printf("%-21s ", "Partial slabs");
345 for(node
= 0; node
<= highest_node
; node
++) {
348 store_size(b
, s
->numa_partial
[node
]);
356 void show_tracking(struct slabinfo
*s
)
358 printf("\n%s: Kernel object allocation\n", s
->name
);
359 printf("-----------------------------------------------------------------------\n");
360 if (read_slab_obj(s
, "alloc_calls"))
365 printf("\n%s: Kernel object freeing\n", s
->name
);
366 printf("------------------------------------------------------------------------\n");
367 if (read_slab_obj(s
, "free_calls"))
374 void ops(struct slabinfo
*s
)
376 if (strcmp(s
->name
, "*") == 0)
379 if (read_slab_obj(s
, "ops")) {
380 printf("\n%s: kmem_cache operations\n", s
->name
);
381 printf("--------------------------------------------\n");
384 printf("\n%s has no kmem_cache operations\n", s
->name
);
387 const char *onoff(int x
)
394 void report(struct slabinfo
*s
)
396 if (strcmp(s
->name
, "*") == 0)
399 printf("\nSlabcache: %-20s Aliases: %2d Order : %2d Objects: %lu\n",
400 s
->name
, s
->aliases
, s
->order
, s
->objects
);
401 if (s
->hwcache_align
)
402 printf("** Hardware cacheline aligned\n");
404 printf("** Memory is allocated in a special DMA zone\n");
405 if (s
->destroy_by_rcu
)
406 printf("** Slabs are destroyed via RCU\n");
407 if (s
->reclaim_account
)
408 printf("** Reclaim accounting active\n");
410 printf("\nSizes (bytes) Slabs Debug Memory\n");
411 printf("------------------------------------------------------------------------\n");
412 printf("Object : %7d Total : %7ld Sanity Checks : %s Total: %7ld\n",
413 s
->object_size
, s
->slabs
, onoff(s
->sanity_checks
),
414 s
->slabs
* (page_size
<< s
->order
));
415 printf("SlabObj: %7d Full : %7ld Redzoning : %s Used : %7ld\n",
416 s
->slab_size
, s
->slabs
- s
->partial
- s
->cpu_slabs
,
417 onoff(s
->red_zone
), s
->objects
* s
->object_size
);
418 printf("SlabSiz: %7d Partial: %7ld Poisoning : %s Loss : %7ld\n",
419 page_size
<< s
->order
, s
->partial
, onoff(s
->poison
),
420 s
->slabs
* (page_size
<< s
->order
) - s
->objects
* s
->object_size
);
421 printf("Loss : %7d CpuSlab: %7d Tracking : %s Lalig: %7ld\n",
422 s
->slab_size
- s
->object_size
, s
->cpu_slabs
, onoff(s
->store_user
),
423 (s
->slab_size
- s
->object_size
) * s
->objects
);
424 printf("Align : %7d Objects: %7d Tracing : %s Lpadd: %7ld\n",
425 s
->align
, s
->objs_per_slab
, onoff(s
->trace
),
426 ((page_size
<< s
->order
) - s
->objs_per_slab
* s
->slab_size
) *
434 void slabcache(struct slabinfo
*s
)
441 if (strcmp(s
->name
, "*") == 0)
444 if (actual_slabs
== 1) {
449 if (skip_zero
&& !show_empty
&& !s
->slabs
)
452 if (show_empty
&& s
->slabs
)
455 store_size(size_str
, slab_size(s
));
456 sprintf(dist_str
,"%lu/%lu/%d", s
->slabs
, s
->partial
, s
->cpu_slabs
);
465 if (s
->hwcache_align
)
469 if (s
->reclaim_account
)
473 if (s
->sanity_checks
)
481 printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n",
482 s
->name
, s
->objects
, s
->object_size
, size_str
, dist_str
,
483 s
->objs_per_slab
, s
->order
,
484 s
->slabs
? (s
->partial
* 100) / s
->slabs
: 100,
485 s
->slabs
? (s
->objects
* s
->object_size
* 100) /
486 (s
->slabs
* (page_size
<< s
->order
)) : 100,
491 * Analyze debug options. Return false if something is amiss.
493 int debug_opt_scan(char *opt
)
495 if (!opt
|| !opt
[0] || strcmp(opt
, "-") == 0)
498 if (strcasecmp(opt
, "a") == 0) {
542 int slab_empty(struct slabinfo
*s
)
548 * We may still have slabs even if there are no objects. Shrinking will
552 set_obj(s
, "shrink", 1);
557 void slab_debug(struct slabinfo
*s
)
559 if (strcmp(s
->name
, "*") == 0)
562 if (sanity
&& !s
->sanity_checks
) {
563 set_obj(s
, "sanity", 1);
565 if (!sanity
&& s
->sanity_checks
) {
567 set_obj(s
, "sanity", 0);
569 fprintf(stderr
, "%s not empty cannot disable sanity checks\n", s
->name
);
571 if (redzone
&& !s
->red_zone
) {
573 set_obj(s
, "red_zone", 1);
575 fprintf(stderr
, "%s not empty cannot enable redzoning\n", s
->name
);
577 if (!redzone
&& s
->red_zone
) {
579 set_obj(s
, "red_zone", 0);
581 fprintf(stderr
, "%s not empty cannot disable redzoning\n", s
->name
);
583 if (poison
&& !s
->poison
) {
585 set_obj(s
, "poison", 1);
587 fprintf(stderr
, "%s not empty cannot enable poisoning\n", s
->name
);
589 if (!poison
&& s
->poison
) {
591 set_obj(s
, "poison", 0);
593 fprintf(stderr
, "%s not empty cannot disable poisoning\n", s
->name
);
595 if (tracking
&& !s
->store_user
) {
597 set_obj(s
, "store_user", 1);
599 fprintf(stderr
, "%s not empty cannot enable tracking\n", s
->name
);
601 if (!tracking
&& s
->store_user
) {
603 set_obj(s
, "store_user", 0);
605 fprintf(stderr
, "%s not empty cannot disable tracking\n", s
->name
);
607 if (tracing
&& !s
->trace
) {
609 set_obj(s
, "trace", 1);
611 fprintf(stderr
, "%s can only enable trace for one slab at a time\n", s
->name
);
613 if (!tracing
&& s
->trace
)
614 set_obj(s
, "trace", 1);
622 char b1
[20], b2
[20], b3
[20], b4
[20];
623 unsigned long long max
= 1ULL << 63;
626 unsigned long long min_objsize
= max
, max_objsize
= 0, avg_objsize
;
628 /* Number of partial slabs in a slabcache */
629 unsigned long long min_partial
= max
, max_partial
= 0,
630 avg_partial
, total_partial
= 0;
632 /* Number of slabs in a slab cache */
633 unsigned long long min_slabs
= max
, max_slabs
= 0,
634 avg_slabs
, total_slabs
= 0;
636 /* Size of the whole slab */
637 unsigned long long min_size
= max
, max_size
= 0,
638 avg_size
, total_size
= 0;
640 /* Bytes used for object storage in a slab */
641 unsigned long long min_used
= max
, max_used
= 0,
642 avg_used
, total_used
= 0;
644 /* Waste: Bytes used for alignment and padding */
645 unsigned long long min_waste
= max
, max_waste
= 0,
646 avg_waste
, total_waste
= 0;
647 /* Number of objects in a slab */
648 unsigned long long min_objects
= max
, max_objects
= 0,
649 avg_objects
, total_objects
= 0;
650 /* Waste per object */
651 unsigned long long min_objwaste
= max
,
652 max_objwaste
= 0, avg_objwaste
,
655 /* Memory per object */
656 unsigned long long min_memobj
= max
,
657 max_memobj
= 0, avg_memobj
,
660 /* Percentage of partial slabs per slab */
661 unsigned long min_ppart
= 100, max_ppart
= 0,
662 avg_ppart
, total_ppart
= 0;
664 /* Number of objects in partial slabs */
665 unsigned long min_partobj
= max
, max_partobj
= 0,
666 avg_partobj
, total_partobj
= 0;
668 /* Percentage of partial objects of all objects in a slab */
669 unsigned long min_ppartobj
= 100, max_ppartobj
= 0,
670 avg_ppartobj
, total_ppartobj
= 0;
673 for (s
= slabinfo
; s
< slabinfo
+ slabs
; s
++) {
674 unsigned long long size
;
676 unsigned long long wasted
;
677 unsigned long long objwaste
;
678 long long objects_in_partial_slabs
;
679 unsigned long percentage_partial_slabs
;
680 unsigned long percentage_partial_objs
;
682 if (!s
->slabs
|| !s
->objects
)
688 used
= s
->objects
* s
->object_size
;
689 wasted
= size
- used
;
690 objwaste
= s
->slab_size
- s
->object_size
;
692 objects_in_partial_slabs
= s
->objects
-
693 (s
->slabs
- s
->partial
- s
->cpu_slabs
) *
696 if (objects_in_partial_slabs
< 0)
697 objects_in_partial_slabs
= 0;
699 percentage_partial_slabs
= s
->partial
* 100 / s
->slabs
;
700 if (percentage_partial_slabs
> 100)
701 percentage_partial_slabs
= 100;
703 percentage_partial_objs
= objects_in_partial_slabs
* 100
706 if (percentage_partial_objs
> 100)
707 percentage_partial_objs
= 100;
709 if (s
->object_size
< min_objsize
)
710 min_objsize
= s
->object_size
;
711 if (s
->partial
< min_partial
)
712 min_partial
= s
->partial
;
713 if (s
->slabs
< min_slabs
)
714 min_slabs
= s
->slabs
;
717 if (wasted
< min_waste
)
719 if (objwaste
< min_objwaste
)
720 min_objwaste
= objwaste
;
721 if (s
->objects
< min_objects
)
722 min_objects
= s
->objects
;
725 if (objects_in_partial_slabs
< min_partobj
)
726 min_partobj
= objects_in_partial_slabs
;
727 if (percentage_partial_slabs
< min_ppart
)
728 min_ppart
= percentage_partial_slabs
;
729 if (percentage_partial_objs
< min_ppartobj
)
730 min_ppartobj
= percentage_partial_objs
;
731 if (s
->slab_size
< min_memobj
)
732 min_memobj
= s
->slab_size
;
734 if (s
->object_size
> max_objsize
)
735 max_objsize
= s
->object_size
;
736 if (s
->partial
> max_partial
)
737 max_partial
= s
->partial
;
738 if (s
->slabs
> max_slabs
)
739 max_slabs
= s
->slabs
;
742 if (wasted
> max_waste
)
744 if (objwaste
> max_objwaste
)
745 max_objwaste
= objwaste
;
746 if (s
->objects
> max_objects
)
747 max_objects
= s
->objects
;
750 if (objects_in_partial_slabs
> max_partobj
)
751 max_partobj
= objects_in_partial_slabs
;
752 if (percentage_partial_slabs
> max_ppart
)
753 max_ppart
= percentage_partial_slabs
;
754 if (percentage_partial_objs
> max_ppartobj
)
755 max_ppartobj
= percentage_partial_objs
;
756 if (s
->slab_size
> max_memobj
)
757 max_memobj
= s
->slab_size
;
759 total_partial
+= s
->partial
;
760 total_slabs
+= s
->slabs
;
762 total_waste
+= wasted
;
764 total_objects
+= s
->objects
;
766 total_partobj
+= objects_in_partial_slabs
;
767 total_ppart
+= percentage_partial_slabs
;
768 total_ppartobj
+= percentage_partial_objs
;
770 total_objwaste
+= s
->objects
* objwaste
;
771 total_objsize
+= s
->objects
* s
->slab_size
;
774 if (!total_objects
) {
775 printf("No objects\n");
779 printf("No slabs\n");
783 /* Per slab averages */
784 avg_partial
= total_partial
/ used_slabs
;
785 avg_slabs
= total_slabs
/ used_slabs
;
786 avg_size
= total_size
/ used_slabs
;
787 avg_waste
= total_waste
/ used_slabs
;
789 avg_objects
= total_objects
/ used_slabs
;
790 avg_used
= total_used
/ used_slabs
;
791 avg_partobj
= total_partobj
/ used_slabs
;
792 avg_ppart
= total_ppart
/ used_slabs
;
793 avg_ppartobj
= total_ppartobj
/ used_slabs
;
795 /* Per object object sizes */
796 avg_objsize
= total_used
/ total_objects
;
797 avg_objwaste
= total_objwaste
/ total_objects
;
798 avg_partobj
= total_partobj
* 100 / total_objects
;
799 avg_memobj
= total_objsize
/ total_objects
;
801 printf("Slabcache Totals\n");
802 printf("----------------\n");
803 printf("Slabcaches : %3d Aliases : %3d->%-3d Active: %3d\n",
804 slabs
, aliases
, alias_targets
, used_slabs
);
806 store_size(b1
, total_size
);store_size(b2
, total_waste
);
807 store_size(b3
, total_waste
* 100 / total_used
);
808 printf("Memory used: %6s # Loss : %6s MRatio:%6s%%\n", b1
, b2
, b3
);
810 store_size(b1
, total_objects
);store_size(b2
, total_partobj
);
811 store_size(b3
, total_partobj
* 100 / total_objects
);
812 printf("# Objects : %6s # PartObj: %6s ORatio:%6s%%\n", b1
, b2
, b3
);
815 printf("Per Cache Average Min Max Total\n");
816 printf("---------------------------------------------------------\n");
818 store_size(b1
, avg_objects
);store_size(b2
, min_objects
);
819 store_size(b3
, max_objects
);store_size(b4
, total_objects
);
820 printf("#Objects %10s %10s %10s %10s\n",
823 store_size(b1
, avg_slabs
);store_size(b2
, min_slabs
);
824 store_size(b3
, max_slabs
);store_size(b4
, total_slabs
);
825 printf("#Slabs %10s %10s %10s %10s\n",
828 store_size(b1
, avg_partial
);store_size(b2
, min_partial
);
829 store_size(b3
, max_partial
);store_size(b4
, total_partial
);
830 printf("#PartSlab %10s %10s %10s %10s\n",
832 store_size(b1
, avg_ppart
);store_size(b2
, min_ppart
);
833 store_size(b3
, max_ppart
);
834 store_size(b4
, total_partial
* 100 / total_slabs
);
835 printf("%%PartSlab%10s%% %10s%% %10s%% %10s%%\n",
838 store_size(b1
, avg_partobj
);store_size(b2
, min_partobj
);
839 store_size(b3
, max_partobj
);
840 store_size(b4
, total_partobj
);
841 printf("PartObjs %10s %10s %10s %10s\n",
844 store_size(b1
, avg_ppartobj
);store_size(b2
, min_ppartobj
);
845 store_size(b3
, max_ppartobj
);
846 store_size(b4
, total_partobj
* 100 / total_objects
);
847 printf("%% PartObj%10s%% %10s%% %10s%% %10s%%\n",
850 store_size(b1
, avg_size
);store_size(b2
, min_size
);
851 store_size(b3
, max_size
);store_size(b4
, total_size
);
852 printf("Memory %10s %10s %10s %10s\n",
855 store_size(b1
, avg_used
);store_size(b2
, min_used
);
856 store_size(b3
, max_used
);store_size(b4
, total_used
);
857 printf("Used %10s %10s %10s %10s\n",
860 store_size(b1
, avg_waste
);store_size(b2
, min_waste
);
861 store_size(b3
, max_waste
);store_size(b4
, total_waste
);
862 printf("Loss %10s %10s %10s %10s\n",
866 printf("Per Object Average Min Max\n");
867 printf("---------------------------------------------\n");
869 store_size(b1
, avg_memobj
);store_size(b2
, min_memobj
);
870 store_size(b3
, max_memobj
);
871 printf("Memory %10s %10s %10s\n",
873 store_size(b1
, avg_objsize
);store_size(b2
, min_objsize
);
874 store_size(b3
, max_objsize
);
875 printf("User %10s %10s %10s\n",
878 store_size(b1
, avg_objwaste
);store_size(b2
, min_objwaste
);
879 store_size(b3
, max_objwaste
);
880 printf("Loss %10s %10s %10s\n",
884 void sort_slabs(void)
886 struct slabinfo
*s1
,*s2
;
888 for (s1
= slabinfo
; s1
< slabinfo
+ slabs
; s1
++) {
889 for (s2
= s1
+ 1; s2
< slabinfo
+ slabs
; s2
++) {
893 result
= slab_size(s1
) < slab_size(s2
);
895 result
= strcasecmp(s1
->name
, s2
->name
);
903 memcpy(&t
, s1
, sizeof(struct slabinfo
));
904 memcpy(s1
, s2
, sizeof(struct slabinfo
));
905 memcpy(s2
, &t
, sizeof(struct slabinfo
));
911 void sort_aliases(void)
913 struct aliasinfo
*a1
,*a2
;
915 for (a1
= aliasinfo
; a1
< aliasinfo
+ aliases
; a1
++) {
916 for (a2
= a1
+ 1; a2
< aliasinfo
+ aliases
; a2
++) {
921 if (show_alias
&& !show_inverted
) {
925 if (strcasecmp(n1
, n2
) > 0) {
928 memcpy(&t
, a1
, sizeof(struct aliasinfo
));
929 memcpy(a1
, a2
, sizeof(struct aliasinfo
));
930 memcpy(a2
, &t
, sizeof(struct aliasinfo
));
936 void link_slabs(void)
941 for (a
= aliasinfo
; a
< aliasinfo
+ aliases
; a
++) {
943 for (s
= slabinfo
; s
< slabinfo
+ slabs
; s
++)
944 if (strcmp(a
->ref
, s
->name
) == 0) {
949 if (s
== slabinfo
+ slabs
)
950 fatal("Unresolved alias %s\n", a
->ref
);
962 for(a
= aliasinfo
; a
< aliasinfo
+ aliases
; a
++) {
964 if (!show_single_ref
&& a
->slab
->refs
== 1)
967 if (!show_inverted
) {
969 if (strcmp(a
->slab
->name
, active
) == 0) {
970 printf(" %s", a
->name
);
974 printf("\n%-12s <- %s", a
->slab
->name
, a
->name
);
975 active
= a
->slab
->name
;
978 printf("%-20s -> %s\n", a
->name
, a
->slab
->name
);
985 void rename_slabs(void)
990 for (s
= slabinfo
; s
< slabinfo
+ slabs
; s
++) {
994 if (s
->refs
> 1 && !show_first_alias
)
997 a
= find_one_alias(s
);
1008 int slab_mismatch(char *slab
)
1010 return regexec(&pattern
, slab
, 0, NULL
, 0);
1013 void read_slab_dir(void)
1017 struct slabinfo
*slab
= slabinfo
;
1018 struct aliasinfo
*alias
= aliasinfo
;
1023 if (chdir("/sys/slab"))
1024 fatal("SYSFS support for SLUB not active\n");
1027 while ((de
= readdir(dir
))) {
1028 if (de
->d_name
[0] == '.' ||
1029 (de
->d_name
[0] != ':' && slab_mismatch(de
->d_name
)))
1031 switch (de
->d_type
) {
1033 alias
->name
= strdup(de
->d_name
);
1034 count
= readlink(de
->d_name
, buffer
, sizeof(buffer
));
1037 fatal("Cannot read symlink %s\n", de
->d_name
);
1041 while (p
> buffer
&& p
[-1] != '/')
1043 alias
->ref
= strdup(p
);
1047 if (chdir(de
->d_name
))
1048 fatal("Unable to access slab %s\n", slab
->name
);
1049 slab
->name
= strdup(de
->d_name
);
1052 slab
->aliases
= get_obj("aliases");
1053 slab
->align
= get_obj("align");
1054 slab
->cache_dma
= get_obj("cache_dma");
1055 slab
->cpu_slabs
= get_obj("cpu_slabs");
1056 slab
->destroy_by_rcu
= get_obj("destroy_by_rcu");
1057 slab
->hwcache_align
= get_obj("hwcache_align");
1058 slab
->object_size
= get_obj("object_size");
1059 slab
->objects
= get_obj("objects");
1060 slab
->objs_per_slab
= get_obj("objs_per_slab");
1061 slab
->order
= get_obj("order");
1062 slab
->partial
= get_obj("partial");
1063 slab
->partial
= get_obj_and_str("partial", &t
);
1064 decode_numa_list(slab
->numa_partial
, t
);
1065 slab
->poison
= get_obj("poison");
1066 slab
->reclaim_account
= get_obj("reclaim_account");
1067 slab
->red_zone
= get_obj("red_zone");
1068 slab
->sanity_checks
= get_obj("sanity_checks");
1069 slab
->slab_size
= get_obj("slab_size");
1070 slab
->slabs
= get_obj_and_str("slabs", &t
);
1071 decode_numa_list(slab
->numa
, t
);
1072 slab
->store_user
= get_obj("store_user");
1073 slab
->trace
= get_obj("trace");
1075 if (slab
->name
[0] == ':')
1080 fatal("Unknown file type %lx\n", de
->d_type
);
1084 slabs
= slab
- slabinfo
;
1085 actual_slabs
= slabs
;
1086 aliases
= alias
- aliasinfo
;
1087 if (slabs
> MAX_SLABS
)
1088 fatal("Too many slabs\n");
1089 if (aliases
> MAX_ALIASES
)
1090 fatal("Too many aliases\n");
1093 void output_slabs(void)
1095 struct slabinfo
*slab
;
1097 for (slab
= slabinfo
; slab
< slabinfo
+ slabs
; slab
++) {
1105 else if (show_track
)
1106 show_tracking(slab
);
1108 slab_validate(slab
);
1117 else if (show_report
)
1122 struct option opts
[] = {
1123 { "aliases", 0, NULL
, 'a' },
1124 { "debug", 2, NULL
, 'd' },
1125 { "empty", 0, NULL
, 'e' },
1126 { "first-alias", 0, NULL
, 'f' },
1127 { "help", 0, NULL
, 'h' },
1128 { "inverted", 0, NULL
, 'i'},
1129 { "numa", 0, NULL
, 'n' },
1130 { "ops", 0, NULL
, 'o' },
1131 { "report", 0, NULL
, 'r' },
1132 { "shrink", 0, NULL
, 's' },
1133 { "slabs", 0, NULL
, 'l' },
1134 { "track", 0, NULL
, 't'},
1135 { "validate", 0, NULL
, 'v' },
1136 { "zero", 0, NULL
, 'z' },
1137 { "1ref", 0, NULL
, '1'},
1138 { NULL
, 0, NULL
, 0 }
1141 int main(int argc
, char *argv
[])
1145 char *pattern_source
;
1147 page_size
= getpagesize();
1149 while ((c
= getopt_long(argc
, argv
, "ad::efhil1noprstvzTS",
1153 show_single_ref
= 1;
1160 if (!debug_opt_scan(optarg
))
1161 fatal("Invalid debug option '%s'\n", optarg
);
1167 show_first_alias
= 1;
1207 fatal("%s: Invalid option '%c'\n", argv
[0], optopt
);
1211 if (!show_slab
&& !show_alias
&& !show_track
&& !show_report
1212 && !validate
&& !shrink
&& !set_debug
&& !show_ops
)
1216 pattern_source
= argv
[optind
];
1218 pattern_source
= ".*";
1220 err
= regcomp(&pattern
, pattern_source
, REG_ICASE
|REG_NOSUB
);
1222 fatal("%s: Invalid pattern '%s' code %d\n",
1223 argv
[0], pattern_source
, err
);