Skip to content

Commit a8ea0bf

Browse files
sergey-senozhatskytorvalds
authored andcommitted
tools/vm/slabinfo: output sizes in bytes
Introduce "-B|--Bytes" opt to disable store_size() dynamic size scaling and report size in bytes instead. This `expands' the interface a bit, it's impossible to use printf("%6s") anymore to output sizes. Example: slabinfo -X -N 2 Slabcache Totals ---------------- Slabcaches : 91 Aliases : 119->69 Active: 63 Memory used: 199798784 # Loss : 10689376 MRatio: 5% # Objects : 324301 # PartObj: 18151 ORatio: 5% Per Cache Average Min Max Total ---------------------------------------------------------------------------- #Objects 5147 1 89068 324301 #Slabs 199 1 3886 12537 #PartSlab 12 0 240 778 %PartSlab 32% 0% 100% 6% PartObjs 5 0 4569 18151 % PartObj 26% 0% 100% 5% Memory 3171409 8192 127336448 199798784 Used 3001736 160 121429728 189109408 Loss 169672 0 5906720 10689376 Per Object Average Min Max ----------------------------------------------------------- Memory 585 8 8192 User 583 8 8192 Loss 2 0 64 Slabs sorted by size -------------------- Name Objects Objsize Space Slabs/Part/Cpu O/S O %Fr %Ef Flg ext4_inode_cache 69948 1736 127336448 3871/0/15 18 3 0 95 a dentry 89068 288 26058752 3164/0/17 28 1 0 98 a Slabs sorted by loss -------------------- Name Objects Objsize Loss Slabs/Part/Cpu O/S O %Fr %Ef Flg ext4_inode_cache 69948 1736 5906720 3871/0/15 18 3 0 95 a inode_cache 11628 864 537472 642/0/4 18 2 0 94 a Besides, store_size() does not use powers of two for G/M/K if (value > 1000000000UL) { divisor = 100000000UL; trailer = 'G'; } else if (value > 1000000UL) { divisor = 100000UL; trailer = 'M'; } else if (value > 1000UL) { divisor = 100; trailer = 'K'; } Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 016c6cd commit a8ea0bf

1 file changed

Lines changed: 51 additions & 37 deletions

File tree

‎tools/vm/slabinfo.c‎

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ int show_activity = 0;
8282
int output_lines = -1;
8383
int sort_loss;
8484
int extended_totals;
85+
int show_bytes;
8586

8687
/* Debug options */
8788
int sanity = 0;
@@ -130,6 +131,7 @@ static void usage(void)
130131
"-N|--lines=K Show the first K slabs\n"
131132
"-L|--Loss Sort by loss\n"
132133
"-X|--Xtotals Show extended summary information\n"
134+
"-B|--Bytes Show size in bytes\n"
133135
"\nValid debug options (FZPUT may be combined)\n"
134136
"a / A Switch on all debug options (=FZUP)\n"
135137
"- Switch off all debug options\n"
@@ -231,15 +233,17 @@ static int store_size(char *buffer, unsigned long value)
231233
char trailer = 0;
232234
int n;
233235

234-
if (value > 1000000000UL) {
235-
divisor = 100000000UL;
236-
trailer = 'G';
237-
} else if (value > 1000000UL) {
238-
divisor = 100000UL;
239-
trailer = 'M';
240-
} else if (value > 1000UL) {
241-
divisor = 100;
242-
trailer = 'K';
236+
if (!show_bytes) {
237+
if (value > 1000000000UL) {
238+
divisor = 100000000UL;
239+
trailer = 'G';
240+
} else if (value > 1000000UL) {
241+
divisor = 100000UL;
242+
trailer = 'M';
243+
} else if (value > 1000UL) {
244+
divisor = 100;
245+
trailer = 'K';
246+
}
243247
}
244248

245249
value /= divisor;
@@ -303,11 +307,12 @@ int line = 0;
303307
static void first_line(void)
304308
{
305309
if (show_activity)
306-
printf("Name Objects Alloc Free %%Fast Fallb O CmpX UL\n");
310+
printf("Name Objects Alloc Free"
311+
" %%Fast Fallb O CmpX UL\n");
307312
else
308-
printf("Name Objects Objsize %s "
313+
printf("Name Objects Objsize %s "
309314
"Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n",
310-
sort_loss ? "Loss" : "Space");
315+
sort_loss ? " Loss" : "Space");
311316
}
312317

313318
/*
@@ -516,7 +521,7 @@ static void report(struct slabinfo *s)
516521
if (strcmp(s->name, "*") == 0)
517522
return;
518523

519-
printf("\nSlabcache: %-20s Aliases: %2d Order : %2d Objects: %lu\n",
524+
printf("\nSlabcache: %-15s Aliases: %2d Order : %2d Objects: %lu\n",
520525
s->name, s->aliases, s->order, s->objects);
521526
if (s->hwcache_align)
522527
printf("** Hardware cacheline aligned\n");
@@ -618,7 +623,7 @@ static void slabcache(struct slabinfo *s)
618623
s->order_fallback, s->order, s->cmpxchg_double_fail,
619624
s->cmpxchg_double_cpu_fail);
620625
} else {
621-
printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n",
626+
printf("%-21s %8ld %7d %15s %14s %4d %1d %3ld %3ld %s\n",
622627
s->name, s->objects, s->object_size, size_str, dist_str,
623628
s->objs_per_slab, s->order,
624629
s->slabs ? (s->partial * 100) / s->slabs : 100,
@@ -933,84 +938,88 @@ static void totals(void)
933938

934939
printf("Slabcache Totals\n");
935940
printf("----------------\n");
936-
printf("Slabcaches : %3d Aliases : %3d->%-3d Active: %3d\n",
941+
printf("Slabcaches : %15d Aliases : %11d->%-3d Active: %3d\n",
937942
slabs, aliases, alias_targets, used_slabs);
938943

939944
store_size(b1, total_size);store_size(b2, total_waste);
940945
store_size(b3, total_waste * 100 / total_used);
941-
printf("Memory used: %6s # Loss : %6s MRatio:%6s%%\n", b1, b2, b3);
946+
printf("Memory used: %15s # Loss : %15s MRatio:%6s%%\n", b1, b2, b3);
942947

943948
store_size(b1, total_objects);store_size(b2, total_partobj);
944949
store_size(b3, total_partobj * 100 / total_objects);
945-
printf("# Objects : %6s # PartObj: %6s ORatio:%6s%%\n", b1, b2, b3);
950+
printf("# Objects : %15s # PartObj: %15s ORatio:%6s%%\n", b1, b2, b3);
946951

947952
printf("\n");
948-
printf("Per Cache Average Min Max Total\n");
949-
printf("---------------------------------------------------------\n");
953+
printf("Per Cache Average "
954+
"Min Max Total\n");
955+
printf("---------------------------------------"
956+
"-------------------------------------\n");
950957

951958
store_size(b1, avg_objects);store_size(b2, min_objects);
952959
store_size(b3, max_objects);store_size(b4, total_objects);
953-
printf("#Objects %10s %10s %10s %10s\n",
960+
printf("#Objects %15s %15s %15s %15s\n",
954961
b1, b2, b3, b4);
955962

956963
store_size(b1, avg_slabs);store_size(b2, min_slabs);
957964
store_size(b3, max_slabs);store_size(b4, total_slabs);
958-
printf("#Slabs %10s %10s %10s %10s\n",
965+
printf("#Slabs %15s %15s %15s %15s\n",
959966
b1, b2, b3, b4);
960967

961968
store_size(b1, avg_partial);store_size(b2, min_partial);
962969
store_size(b3, max_partial);store_size(b4, total_partial);
963-
printf("#PartSlab %10s %10s %10s %10s\n",
970+
printf("#PartSlab %15s %15s %15s %15s\n",
964971
b1, b2, b3, b4);
965972
store_size(b1, avg_ppart);store_size(b2, min_ppart);
966973
store_size(b3, max_ppart);
967974
store_size(b4, total_partial * 100 / total_slabs);
968-
printf("%%PartSlab%10s%% %10s%% %10s%% %10s%%\n",
975+
printf("%%PartSlab%15s%% %15s%% %15s%% %15s%%\n",
969976
b1, b2, b3, b4);
970977

971978
store_size(b1, avg_partobj);store_size(b2, min_partobj);
972979
store_size(b3, max_partobj);
973980
store_size(b4, total_partobj);
974-
printf("PartObjs %10s %10s %10s %10s\n",
981+
printf("PartObjs %15s %15s %15s %15s\n",
975982
b1, b2, b3, b4);
976983

977984
store_size(b1, avg_ppartobj);store_size(b2, min_ppartobj);
978985
store_size(b3, max_ppartobj);
979986
store_size(b4, total_partobj * 100 / total_objects);
980-
printf("%% PartObj%10s%% %10s%% %10s%% %10s%%\n",
987+
printf("%% PartObj%15s%% %15s%% %15s%% %15s%%\n",
981988
b1, b2, b3, b4);
982989

983990
store_size(b1, avg_size);store_size(b2, min_size);
984991
store_size(b3, max_size);store_size(b4, total_size);
985-
printf("Memory %10s %10s %10s %10s\n",
992+
printf("Memory %15s %15s %15s %15s\n",
986993
b1, b2, b3, b4);
987994

988995
store_size(b1, avg_used);store_size(b2, min_used);
989996
store_size(b3, max_used);store_size(b4, total_used);
990-
printf("Used %10s %10s %10s %10s\n",
997+
printf("Used %15s %15s %15s %15s\n",
991998
b1, b2, b3, b4);
992999

9931000
store_size(b1, avg_waste);store_size(b2, min_waste);
9941001
store_size(b3, max_waste);store_size(b4, total_waste);
995-
printf("Loss %10s %10s %10s %10s\n",
1002+
printf("Loss %15s %15s %15s %15s\n",
9961003
b1, b2, b3, b4);
9971004

9981005
printf("\n");
999-
printf("Per Object Average Min Max\n");
1000-
printf("---------------------------------------------\n");
1006+
printf("Per Object Average "
1007+
"Min Max\n");
1008+
printf("---------------------------------------"
1009+
"--------------------\n");
10011010

10021011
store_size(b1, avg_memobj);store_size(b2, min_memobj);
10031012
store_size(b3, max_memobj);
1004-
printf("Memory %10s %10s %10s\n",
1013+
printf("Memory %15s %15s %15s\n",
10051014
b1, b2, b3);
10061015
store_size(b1, avg_objsize);store_size(b2, min_objsize);
10071016
store_size(b3, max_objsize);
1008-
printf("User %10s %10s %10s\n",
1017+
printf("User %15s %15s %15s\n",
10091018
b1, b2, b3);
10101019

10111020
store_size(b1, avg_objwaste);store_size(b2, min_objwaste);
10121021
store_size(b3, max_objwaste);
1013-
printf("Loss %10s %10s %10s\n",
1022+
printf("Loss %15s %15s %15s\n",
10141023
b1, b2, b3);
10151024
}
10161025

@@ -1112,7 +1121,7 @@ static void alias(void)
11121121
active = a->slab->name;
11131122
}
11141123
else
1115-
printf("%-20s -> %s\n", a->name, a->slab->name);
1124+
printf("%-15s -> %s\n", a->name, a->slab->name);
11161125
}
11171126
if (active)
11181127
printf("\n");
@@ -1296,14 +1305,14 @@ static void xtotals(void)
12961305
rename_slabs();
12971306

12981307
printf("\nSlabs sorted by size\n");
1299-
printf("----------------------\n");
1308+
printf("--------------------\n");
13001309
sort_loss = 0;
13011310
sort_size = 1;
13021311
sort_slabs();
13031312
output_slabs();
13041313

13051314
printf("\nSlabs sorted by loss\n");
1306-
printf("----------------------\n");
1315+
printf("--------------------\n");
13071316
line = 0;
13081317
sort_loss = 1;
13091318
sort_size = 0;
@@ -1335,6 +1344,7 @@ struct option opts[] = {
13351344
{ "lines", required_argument, NULL, 'N'},
13361345
{ "Loss", no_argument, NULL, 'L'},
13371346
{ "Xtotals", no_argument, NULL, 'X'},
1347+
{ "Bytes", no_argument, NULL, 'B'},
13381348
{ NULL, 0, NULL, 0 }
13391349
};
13401350

@@ -1346,7 +1356,7 @@ int main(int argc, char *argv[])
13461356

13471357
page_size = getpagesize();
13481358

1349-
while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTSN:LX",
1359+
while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTSN:LXB",
13501360
opts, NULL)) != -1)
13511361
switch (c) {
13521362
case '1':
@@ -1422,6 +1432,10 @@ int main(int argc, char *argv[])
14221432
if (output_lines == -1)
14231433
output_lines = 1;
14241434
extended_totals = 1;
1435+
show_bytes = 1;
1436+
break;
1437+
case 'B':
1438+
show_bytes = 1;
14251439
break;
14261440
default:
14271441
fatal("%s: Invalid option '%c'\n", argv[0], optopt);

0 commit comments

Comments
 (0)