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
;
36 int numa_partial
[MAX_NODES
];
37 } slabinfo
[MAX_SLABS
];
42 struct slabinfo
*slab
;
43 } aliasinfo
[MAX_ALIASES
];
48 int alias_targets
= 0;
60 int show_first_alias
= 0;
63 int show_inverted
= 0;
64 int show_single_ref
= 0;
81 void fatal(const char *x
, ...)
86 vfprintf(stderr
, x
, ap
);
93 printf("slabinfo 5/7/2007. (c) 2007 sgi. clameter@sgi.com\n\n"
94 "slabinfo [-ahnpvtsz] [-d debugopts] [slab-regexp]\n"
95 "-a|--aliases Show aliases\n"
96 "-d<options>|--debug=<options> Set/Clear Debug options\n"
97 "-e|--empty Show empty slabs\n"
98 "-f|--first-alias Show first alias\n"
99 "-h|--help Show usage information\n"
100 "-i|--inverted Inverted list\n"
101 "-l|--slabs Show slabs\n"
102 "-n|--numa Show NUMA information\n"
103 "-o|--ops Show kmem_cache_ops\n"
104 "-s|--shrink Shrink slabs\n"
105 "-r|--report Detailed report on single slabs\n"
106 "-S|--Size Sort by size\n"
107 "-t|--tracking Show alloc/free information\n"
108 "-T|--Totals Show summary information\n"
109 "-v|--validate Validate slabs\n"
110 "-z|--zero Include empty slabs\n"
111 "-1|--1ref Single reference\n"
112 "\nValid debug options (FZPUT may be combined)\n"
113 "a / A Switch on all debug options (=FZUP)\n"
114 "- Switch off all debug options\n"
115 "f / F Sanity Checks (SLAB_DEBUG_FREE)\n"
123 unsigned long read_obj(const char *name
)
125 FILE *f
= fopen(name
, "r");
130 if (!fgets(buffer
, sizeof(buffer
), f
))
133 if (buffer
[strlen(buffer
)] == '\n')
134 buffer
[strlen(buffer
)] = 0;
136 return strlen(buffer
);
141 * Get the contents of an attribute
143 unsigned long get_obj(const char *name
)
151 unsigned long get_obj_and_str(const char *name
, char **x
)
153 unsigned long result
= 0;
158 if (!read_obj(name
)) {
162 result
= strtoul(buffer
, &p
, 10);
170 void set_obj(struct slabinfo
*s
, const char *name
, int n
)
175 snprintf(x
, 100, "%s/%s", s
->name
, name
);
178 fatal("Cannot write to %s\n", x
);
180 fprintf(f
, "%d\n", n
);
184 unsigned long read_slab_obj(struct slabinfo
*s
, const char *name
)
190 snprintf(x
, 100, "%s/%s", s
->name
, name
);
196 l
= fread(buffer
, 1, sizeof(buffer
), f
);
205 * Put a size string together
207 int store_size(char *buffer
, unsigned long value
)
209 unsigned long divisor
= 1;
213 if (value
> 1000000000UL) {
214 divisor
= 100000000UL;
216 } else if (value
> 1000000UL) {
219 } else if (value
> 1000UL) {
225 n
= sprintf(buffer
, "%ld",value
);
232 memmove(buffer
+ n
- 2, buffer
+ n
- 3, 4);
239 void decode_numa_list(int *numa
, char *t
)
244 memset(numa
, 0, MAX_NODES
* sizeof(int));
251 node
= strtoul(t
, &t
, 10);
254 nr
= strtoul(t
, &t
, 10);
256 if (node
> highest_node
)
264 void slab_validate(struct slabinfo
*s
)
266 if (strcmp(s
->name
, "*") == 0)
269 set_obj(s
, "validate", 1);
272 void slab_shrink(struct slabinfo
*s
)
274 if (strcmp(s
->name
, "*") == 0)
277 set_obj(s
, "shrink", 1);
282 void first_line(void)
284 printf("Name Objects Objsize Space "
285 "Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n");
289 * Find the shortest alias of a slab
291 struct aliasinfo
*find_one_alias(struct slabinfo
*find
)
294 struct aliasinfo
*best
= NULL
;
296 for(a
= aliasinfo
;a
< aliasinfo
+ aliases
; a
++) {
297 if (a
->slab
== find
&&
298 (!best
|| strlen(best
->name
) < strlen(a
->name
))) {
300 if (strncmp(a
->name
,"kmall", 5) == 0)
307 unsigned long slab_size(struct slabinfo
*s
)
309 return s
->slabs
* (page_size
<< s
->order
);
312 void slab_numa(struct slabinfo
*s
, int mode
)
316 if (strcmp(s
->name
, "*") == 0)
320 printf("\n%s: No NUMA information available.\n", s
->name
);
324 if (skip_zero
&& !s
->slabs
)
328 printf("\n%-21s:", mode
? "NUMA nodes" : "Slab");
329 for(node
= 0; node
<= highest_node
; node
++)
330 printf(" %4d", node
);
331 printf("\n----------------------");
332 for(node
= 0; node
<= highest_node
; node
++)
336 printf("%-21s ", mode
? "All slabs" : s
->name
);
337 for(node
= 0; node
<= highest_node
; node
++) {
340 store_size(b
, s
->numa
[node
]);
345 printf("%-21s ", "Partial slabs");
346 for(node
= 0; node
<= highest_node
; node
++) {
349 store_size(b
, s
->numa_partial
[node
]);
357 void show_tracking(struct slabinfo
*s
)
359 printf("\n%s: Kernel object allocation\n", s
->name
);
360 printf("-----------------------------------------------------------------------\n");
361 if (read_slab_obj(s
, "alloc_calls"))
366 printf("\n%s: Kernel object freeing\n", s
->name
);
367 printf("------------------------------------------------------------------------\n");
368 if (read_slab_obj(s
, "free_calls"))
375 void ops(struct slabinfo
*s
)
377 if (strcmp(s
->name
, "*") == 0)
380 if (read_slab_obj(s
, "ops")) {
381 printf("\n%s: kmem_cache operations\n", s
->name
);
382 printf("--------------------------------------------\n");
385 printf("\n%s has no kmem_cache operations\n", s
->name
);
388 const char *onoff(int x
)
395 void report(struct slabinfo
*s
)
397 if (strcmp(s
->name
, "*") == 0)
400 printf("\nSlabcache: %-20s Aliases: %2d Order : %2d Objects: %lu\n",
401 s
->name
, s
->aliases
, s
->order
, s
->objects
);
402 if (s
->hwcache_align
)
403 printf("** Hardware cacheline aligned\n");
405 printf("** Memory is allocated in a special DMA zone\n");
406 if (s
->destroy_by_rcu
)
407 printf("** Slabs are destroyed via RCU\n");
408 if (s
->reclaim_account
)
409 printf("** Reclaim accounting active\n");
411 printf("\nSizes (bytes) Slabs Debug Memory\n");
412 printf("------------------------------------------------------------------------\n");
413 printf("Object : %7d Total : %7ld Sanity Checks : %s Total: %7ld\n",
414 s
->object_size
, s
->slabs
, onoff(s
->sanity_checks
),
415 s
->slabs
* (page_size
<< s
->order
));
416 printf("SlabObj: %7d Full : %7ld Redzoning : %s Used : %7ld\n",
417 s
->slab_size
, s
->slabs
- s
->partial
- s
->cpu_slabs
,
418 onoff(s
->red_zone
), s
->objects
* s
->object_size
);
419 printf("SlabSiz: %7d Partial: %7ld Poisoning : %s Loss : %7ld\n",
420 page_size
<< s
->order
, s
->partial
, onoff(s
->poison
),
421 s
->slabs
* (page_size
<< s
->order
) - s
->objects
* s
->object_size
);
422 printf("Loss : %7d CpuSlab: %7d Tracking : %s Lalig: %7ld\n",
423 s
->slab_size
- s
->object_size
, s
->cpu_slabs
, onoff(s
->store_user
),
424 (s
->slab_size
- s
->object_size
) * s
->objects
);
425 printf("Align : %7d Objects: %7d Tracing : %s Lpadd: %7ld\n",
426 s
->align
, s
->objs_per_slab
, onoff(s
->trace
),
427 ((page_size
<< s
->order
) - s
->objs_per_slab
* s
->slab_size
) *
435 void slabcache(struct slabinfo
*s
)
442 if (strcmp(s
->name
, "*") == 0)
445 if (actual_slabs
== 1) {
450 if (skip_zero
&& !show_empty
&& !s
->slabs
)
453 if (show_empty
&& s
->slabs
)
456 store_size(size_str
, slab_size(s
));
457 snprintf(dist_str
, 40, "%lu/%lu/%d", s
->slabs
, s
->partial
, s
->cpu_slabs
);
466 if (s
->hwcache_align
)
470 if (s
->reclaim_account
)
474 if (s
->sanity_checks
)
482 printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n",
483 s
->name
, s
->objects
, s
->object_size
, size_str
, dist_str
,
484 s
->objs_per_slab
, s
->order
,
485 s
->slabs
? (s
->partial
* 100) / s
->slabs
: 100,
486 s
->slabs
? (s
->objects
* s
->object_size
* 100) /
487 (s
->slabs
* (page_size
<< s
->order
)) : 100,
492 * Analyze debug options. Return false if something is amiss.
494 int debug_opt_scan(char *opt
)
496 if (!opt
|| !opt
[0] || strcmp(opt
, "-") == 0)
499 if (strcasecmp(opt
, "a") == 0) {
543 int slab_empty(struct slabinfo
*s
)
549 * We may still have slabs even if there are no objects. Shrinking will
553 set_obj(s
, "shrink", 1);
558 void slab_debug(struct slabinfo
*s
)
560 if (strcmp(s
->name
, "*") == 0)
563 if (sanity
&& !s
->sanity_checks
) {
564 set_obj(s
, "sanity", 1);
566 if (!sanity
&& s
->sanity_checks
) {
568 set_obj(s
, "sanity", 0);
570 fprintf(stderr
, "%s not empty cannot disable sanity checks\n", s
->name
);
572 if (redzone
&& !s
->red_zone
) {
574 set_obj(s
, "red_zone", 1);
576 fprintf(stderr
, "%s not empty cannot enable redzoning\n", s
->name
);
578 if (!redzone
&& s
->red_zone
) {
580 set_obj(s
, "red_zone", 0);
582 fprintf(stderr
, "%s not empty cannot disable redzoning\n", s
->name
);
584 if (poison
&& !s
->poison
) {
586 set_obj(s
, "poison", 1);
588 fprintf(stderr
, "%s not empty cannot enable poisoning\n", s
->name
);
590 if (!poison
&& s
->poison
) {
592 set_obj(s
, "poison", 0);
594 fprintf(stderr
, "%s not empty cannot disable poisoning\n", s
->name
);
596 if (tracking
&& !s
->store_user
) {
598 set_obj(s
, "store_user", 1);
600 fprintf(stderr
, "%s not empty cannot enable tracking\n", s
->name
);
602 if (!tracking
&& s
->store_user
) {
604 set_obj(s
, "store_user", 0);
606 fprintf(stderr
, "%s not empty cannot disable tracking\n", s
->name
);
608 if (tracing
&& !s
->trace
) {
610 set_obj(s
, "trace", 1);
612 fprintf(stderr
, "%s can only enable trace for one slab at a time\n", s
->name
);
614 if (!tracing
&& s
->trace
)
615 set_obj(s
, "trace", 1);
623 char b1
[20], b2
[20], b3
[20], b4
[20];
624 unsigned long long max
= 1ULL << 63;
627 unsigned long long min_objsize
= max
, max_objsize
= 0, avg_objsize
;
629 /* Number of partial slabs in a slabcache */
630 unsigned long long min_partial
= max
, max_partial
= 0,
631 avg_partial
, total_partial
= 0;
633 /* Number of slabs in a slab cache */
634 unsigned long long min_slabs
= max
, max_slabs
= 0,
635 avg_slabs
, total_slabs
= 0;
637 /* Size of the whole slab */
638 unsigned long long min_size
= max
, max_size
= 0,
639 avg_size
, total_size
= 0;
641 /* Bytes used for object storage in a slab */
642 unsigned long long min_used
= max
, max_used
= 0,
643 avg_used
, total_used
= 0;
645 /* Waste: Bytes used for alignment and padding */
646 unsigned long long min_waste
= max
, max_waste
= 0,
647 avg_waste
, total_waste
= 0;
648 /* Number of objects in a slab */
649 unsigned long long min_objects
= max
, max_objects
= 0,
650 avg_objects
, total_objects
= 0;
651 /* Waste per object */
652 unsigned long long min_objwaste
= max
,
653 max_objwaste
= 0, avg_objwaste
,
656 /* Memory per object */
657 unsigned long long min_memobj
= max
,
658 max_memobj
= 0, avg_memobj
,
661 /* Percentage of partial slabs per slab */
662 unsigned long min_ppart
= 100, max_ppart
= 0,
663 avg_ppart
, total_ppart
= 0;
665 /* Number of objects in partial slabs */
666 unsigned long min_partobj
= max
, max_partobj
= 0,
667 avg_partobj
, total_partobj
= 0;
669 /* Percentage of partial objects of all objects in a slab */
670 unsigned long min_ppartobj
= 100, max_ppartobj
= 0,
671 avg_ppartobj
, total_ppartobj
= 0;
674 for (s
= slabinfo
; s
< slabinfo
+ slabs
; s
++) {
675 unsigned long long size
;
677 unsigned long long wasted
;
678 unsigned long long objwaste
;
679 long long objects_in_partial_slabs
;
680 unsigned long percentage_partial_slabs
;
681 unsigned long percentage_partial_objs
;
683 if (!s
->slabs
|| !s
->objects
)
689 used
= s
->objects
* s
->object_size
;
690 wasted
= size
- used
;
691 objwaste
= s
->slab_size
- s
->object_size
;
693 objects_in_partial_slabs
= s
->objects
-
694 (s
->slabs
- s
->partial
- s
->cpu_slabs
) *
697 if (objects_in_partial_slabs
< 0)
698 objects_in_partial_slabs
= 0;
700 percentage_partial_slabs
= s
->partial
* 100 / s
->slabs
;
701 if (percentage_partial_slabs
> 100)
702 percentage_partial_slabs
= 100;
704 percentage_partial_objs
= objects_in_partial_slabs
* 100
707 if (percentage_partial_objs
> 100)
708 percentage_partial_objs
= 100;
710 if (s
->object_size
< min_objsize
)
711 min_objsize
= s
->object_size
;
712 if (s
->partial
< min_partial
)
713 min_partial
= s
->partial
;
714 if (s
->slabs
< min_slabs
)
715 min_slabs
= s
->slabs
;
718 if (wasted
< min_waste
)
720 if (objwaste
< min_objwaste
)
721 min_objwaste
= objwaste
;
722 if (s
->objects
< min_objects
)
723 min_objects
= s
->objects
;
726 if (objects_in_partial_slabs
< min_partobj
)
727 min_partobj
= objects_in_partial_slabs
;
728 if (percentage_partial_slabs
< min_ppart
)
729 min_ppart
= percentage_partial_slabs
;
730 if (percentage_partial_objs
< min_ppartobj
)
731 min_ppartobj
= percentage_partial_objs
;
732 if (s
->slab_size
< min_memobj
)
733 min_memobj
= s
->slab_size
;
735 if (s
->object_size
> max_objsize
)
736 max_objsize
= s
->object_size
;
737 if (s
->partial
> max_partial
)
738 max_partial
= s
->partial
;
739 if (s
->slabs
> max_slabs
)
740 max_slabs
= s
->slabs
;
743 if (wasted
> max_waste
)
745 if (objwaste
> max_objwaste
)
746 max_objwaste
= objwaste
;
747 if (s
->objects
> max_objects
)
748 max_objects
= s
->objects
;
751 if (objects_in_partial_slabs
> max_partobj
)
752 max_partobj
= objects_in_partial_slabs
;
753 if (percentage_partial_slabs
> max_ppart
)
754 max_ppart
= percentage_partial_slabs
;
755 if (percentage_partial_objs
> max_ppartobj
)
756 max_ppartobj
= percentage_partial_objs
;
757 if (s
->slab_size
> max_memobj
)
758 max_memobj
= s
->slab_size
;
760 total_partial
+= s
->partial
;
761 total_slabs
+= s
->slabs
;
763 total_waste
+= wasted
;
765 total_objects
+= s
->objects
;
767 total_partobj
+= objects_in_partial_slabs
;
768 total_ppart
+= percentage_partial_slabs
;
769 total_ppartobj
+= percentage_partial_objs
;
771 total_objwaste
+= s
->objects
* objwaste
;
772 total_objsize
+= s
->objects
* s
->slab_size
;
775 if (!total_objects
) {
776 printf("No objects\n");
780 printf("No slabs\n");
784 /* Per slab averages */
785 avg_partial
= total_partial
/ used_slabs
;
786 avg_slabs
= total_slabs
/ used_slabs
;
787 avg_size
= total_size
/ used_slabs
;
788 avg_waste
= total_waste
/ used_slabs
;
790 avg_objects
= total_objects
/ used_slabs
;
791 avg_used
= total_used
/ used_slabs
;
792 avg_partobj
= total_partobj
/ used_slabs
;
793 avg_ppart
= total_ppart
/ used_slabs
;
794 avg_ppartobj
= total_ppartobj
/ used_slabs
;
796 /* Per object object sizes */
797 avg_objsize
= total_used
/ total_objects
;
798 avg_objwaste
= total_objwaste
/ total_objects
;
799 avg_partobj
= total_partobj
* 100 / total_objects
;
800 avg_memobj
= total_objsize
/ total_objects
;
802 printf("Slabcache Totals\n");
803 printf("----------------\n");
804 printf("Slabcaches : %3d Aliases : %3d->%-3d Active: %3d\n",
805 slabs
, aliases
, alias_targets
, used_slabs
);
807 store_size(b1
, total_size
);store_size(b2
, total_waste
);
808 store_size(b3
, total_waste
* 100 / total_used
);
809 printf("Memory used: %6s # Loss : %6s MRatio:%6s%%\n", b1
, b2
, b3
);
811 store_size(b1
, total_objects
);store_size(b2
, total_partobj
);
812 store_size(b3
, total_partobj
* 100 / total_objects
);
813 printf("# Objects : %6s # PartObj: %6s ORatio:%6s%%\n", b1
, b2
, b3
);
816 printf("Per Cache Average Min Max Total\n");
817 printf("---------------------------------------------------------\n");
819 store_size(b1
, avg_objects
);store_size(b2
, min_objects
);
820 store_size(b3
, max_objects
);store_size(b4
, total_objects
);
821 printf("#Objects %10s %10s %10s %10s\n",
824 store_size(b1
, avg_slabs
);store_size(b2
, min_slabs
);
825 store_size(b3
, max_slabs
);store_size(b4
, total_slabs
);
826 printf("#Slabs %10s %10s %10s %10s\n",
829 store_size(b1
, avg_partial
);store_size(b2
, min_partial
);
830 store_size(b3
, max_partial
);store_size(b4
, total_partial
);
831 printf("#PartSlab %10s %10s %10s %10s\n",
833 store_size(b1
, avg_ppart
);store_size(b2
, min_ppart
);
834 store_size(b3
, max_ppart
);
835 store_size(b4
, total_partial
* 100 / total_slabs
);
836 printf("%%PartSlab%10s%% %10s%% %10s%% %10s%%\n",
839 store_size(b1
, avg_partobj
);store_size(b2
, min_partobj
);
840 store_size(b3
, max_partobj
);
841 store_size(b4
, total_partobj
);
842 printf("PartObjs %10s %10s %10s %10s\n",
845 store_size(b1
, avg_ppartobj
);store_size(b2
, min_ppartobj
);
846 store_size(b3
, max_ppartobj
);
847 store_size(b4
, total_partobj
* 100 / total_objects
);
848 printf("%% PartObj%10s%% %10s%% %10s%% %10s%%\n",
851 store_size(b1
, avg_size
);store_size(b2
, min_size
);
852 store_size(b3
, max_size
);store_size(b4
, total_size
);
853 printf("Memory %10s %10s %10s %10s\n",
856 store_size(b1
, avg_used
);store_size(b2
, min_used
);
857 store_size(b3
, max_used
);store_size(b4
, total_used
);
858 printf("Used %10s %10s %10s %10s\n",
861 store_size(b1
, avg_waste
);store_size(b2
, min_waste
);
862 store_size(b3
, max_waste
);store_size(b4
, total_waste
);
863 printf("Loss %10s %10s %10s %10s\n",
867 printf("Per Object Average Min Max\n");
868 printf("---------------------------------------------\n");
870 store_size(b1
, avg_memobj
);store_size(b2
, min_memobj
);
871 store_size(b3
, max_memobj
);
872 printf("Memory %10s %10s %10s\n",
874 store_size(b1
, avg_objsize
);store_size(b2
, min_objsize
);
875 store_size(b3
, max_objsize
);
876 printf("User %10s %10s %10s\n",
879 store_size(b1
, avg_objwaste
);store_size(b2
, min_objwaste
);
880 store_size(b3
, max_objwaste
);
881 printf("Loss %10s %10s %10s\n",
885 void sort_slabs(void)
887 struct slabinfo
*s1
,*s2
;
889 for (s1
= slabinfo
; s1
< slabinfo
+ slabs
; s1
++) {
890 for (s2
= s1
+ 1; s2
< slabinfo
+ slabs
; s2
++) {
894 result
= slab_size(s1
) < slab_size(s2
);
896 result
= strcasecmp(s1
->name
, s2
->name
);
904 memcpy(&t
, s1
, sizeof(struct slabinfo
));
905 memcpy(s1
, s2
, sizeof(struct slabinfo
));
906 memcpy(s2
, &t
, sizeof(struct slabinfo
));
912 void sort_aliases(void)
914 struct aliasinfo
*a1
,*a2
;
916 for (a1
= aliasinfo
; a1
< aliasinfo
+ aliases
; a1
++) {
917 for (a2
= a1
+ 1; a2
< aliasinfo
+ aliases
; a2
++) {
922 if (show_alias
&& !show_inverted
) {
926 if (strcasecmp(n1
, n2
) > 0) {
929 memcpy(&t
, a1
, sizeof(struct aliasinfo
));
930 memcpy(a1
, a2
, sizeof(struct aliasinfo
));
931 memcpy(a2
, &t
, sizeof(struct aliasinfo
));
937 void link_slabs(void)
942 for (a
= aliasinfo
; a
< aliasinfo
+ aliases
; a
++) {
944 for (s
= slabinfo
; s
< slabinfo
+ slabs
; s
++)
945 if (strcmp(a
->ref
, s
->name
) == 0) {
950 if (s
== slabinfo
+ slabs
)
951 fatal("Unresolved alias %s\n", a
->ref
);
963 for(a
= aliasinfo
; a
< aliasinfo
+ aliases
; a
++) {
965 if (!show_single_ref
&& a
->slab
->refs
== 1)
968 if (!show_inverted
) {
970 if (strcmp(a
->slab
->name
, active
) == 0) {
971 printf(" %s", a
->name
);
975 printf("\n%-12s <- %s", a
->slab
->name
, a
->name
);
976 active
= a
->slab
->name
;
979 printf("%-20s -> %s\n", a
->name
, a
->slab
->name
);
986 void rename_slabs(void)
991 for (s
= slabinfo
; s
< slabinfo
+ slabs
; s
++) {
995 if (s
->refs
> 1 && !show_first_alias
)
998 a
= find_one_alias(s
);
1009 int slab_mismatch(char *slab
)
1011 return regexec(&pattern
, slab
, 0, NULL
, 0);
1014 void read_slab_dir(void)
1018 struct slabinfo
*slab
= slabinfo
;
1019 struct aliasinfo
*alias
= aliasinfo
;
1024 if (chdir("/sys/kernel/slab"))
1025 fatal("SYSFS support for SLUB not active\n");
1028 while ((de
= readdir(dir
))) {
1029 if (de
->d_name
[0] == '.' ||
1030 (de
->d_name
[0] != ':' && slab_mismatch(de
->d_name
)))
1032 switch (de
->d_type
) {
1034 alias
->name
= strdup(de
->d_name
);
1035 count
= readlink(de
->d_name
, buffer
, sizeof(buffer
));
1038 fatal("Cannot read symlink %s\n", de
->d_name
);
1042 while (p
> buffer
&& p
[-1] != '/')
1044 alias
->ref
= strdup(p
);
1048 if (chdir(de
->d_name
))
1049 fatal("Unable to access slab %s\n", slab
->name
);
1050 slab
->name
= strdup(de
->d_name
);
1053 slab
->aliases
= get_obj("aliases");
1054 slab
->align
= get_obj("align");
1055 slab
->cache_dma
= get_obj("cache_dma");
1056 slab
->cpu_slabs
= get_obj("cpu_slabs");
1057 slab
->destroy_by_rcu
= get_obj("destroy_by_rcu");
1058 slab
->hwcache_align
= get_obj("hwcache_align");
1059 slab
->object_size
= get_obj("object_size");
1060 slab
->objects
= get_obj("objects");
1061 slab
->objs_per_slab
= get_obj("objs_per_slab");
1062 slab
->order
= get_obj("order");
1063 slab
->partial
= get_obj("partial");
1064 slab
->partial
= get_obj_and_str("partial", &t
);
1065 decode_numa_list(slab
->numa_partial
, t
);
1067 slab
->poison
= get_obj("poison");
1068 slab
->reclaim_account
= get_obj("reclaim_account");
1069 slab
->red_zone
= get_obj("red_zone");
1070 slab
->sanity_checks
= get_obj("sanity_checks");
1071 slab
->slab_size
= get_obj("slab_size");
1072 slab
->slabs
= get_obj_and_str("slabs", &t
);
1073 decode_numa_list(slab
->numa
, t
);
1075 slab
->store_user
= get_obj("store_user");
1076 slab
->trace
= get_obj("trace");
1078 if (slab
->name
[0] == ':')
1083 fatal("Unknown file type %lx\n", de
->d_type
);
1087 slabs
= slab
- slabinfo
;
1088 actual_slabs
= slabs
;
1089 aliases
= alias
- aliasinfo
;
1090 if (slabs
> MAX_SLABS
)
1091 fatal("Too many slabs\n");
1092 if (aliases
> MAX_ALIASES
)
1093 fatal("Too many aliases\n");
1096 void output_slabs(void)
1098 struct slabinfo
*slab
;
1100 for (slab
= slabinfo
; slab
< slabinfo
+ slabs
; slab
++) {
1108 else if (show_track
)
1109 show_tracking(slab
);
1111 slab_validate(slab
);
1120 else if (show_report
)
1125 struct option opts
[] = {
1126 { "aliases", 0, NULL
, 'a' },
1127 { "debug", 2, NULL
, 'd' },
1128 { "empty", 0, NULL
, 'e' },
1129 { "first-alias", 0, NULL
, 'f' },
1130 { "help", 0, NULL
, 'h' },
1131 { "inverted", 0, NULL
, 'i'},
1132 { "numa", 0, NULL
, 'n' },
1133 { "ops", 0, NULL
, 'o' },
1134 { "report", 0, NULL
, 'r' },
1135 { "shrink", 0, NULL
, 's' },
1136 { "slabs", 0, NULL
, 'l' },
1137 { "track", 0, NULL
, 't'},
1138 { "validate", 0, NULL
, 'v' },
1139 { "zero", 0, NULL
, 'z' },
1140 { "1ref", 0, NULL
, '1'},
1141 { NULL
, 0, NULL
, 0 }
1144 int main(int argc
, char *argv
[])
1148 char *pattern_source
;
1150 page_size
= getpagesize();
1152 while ((c
= getopt_long(argc
, argv
, "ad::efhil1noprstvzTS",
1156 show_single_ref
= 1;
1163 if (!debug_opt_scan(optarg
))
1164 fatal("Invalid debug option '%s'\n", optarg
);
1170 show_first_alias
= 1;
1210 fatal("%s: Invalid option '%c'\n", argv
[0], optopt
);
1214 if (!show_slab
&& !show_alias
&& !show_track
&& !show_report
1215 && !validate
&& !shrink
&& !set_debug
&& !show_ops
)
1219 pattern_source
= argv
[optind
];
1221 pattern_source
= ".*";
1223 err
= regcomp(&pattern
, pattern_source
, REG_ICASE
|REG_NOSUB
);
1225 fatal("%s: Invalid pattern '%s' code %d\n",
1226 argv
[0], pattern_source
, err
);