Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[pandora-kernel.git] / Documentation / vm / slabinfo.c
index 686a8e0..488c1f3 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <dirent.h>
+#include <strings.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdarg.h>
@@ -84,7 +85,7 @@ void fatal(const char *x, ...)
        va_start(ap, x);
        vfprintf(stderr, x, ap);
        va_end(ap);
-       exit(1);
+       exit(EXIT_FAILURE);
 }
 
 void usage(void)
@@ -119,14 +120,14 @@ void usage(void)
        );
 }
 
-unsigned long read_obj(char *name)
+unsigned long read_obj(const char *name)
 {
        FILE *f = fopen(name, "r");
 
        if (!f)
                buffer[0] = 0;
        else {
-               if (!fgets(buffer,sizeof(buffer), f))
+               if (!fgets(buffer, sizeof(buffer), f))
                        buffer[0] = 0;
                fclose(f);
                if (buffer[strlen(buffer)] == '\n')
@@ -139,7 +140,7 @@ unsigned long read_obj(char *name)
 /*
  * Get the contents of an attribute
  */
-unsigned long get_obj(char *name)
+unsigned long get_obj(const char *name)
 {
        if (!read_obj(name))
                return 0;
@@ -147,7 +148,7 @@ unsigned long get_obj(char *name)
        return atol(buffer);
 }
 
-unsigned long get_obj_and_str(char *name, char **x)
+unsigned long get_obj_and_str(const char *name, char **x)
 {
        unsigned long result = 0;
        char *p;
@@ -166,12 +167,12 @@ unsigned long get_obj_and_str(char *name, char **x)
        return result;
 }
 
-void set_obj(struct slabinfo *s, char *name, int n)
+void set_obj(struct slabinfo *s, const char *name, int n)
 {
        char x[100];
        FILE *f;
 
-       sprintf(x, "%s/%s", s->name, name);
+       snprintf(x, 100, "%s/%s", s->name, name);
        f = fopen(x, "w");
        if (!f)
                fatal("Cannot write to %s\n", x);
@@ -180,13 +181,13 @@ void set_obj(struct slabinfo *s, char *name, int n)
        fclose(f);
 }
 
-unsigned long read_slab_obj(struct slabinfo *s, char *name)
+unsigned long read_slab_obj(struct slabinfo *s, const char *name)
 {
        char x[100];
        FILE *f;
-       int l;
+       size_t l;
 
-       sprintf(x, "%s/%s", s->name, name);
+       snprintf(x, 100, "%s/%s", s->name, name);
        f = fopen(x, "r");
        if (!f) {
                buffer[0] = 0;
@@ -242,6 +243,9 @@ void decode_numa_list(int *numa, char *t)
 
        memset(numa, 0, MAX_NODES * sizeof(int));
 
+       if (!t)
+               return;
+
        while (*t == 'N') {
                t++;
                node = strtoul(t, &t, 10);
@@ -259,11 +263,17 @@ void decode_numa_list(int *numa, char *t)
 
 void slab_validate(struct slabinfo *s)
 {
+       if (strcmp(s->name, "*") == 0)
+               return;
+
        set_obj(s, "validate", 1);
 }
 
 void slab_shrink(struct slabinfo *s)
 {
+       if (strcmp(s->name, "*") == 0)
+               return;
+
        set_obj(s, "shrink", 1);
 }
 
@@ -386,7 +396,9 @@ void report(struct slabinfo *s)
 {
        if (strcmp(s->name, "*") == 0)
                return;
-       printf("\nSlabcache: %-20s  Aliases: %2d Order : %2d\n", s->name, s->aliases, s->order);
+
+       printf("\nSlabcache: %-20s  Aliases: %2d Order : %2d Objects: %lu\n",
+               s->name, s->aliases, s->order, s->objects);
        if (s->hwcache_align)
                printf("** Hardware cacheline aligned\n");
        if (s->cache_dma)
@@ -442,7 +454,7 @@ void slabcache(struct slabinfo *s)
                return;
 
        store_size(size_str, slab_size(s));
-       sprintf(dist_str,"%lu/%lu/%d", s->slabs, s->partial, s->cpu_slabs);
+       snprintf(dist_str, 40, "%lu/%lu/%d", s->slabs, s->partial, s->cpu_slabs);
 
        if (!line++)
                first_line();
@@ -545,6 +557,9 @@ int slab_empty(struct slabinfo *s)
 
 void slab_debug(struct slabinfo *s)
 {
+       if (strcmp(s->name, "*") == 0)
+               return;
+
        if (sanity && !s->sanity_checks) {
                set_obj(s, "sanity", 1);
        }
@@ -791,11 +806,11 @@ void totals(void)
 
        store_size(b1, total_size);store_size(b2, total_waste);
        store_size(b3, total_waste * 100 / total_used);
-       printf("Memory used: %6s   # Loss   : %6s   MRatio: %6s%%\n", b1, b2, b3);
+       printf("Memory used: %6s   # Loss   : %6s   MRatio:%6s%%\n", b1, b2, b3);
 
        store_size(b1, total_objects);store_size(b2, total_partobj);
        store_size(b3, total_partobj * 100 / total_objects);
-       printf("# Objects  : %6s   # PartObj: %6s   ORatio: %6s%%\n", b1, b2, b3);
+       printf("# Objects  : %6s   # PartObj: %6s   ORatio:%6s%%\n", b1, b2, b3);
 
        printf("\n");
        printf("Per Cache    Average         Min         Max       Total\n");
@@ -818,7 +833,7 @@ void totals(void)
        store_size(b1, avg_ppart);store_size(b2, min_ppart);
        store_size(b3, max_ppart);
        store_size(b4, total_partial * 100  / total_slabs);
-       printf("%%PartSlab %10s%% %10s%% %10s%% %10s%%\n",
+       printf("%%PartSlab%10s%% %10s%% %10s%% %10s%%\n",
                        b1,     b2,     b3,     b4);
 
        store_size(b1, avg_partobj);store_size(b2, min_partobj);
@@ -830,7 +845,7 @@ void totals(void)
        store_size(b1, avg_ppartobj);store_size(b2, min_ppartobj);
        store_size(b3, max_ppartobj);
        store_size(b4, total_partobj * 100 / total_objects);
-       printf("%% PartObj %10s%% %10s%% %10s%% %10s%%\n",
+       printf("%% PartObj%10s%% %10s%% %10s%% %10s%%\n",
                        b1,     b2,     b3,     b4);
 
        store_size(b1, avg_size);store_size(b2, min_size);
@@ -1006,7 +1021,7 @@ void read_slab_dir(void)
        char *t;
        int count;
 
-       if (chdir("/sys/slab"))
+       if (chdir("/sys/kernel/slab"))
                fatal("SYSFS support for SLUB not active\n");
 
        dir = opendir(".");
@@ -1048,6 +1063,7 @@ void read_slab_dir(void)
                        slab->partial = get_obj("partial");
                        slab->partial = get_obj_and_str("partial", &t);
                        decode_numa_list(slab->numa_partial, t);
+                       free(t);
                        slab->poison = get_obj("poison");
                        slab->reclaim_account = get_obj("reclaim_account");
                        slab->red_zone = get_obj("red_zone");
@@ -1055,6 +1071,7 @@ void read_slab_dir(void)
                        slab->slab_size = get_obj("slab_size");
                        slab->slabs = get_obj_and_str("slabs", &t);
                        decode_numa_list(slab->numa, t);
+                       free(t);
                        slab->store_user = get_obj("store_user");
                        slab->trace = get_obj("trace");
                        chdir("..");
@@ -1100,6 +1117,8 @@ void output_slabs(void)
                        ops(slab);
                else if (show_slab)
                        slabcache(slab);
+               else if (show_report)
+                       report(slab);
        }
 }
 
@@ -1132,7 +1151,7 @@ int main(int argc, char *argv[])
 
        while ((c = getopt_long(argc, argv, "ad::efhil1noprstvzTS",
                                                opts, NULL)) != -1)
-       switch(c) {
+               switch (c) {
                case '1':
                        show_single_ref = 1;
                        break;