slabinfo.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. /*
  2. * Slabinfo: Tool to get reports about slabs
  3. *
  4. * (C) 2007 sgi, Christoph Lameter
  5. * (C) 2011 Linux Foundation, Christoph Lameter
  6. *
  7. * Compile with:
  8. *
  9. * gcc -o slabinfo slabinfo.c
  10. */
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <sys/types.h>
  14. #include <dirent.h>
  15. #include <strings.h>
  16. #include <string.h>
  17. #include <unistd.h>
  18. #include <stdarg.h>
  19. #include <getopt.h>
  20. #include <regex.h>
  21. #include <errno.h>
  22. #define MAX_SLABS 500
  23. #define MAX_ALIASES 500
  24. #define MAX_NODES 1024
  25. struct slabinfo {
  26. char *name;
  27. int alias;
  28. int refs;
  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, objects_partial, objects_total;
  34. unsigned long alloc_fastpath, alloc_slowpath;
  35. unsigned long free_fastpath, free_slowpath;
  36. unsigned long free_frozen, free_add_partial, free_remove_partial;
  37. unsigned long alloc_from_partial, alloc_slab, free_slab, alloc_refill;
  38. unsigned long cpuslab_flush, deactivate_full, deactivate_empty;
  39. unsigned long deactivate_to_head, deactivate_to_tail;
  40. unsigned long deactivate_remote_frees, order_fallback;
  41. unsigned long cmpxchg_double_cpu_fail, cmpxchg_double_fail;
  42. unsigned long alloc_node_mismatch, deactivate_bypass;
  43. unsigned long cpu_partial_alloc, cpu_partial_free;
  44. int numa[MAX_NODES];
  45. int numa_partial[MAX_NODES];
  46. } slabinfo[MAX_SLABS];
  47. struct aliasinfo {
  48. char *name;
  49. char *ref;
  50. struct slabinfo *slab;
  51. } aliasinfo[MAX_ALIASES];
  52. int slabs = 0;
  53. int actual_slabs = 0;
  54. int aliases = 0;
  55. int alias_targets = 0;
  56. int highest_node = 0;
  57. char buffer[4096];
  58. int show_empty = 0;
  59. int show_report = 0;
  60. int show_alias = 0;
  61. int show_slab = 0;
  62. int skip_zero = 1;
  63. int show_numa = 0;
  64. int show_track = 0;
  65. int show_first_alias = 0;
  66. int validate = 0;
  67. int shrink = 0;
  68. int show_inverted = 0;
  69. int show_single_ref = 0;
  70. int show_totals = 0;
  71. int sort_size = 0;
  72. int sort_active = 0;
  73. int set_debug = 0;
  74. int show_ops = 0;
  75. int show_activity = 0;
  76. /* Debug options */
  77. int sanity = 0;
  78. int redzone = 0;
  79. int poison = 0;
  80. int tracking = 0;
  81. int tracing = 0;
  82. int page_size;
  83. regex_t pattern;
  84. static void fatal(const char *x, ...)
  85. {
  86. va_list ap;
  87. va_start(ap, x);
  88. vfprintf(stderr, x, ap);
  89. va_end(ap);
  90. exit(EXIT_FAILURE);
  91. }
  92. static void usage(void)
  93. {
  94. printf("slabinfo 4/15/2011. (c) 2007 sgi/(c) 2011 Linux Foundation.\n\n"
  95. "slabinfo [-ahnpvtsz] [-d debugopts] [slab-regexp]\n"
  96. "-a|--aliases Show aliases\n"
  97. "-A|--activity Most active slabs first\n"
  98. "-d<options>|--debug=<options> Set/Clear Debug options\n"
  99. "-D|--display-active Switch line format to activity\n"
  100. "-e|--empty Show empty slabs\n"
  101. "-f|--first-alias Show first alias\n"
  102. "-h|--help Show usage information\n"
  103. "-i|--inverted Inverted list\n"
  104. "-l|--slabs Show slabs\n"
  105. "-n|--numa Show NUMA information\n"
  106. "-o|--ops Show kmem_cache_ops\n"
  107. "-s|--shrink Shrink slabs\n"
  108. "-r|--report Detailed report on single slabs\n"
  109. "-S|--Size Sort by size\n"
  110. "-t|--tracking Show alloc/free information\n"
  111. "-T|--Totals Show summary information\n"
  112. "-v|--validate Validate slabs\n"
  113. "-z|--zero Include empty slabs\n"
  114. "-1|--1ref Single reference\n"
  115. "\nValid debug options (FZPUT may be combined)\n"
  116. "a / A Switch on all debug options (=FZUP)\n"
  117. "- Switch off all debug options\n"
  118. "f / F Sanity Checks (SLAB_DEBUG_FREE)\n"
  119. "z / Z Redzoning\n"
  120. "p / P Poisoning\n"
  121. "u / U Tracking\n"
  122. "t / T Tracing\n"
  123. );
  124. }
  125. static unsigned long read_obj(const char *name)
  126. {
  127. FILE *f = fopen(name, "r");
  128. if (!f)
  129. buffer[0] = 0;
  130. else {
  131. if (!fgets(buffer, sizeof(buffer), f))
  132. buffer[0] = 0;
  133. fclose(f);
  134. if (buffer[strlen(buffer)] == '\n')
  135. buffer[strlen(buffer)] = 0;
  136. }
  137. return strlen(buffer);
  138. }
  139. /*
  140. * Get the contents of an attribute
  141. */
  142. static unsigned long get_obj(const char *name)
  143. {
  144. if (!read_obj(name))
  145. return 0;
  146. return atol(buffer);
  147. }
  148. static unsigned long get_obj_and_str(const char *name, char **x)
  149. {
  150. unsigned long result = 0;
  151. char *p;
  152. *x = NULL;
  153. if (!read_obj(name)) {
  154. x = NULL;
  155. return 0;
  156. }
  157. result = strtoul(buffer, &p, 10);
  158. while (*p == ' ')
  159. p++;
  160. if (*p)
  161. *x = strdup(p);
  162. return result;
  163. }
  164. static void set_obj(struct slabinfo *s, const char *name, int n)
  165. {
  166. char x[100];
  167. FILE *f;
  168. snprintf(x, 100, "%s/%s", s->name, name);
  169. f = fopen(x, "w");
  170. if (!f)
  171. fatal("Cannot write to %s\n", x);
  172. fprintf(f, "%d\n", n);
  173. fclose(f);
  174. }
  175. static unsigned long read_slab_obj(struct slabinfo *s, const char *name)
  176. {
  177. char x[100];
  178. FILE *f;
  179. size_t l;
  180. snprintf(x, 100, "%s/%s", s->name, name);
  181. f = fopen(x, "r");
  182. if (!f) {
  183. buffer[0] = 0;
  184. l = 0;
  185. } else {
  186. l = fread(buffer, 1, sizeof(buffer), f);
  187. buffer[l] = 0;
  188. fclose(f);
  189. }
  190. return l;
  191. }
  192. /*
  193. * Put a size string together
  194. */
  195. static int store_size(char *buffer, unsigned long value)
  196. {
  197. unsigned long divisor = 1;
  198. char trailer = 0;
  199. int n;
  200. if (value > 1000000000UL) {
  201. divisor = 100000000UL;
  202. trailer = 'G';
  203. } else if (value > 1000000UL) {
  204. divisor = 100000UL;
  205. trailer = 'M';
  206. } else if (value > 1000UL) {
  207. divisor = 100;
  208. trailer = 'K';
  209. }
  210. value /= divisor;
  211. n = sprintf(buffer, "%ld",value);
  212. if (trailer) {
  213. buffer[n] = trailer;
  214. n++;
  215. buffer[n] = 0;
  216. }
  217. if (divisor != 1) {
  218. memmove(buffer + n - 2, buffer + n - 3, 4);
  219. buffer[n-2] = '.';
  220. n++;
  221. }
  222. return n;
  223. }
  224. static void decode_numa_list(int *numa, char *t)
  225. {
  226. int node;
  227. int nr;
  228. memset(numa, 0, MAX_NODES * sizeof(int));
  229. if (!t)
  230. return;
  231. while (*t == 'N') {
  232. t++;
  233. node = strtoul(t, &t, 10);
  234. if (*t == '=') {
  235. t++;
  236. nr = strtoul(t, &t, 10);
  237. numa[node] = nr;
  238. if (node > highest_node)
  239. highest_node = node;
  240. }
  241. while (*t == ' ')
  242. t++;
  243. }
  244. }
  245. static void slab_validate(struct slabinfo *s)
  246. {
  247. if (strcmp(s->name, "*") == 0)
  248. return;
  249. set_obj(s, "validate", 1);
  250. }
  251. static void slab_shrink(struct slabinfo *s)
  252. {
  253. if (strcmp(s->name, "*") == 0)
  254. return;
  255. set_obj(s, "shrink", 1);
  256. }
  257. int line = 0;
  258. static void first_line(void)
  259. {
  260. if (show_activity)
  261. printf("Name Objects Alloc Free %%Fast Fallb O CmpX UL\n");
  262. else
  263. printf("Name Objects Objsize Space "
  264. "Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n");
  265. }
  266. /*
  267. * Find the shortest alias of a slab
  268. */
  269. static struct aliasinfo *find_one_alias(struct slabinfo *find)
  270. {
  271. struct aliasinfo *a;
  272. struct aliasinfo *best = NULL;
  273. for(a = aliasinfo;a < aliasinfo + aliases; a++) {
  274. if (a->slab == find &&
  275. (!best || strlen(best->name) < strlen(a->name))) {
  276. best = a;
  277. if (strncmp(a->name,"kmall", 5) == 0)
  278. return best;
  279. }
  280. }
  281. return best;
  282. }
  283. static unsigned long slab_size(struct slabinfo *s)
  284. {
  285. return s->slabs * (page_size << s->order);
  286. }
  287. static unsigned long slab_activity(struct slabinfo *s)
  288. {
  289. return s->alloc_fastpath + s->free_fastpath +
  290. s->alloc_slowpath + s->free_slowpath;
  291. }
  292. static void slab_numa(struct slabinfo *s, int mode)
  293. {
  294. int node;
  295. if (strcmp(s->name, "*") == 0)
  296. return;
  297. if (!highest_node) {
  298. printf("\n%s: No NUMA information available.\n", s->name);
  299. return;
  300. }
  301. if (skip_zero && !s->slabs)
  302. return;
  303. if (!line) {
  304. printf("\n%-21s:", mode ? "NUMA nodes" : "Slab");
  305. for(node = 0; node <= highest_node; node++)
  306. printf(" %4d", node);
  307. printf("\n----------------------");
  308. for(node = 0; node <= highest_node; node++)
  309. printf("-----");
  310. printf("\n");
  311. }
  312. printf("%-21s ", mode ? "All slabs" : s->name);
  313. for(node = 0; node <= highest_node; node++) {
  314. char b[20];
  315. store_size(b, s->numa[node]);
  316. printf(" %4s", b);
  317. }
  318. printf("\n");
  319. if (mode) {
  320. printf("%-21s ", "Partial slabs");
  321. for(node = 0; node <= highest_node; node++) {
  322. char b[20];
  323. store_size(b, s->numa_partial[node]);
  324. printf(" %4s", b);
  325. }
  326. printf("\n");
  327. }
  328. line++;
  329. }
  330. static void show_tracking(struct slabinfo *s)
  331. {
  332. printf("\n%s: Kernel object allocation\n", s->name);
  333. printf("-----------------------------------------------------------------------\n");
  334. if (read_slab_obj(s, "alloc_calls"))
  335. printf("%s", buffer);
  336. else
  337. printf("No Data\n");
  338. printf("\n%s: Kernel object freeing\n", s->name);
  339. printf("------------------------------------------------------------------------\n");
  340. if (read_slab_obj(s, "free_calls"))
  341. printf("%s", buffer);
  342. else
  343. printf("No Data\n");
  344. }
  345. static void ops(struct slabinfo *s)
  346. {
  347. if (strcmp(s->name, "*") == 0)
  348. return;
  349. if (read_slab_obj(s, "ops")) {
  350. printf("\n%s: kmem_cache operations\n", s->name);
  351. printf("--------------------------------------------\n");
  352. printf("%s", buffer);
  353. } else
  354. printf("\n%s has no kmem_cache operations\n", s->name);
  355. }
  356. static const char *onoff(int x)
  357. {
  358. if (x)
  359. return "On ";
  360. return "Off";
  361. }
  362. static void slab_stats(struct slabinfo *s)
  363. {
  364. unsigned long total_alloc;
  365. unsigned long total_free;
  366. unsigned long total;
  367. if (!s->alloc_slab)
  368. return;
  369. total_alloc = s->alloc_fastpath + s->alloc_slowpath;
  370. total_free = s->free_fastpath + s->free_slowpath;
  371. if (!total_alloc)
  372. return;
  373. printf("\n");
  374. printf("Slab Perf Counter Alloc Free %%Al %%Fr\n");
  375. printf("--------------------------------------------------\n");
  376. printf("Fastpath %8lu %8lu %3lu %3lu\n",
  377. s->alloc_fastpath, s->free_fastpath,
  378. s->alloc_fastpath * 100 / total_alloc,
  379. total_free ? s->free_fastpath * 100 / total_free : 0);
  380. printf("Slowpath %8lu %8lu %3lu %3lu\n",
  381. total_alloc - s->alloc_fastpath, s->free_slowpath,
  382. (total_alloc - s->alloc_fastpath) * 100 / total_alloc,
  383. total_free ? s->free_slowpath * 100 / total_free : 0);
  384. printf("Page Alloc %8lu %8lu %3lu %3lu\n",
  385. s->alloc_slab, s->free_slab,
  386. s->alloc_slab * 100 / total_alloc,
  387. total_free ? s->free_slab * 100 / total_free : 0);
  388. printf("Add partial %8lu %8lu %3lu %3lu\n",
  389. s->deactivate_to_head + s->deactivate_to_tail,
  390. s->free_add_partial,
  391. (s->deactivate_to_head + s->deactivate_to_tail) * 100 / total_alloc,
  392. total_free ? s->free_add_partial * 100 / total_free : 0);
  393. printf("Remove partial %8lu %8lu %3lu %3lu\n",
  394. s->alloc_from_partial, s->free_remove_partial,
  395. s->alloc_from_partial * 100 / total_alloc,
  396. total_free ? s->free_remove_partial * 100 / total_free : 0);
  397. printf("Cpu partial list %8lu %8lu %3lu %3lu\n",
  398. s->cpu_partial_alloc, s->cpu_partial_free,
  399. s->cpu_partial_alloc * 100 / total_alloc,
  400. total_free ? s->cpu_partial_free * 100 / total_free : 0);
  401. printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n",
  402. s->deactivate_remote_frees, s->free_frozen,
  403. s->deactivate_remote_frees * 100 / total_alloc,
  404. total_free ? s->free_frozen * 100 / total_free : 0);
  405. printf("Total %8lu %8lu\n\n", total_alloc, total_free);
  406. if (s->cpuslab_flush)
  407. printf("Flushes %8lu\n", s->cpuslab_flush);
  408. total = s->deactivate_full + s->deactivate_empty +
  409. s->deactivate_to_head + s->deactivate_to_tail + s->deactivate_bypass;
  410. if (total) {
  411. printf("\nSlab Deactivation Ocurrences %%\n");
  412. printf("-------------------------------------------------\n");
  413. printf("Slab full %7lu %3lu%%\n",
  414. s->deactivate_full, (s->deactivate_full * 100) / total);
  415. printf("Slab empty %7lu %3lu%%\n",
  416. s->deactivate_empty, (s->deactivate_empty * 100) / total);
  417. printf("Moved to head of partial list %7lu %3lu%%\n",
  418. s->deactivate_to_head, (s->deactivate_to_head * 100) / total);
  419. printf("Moved to tail of partial list %7lu %3lu%%\n",
  420. s->deactivate_to_tail, (s->deactivate_to_tail * 100) / total);
  421. printf("Deactivation bypass %7lu %3lu%%\n",
  422. s->deactivate_bypass, (s->deactivate_bypass * 100) / total);
  423. printf("Refilled from foreign frees %7lu %3lu%%\n",
  424. s->alloc_refill, (s->alloc_refill * 100) / total);
  425. printf("Node mismatch %7lu %3lu%%\n",
  426. s->alloc_node_mismatch, (s->alloc_node_mismatch * 100) / total);
  427. }
  428. if (s->cmpxchg_double_fail || s->cmpxchg_double_cpu_fail)
  429. printf("\nCmpxchg_double Looping\n------------------------\n");
  430. printf("Locked Cmpxchg Double redos %lu\nUnlocked Cmpxchg Double redos %lu\n",
  431. s->cmpxchg_double_fail, s->cmpxchg_double_cpu_fail);
  432. }
  433. static void report(struct slabinfo *s)
  434. {
  435. if (strcmp(s->name, "*") == 0)
  436. return;
  437. printf("\nSlabcache: %-20s Aliases: %2d Order : %2d Objects: %lu\n",
  438. s->name, s->aliases, s->order, s->objects);
  439. if (s->hwcache_align)
  440. printf("** Hardware cacheline aligned\n");
  441. if (s->cache_dma)
  442. printf("** Memory is allocated in a special DMA zone\n");
  443. if (s->destroy_by_rcu)
  444. printf("** Slabs are destroyed via RCU\n");
  445. if (s->reclaim_account)
  446. printf("** Reclaim accounting active\n");
  447. printf("\nSizes (bytes) Slabs Debug Memory\n");
  448. printf("------------------------------------------------------------------------\n");
  449. printf("Object : %7d Total : %7ld Sanity Checks : %s Total: %7ld\n",
  450. s->object_size, s->slabs, onoff(s->sanity_checks),
  451. s->slabs * (page_size << s->order));
  452. printf("SlabObj: %7d Full : %7ld Redzoning : %s Used : %7ld\n",
  453. s->slab_size, s->slabs - s->partial - s->cpu_slabs,
  454. onoff(s->red_zone), s->objects * s->object_size);
  455. printf("SlabSiz: %7d Partial: %7ld Poisoning : %s Loss : %7ld\n",
  456. page_size << s->order, s->partial, onoff(s->poison),
  457. s->slabs * (page_size << s->order) - s->objects * s->object_size);
  458. printf("Loss : %7d CpuSlab: %7d Tracking : %s Lalig: %7ld\n",
  459. s->slab_size - s->object_size, s->cpu_slabs, onoff(s->store_user),
  460. (s->slab_size - s->object_size) * s->objects);
  461. printf("Align : %7d Objects: %7d Tracing : %s Lpadd: %7ld\n",
  462. s->align, s->objs_per_slab, onoff(s->trace),
  463. ((page_size << s->order) - s->objs_per_slab * s->slab_size) *
  464. s->slabs);
  465. ops(s);
  466. show_tracking(s);
  467. slab_numa(s, 1);
  468. slab_stats(s);
  469. }
  470. static void slabcache(struct slabinfo *s)
  471. {
  472. char size_str[20];
  473. char dist_str[40];
  474. char flags[20];
  475. char *p = flags;
  476. if (strcmp(s->name, "*") == 0)
  477. return;
  478. if (actual_slabs == 1) {
  479. report(s);
  480. return;
  481. }
  482. if (skip_zero && !show_empty && !s->slabs)
  483. return;
  484. if (show_empty && s->slabs)
  485. return;
  486. store_size(size_str, slab_size(s));
  487. snprintf(dist_str, 40, "%lu/%lu/%d", s->slabs - s->cpu_slabs,
  488. s->partial, s->cpu_slabs);
  489. if (!line++)
  490. first_line();
  491. if (s->aliases)
  492. *p++ = '*';
  493. if (s->cache_dma)
  494. *p++ = 'd';
  495. if (s->hwcache_align)
  496. *p++ = 'A';
  497. if (s->poison)
  498. *p++ = 'P';
  499. if (s->reclaim_account)
  500. *p++ = 'a';
  501. if (s->red_zone)
  502. *p++ = 'Z';
  503. if (s->sanity_checks)
  504. *p++ = 'F';
  505. if (s->store_user)
  506. *p++ = 'U';
  507. if (s->trace)
  508. *p++ = 'T';
  509. *p = 0;
  510. if (show_activity) {
  511. unsigned long total_alloc;
  512. unsigned long total_free;
  513. total_alloc = s->alloc_fastpath + s->alloc_slowpath;
  514. total_free = s->free_fastpath + s->free_slowpath;
  515. printf("%-21s %8ld %10ld %10ld %3ld %3ld %5ld %1d %4ld %4ld\n",
  516. s->name, s->objects,
  517. total_alloc, total_free,
  518. total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0,
  519. total_free ? (s->free_fastpath * 100 / total_free) : 0,
  520. s->order_fallback, s->order, s->cmpxchg_double_fail,
  521. s->cmpxchg_double_cpu_fail);
  522. }
  523. else
  524. printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n",
  525. s->name, s->objects, s->object_size, size_str, dist_str,
  526. s->objs_per_slab, s->order,
  527. s->slabs ? (s->partial * 100) / s->slabs : 100,
  528. s->slabs ? (s->objects * s->object_size * 100) /
  529. (s->slabs * (page_size << s->order)) : 100,
  530. flags);
  531. }
  532. /*
  533. * Analyze debug options. Return false if something is amiss.
  534. */
  535. static int debug_opt_scan(char *opt)
  536. {
  537. if (!opt || !opt[0] || strcmp(opt, "-") == 0)
  538. return 1;
  539. if (strcasecmp(opt, "a") == 0) {
  540. sanity = 1;
  541. poison = 1;
  542. redzone = 1;
  543. tracking = 1;
  544. return 1;
  545. }
  546. for ( ; *opt; opt++)
  547. switch (*opt) {
  548. case 'F' : case 'f':
  549. if (sanity)
  550. return 0;
  551. sanity = 1;
  552. break;
  553. case 'P' : case 'p':
  554. if (poison)
  555. return 0;
  556. poison = 1;
  557. break;
  558. case 'Z' : case 'z':
  559. if (redzone)
  560. return 0;
  561. redzone = 1;
  562. break;
  563. case 'U' : case 'u':
  564. if (tracking)
  565. return 0;
  566. tracking = 1;
  567. break;
  568. case 'T' : case 't':
  569. if (tracing)
  570. return 0;
  571. tracing = 1;
  572. break;
  573. default:
  574. return 0;
  575. }
  576. return 1;
  577. }
  578. static int slab_empty(struct slabinfo *s)
  579. {
  580. if (s->objects > 0)
  581. return 0;
  582. /*
  583. * We may still have slabs even if there are no objects. Shrinking will
  584. * remove them.
  585. */
  586. if (s->slabs != 0)
  587. set_obj(s, "shrink", 1);
  588. return 1;
  589. }
  590. static void slab_debug(struct slabinfo *s)
  591. {
  592. if (strcmp(s->name, "*") == 0)
  593. return;
  594. if (sanity && !s->sanity_checks) {
  595. set_obj(s, "sanity", 1);
  596. }
  597. if (!sanity && s->sanity_checks) {
  598. if (slab_empty(s))
  599. set_obj(s, "sanity", 0);
  600. else
  601. fprintf(stderr, "%s not empty cannot disable sanity checks\n", s->name);
  602. }
  603. if (redzone && !s->red_zone) {
  604. if (slab_empty(s))
  605. set_obj(s, "red_zone", 1);
  606. else
  607. fprintf(stderr, "%s not empty cannot enable redzoning\n", s->name);
  608. }
  609. if (!redzone && s->red_zone) {
  610. if (slab_empty(s))
  611. set_obj(s, "red_zone", 0);
  612. else
  613. fprintf(stderr, "%s not empty cannot disable redzoning\n", s->name);
  614. }
  615. if (poison && !s->poison) {
  616. if (slab_empty(s))
  617. set_obj(s, "poison", 1);
  618. else
  619. fprintf(stderr, "%s not empty cannot enable poisoning\n", s->name);
  620. }
  621. if (!poison && s->poison) {
  622. if (slab_empty(s))
  623. set_obj(s, "poison", 0);
  624. else
  625. fprintf(stderr, "%s not empty cannot disable poisoning\n", s->name);
  626. }
  627. if (tracking && !s->store_user) {
  628. if (slab_empty(s))
  629. set_obj(s, "store_user", 1);
  630. else
  631. fprintf(stderr, "%s not empty cannot enable tracking\n", s->name);
  632. }
  633. if (!tracking && s->store_user) {
  634. if (slab_empty(s))
  635. set_obj(s, "store_user", 0);
  636. else
  637. fprintf(stderr, "%s not empty cannot disable tracking\n", s->name);
  638. }
  639. if (tracing && !s->trace) {
  640. if (slabs == 1)
  641. set_obj(s, "trace", 1);
  642. else
  643. fprintf(stderr, "%s can only enable trace for one slab at a time\n", s->name);
  644. }
  645. if (!tracing && s->trace)
  646. set_obj(s, "trace", 1);
  647. }
  648. static void totals(void)
  649. {
  650. struct slabinfo *s;
  651. int used_slabs = 0;
  652. char b1[20], b2[20], b3[20], b4[20];
  653. unsigned long long max = 1ULL << 63;
  654. /* Object size */
  655. unsigned long long min_objsize = max, max_objsize = 0, avg_objsize;
  656. /* Number of partial slabs in a slabcache */
  657. unsigned long long min_partial = max, max_partial = 0,
  658. avg_partial, total_partial = 0;
  659. /* Number of slabs in a slab cache */
  660. unsigned long long min_slabs = max, max_slabs = 0,
  661. avg_slabs, total_slabs = 0;
  662. /* Size of the whole slab */
  663. unsigned long long min_size = max, max_size = 0,
  664. avg_size, total_size = 0;
  665. /* Bytes used for object storage in a slab */
  666. unsigned long long min_used = max, max_used = 0,
  667. avg_used, total_used = 0;
  668. /* Waste: Bytes used for alignment and padding */
  669. unsigned long long min_waste = max, max_waste = 0,
  670. avg_waste, total_waste = 0;
  671. /* Number of objects in a slab */
  672. unsigned long long min_objects = max, max_objects = 0,
  673. avg_objects, total_objects = 0;
  674. /* Waste per object */
  675. unsigned long long min_objwaste = max,
  676. max_objwaste = 0, avg_objwaste,
  677. total_objwaste = 0;
  678. /* Memory per object */
  679. unsigned long long min_memobj = max,
  680. max_memobj = 0, avg_memobj,
  681. total_objsize = 0;
  682. /* Percentage of partial slabs per slab */
  683. unsigned long min_ppart = 100, max_ppart = 0,
  684. avg_ppart, total_ppart = 0;
  685. /* Number of objects in partial slabs */
  686. unsigned long min_partobj = max, max_partobj = 0,
  687. avg_partobj, total_partobj = 0;
  688. /* Percentage of partial objects of all objects in a slab */
  689. unsigned long min_ppartobj = 100, max_ppartobj = 0,
  690. avg_ppartobj, total_ppartobj = 0;
  691. for (s = slabinfo; s < slabinfo + slabs; s++) {
  692. unsigned long long size;
  693. unsigned long used;
  694. unsigned long long wasted;
  695. unsigned long long objwaste;
  696. unsigned long percentage_partial_slabs;
  697. unsigned long percentage_partial_objs;
  698. if (!s->slabs || !s->objects)
  699. continue;
  700. used_slabs++;
  701. size = slab_size(s);
  702. used = s->objects * s->object_size;
  703. wasted = size - used;
  704. objwaste = s->slab_size - s->object_size;
  705. percentage_partial_slabs = s->partial * 100 / s->slabs;
  706. if (percentage_partial_slabs > 100)
  707. percentage_partial_slabs = 100;
  708. percentage_partial_objs = s->objects_partial * 100
  709. / s->objects;
  710. if (percentage_partial_objs > 100)
  711. percentage_partial_objs = 100;
  712. if (s->object_size < min_objsize)
  713. min_objsize = s->object_size;
  714. if (s->partial < min_partial)
  715. min_partial = s->partial;
  716. if (s->slabs < min_slabs)
  717. min_slabs = s->slabs;
  718. if (size < min_size)
  719. min_size = size;
  720. if (wasted < min_waste)
  721. min_waste = wasted;
  722. if (objwaste < min_objwaste)
  723. min_objwaste = objwaste;
  724. if (s->objects < min_objects)
  725. min_objects = s->objects;
  726. if (used < min_used)
  727. min_used = used;
  728. if (s->objects_partial < min_partobj)
  729. min_partobj = s->objects_partial;
  730. if (percentage_partial_slabs < min_ppart)
  731. min_ppart = percentage_partial_slabs;
  732. if (percentage_partial_objs < min_ppartobj)
  733. min_ppartobj = percentage_partial_objs;
  734. if (s->slab_size < min_memobj)
  735. min_memobj = s->slab_size;
  736. if (s->object_size > max_objsize)
  737. max_objsize = s->object_size;
  738. if (s->partial > max_partial)
  739. max_partial = s->partial;
  740. if (s->slabs > max_slabs)
  741. max_slabs = s->slabs;
  742. if (size > max_size)
  743. max_size = size;
  744. if (wasted > max_waste)
  745. max_waste = wasted;
  746. if (objwaste > max_objwaste)
  747. max_objwaste = objwaste;
  748. if (s->objects > max_objects)
  749. max_objects = s->objects;
  750. if (used > max_used)
  751. max_used = used;
  752. if (s->objects_partial > max_partobj)
  753. max_partobj = s->objects_partial;
  754. if (percentage_partial_slabs > max_ppart)
  755. max_ppart = percentage_partial_slabs;
  756. if (percentage_partial_objs > max_ppartobj)
  757. max_ppartobj = percentage_partial_objs;
  758. if (s->slab_size > max_memobj)
  759. max_memobj = s->slab_size;
  760. total_partial += s->partial;
  761. total_slabs += s->slabs;
  762. total_size += size;
  763. total_waste += wasted;
  764. total_objects += s->objects;
  765. total_used += used;
  766. total_partobj += s->objects_partial;
  767. total_ppart += percentage_partial_slabs;
  768. total_ppartobj += percentage_partial_objs;
  769. total_objwaste += s->objects * objwaste;
  770. total_objsize += s->objects * s->slab_size;
  771. }
  772. if (!total_objects) {
  773. printf("No objects\n");
  774. return;
  775. }
  776. if (!used_slabs) {
  777. printf("No slabs\n");
  778. return;
  779. }
  780. /* Per slab averages */
  781. avg_partial = total_partial / used_slabs;
  782. avg_slabs = total_slabs / used_slabs;
  783. avg_size = total_size / used_slabs;
  784. avg_waste = total_waste / used_slabs;
  785. avg_objects = total_objects / used_slabs;
  786. avg_used = total_used / used_slabs;
  787. avg_partobj = total_partobj / used_slabs;
  788. avg_ppart = total_ppart / used_slabs;
  789. avg_ppartobj = total_ppartobj / used_slabs;
  790. /* Per object object sizes */
  791. avg_objsize = total_used / total_objects;
  792. avg_objwaste = total_objwaste / total_objects;
  793. avg_partobj = total_partobj * 100 / total_objects;
  794. avg_memobj = total_objsize / total_objects;
  795. printf("Slabcache Totals\n");
  796. printf("----------------\n");
  797. printf("Slabcaches : %3d Aliases : %3d->%-3d Active: %3d\n",
  798. slabs, aliases, alias_targets, used_slabs);
  799. store_size(b1, total_size);store_size(b2, total_waste);
  800. store_size(b3, total_waste * 100 / total_used);
  801. printf("Memory used: %6s # Loss : %6s MRatio:%6s%%\n", b1, b2, b3);
  802. store_size(b1, total_objects);store_size(b2, total_partobj);
  803. store_size(b3, total_partobj * 100 / total_objects);
  804. printf("# Objects : %6s # PartObj: %6s ORatio:%6s%%\n", b1, b2, b3);
  805. printf("\n");
  806. printf("Per Cache Average Min Max Total\n");
  807. printf("---------------------------------------------------------\n");
  808. store_size(b1, avg_objects);store_size(b2, min_objects);
  809. store_size(b3, max_objects);store_size(b4, total_objects);
  810. printf("#Objects %10s %10s %10s %10s\n",
  811. b1, b2, b3, b4);
  812. store_size(b1, avg_slabs);store_size(b2, min_slabs);
  813. store_size(b3, max_slabs);store_size(b4, total_slabs);
  814. printf("#Slabs %10s %10s %10s %10s\n",
  815. b1, b2, b3, b4);
  816. store_size(b1, avg_partial);store_size(b2, min_partial);
  817. store_size(b3, max_partial);store_size(b4, total_partial);
  818. printf("#PartSlab %10s %10s %10s %10s\n",
  819. b1, b2, b3, b4);
  820. store_size(b1, avg_ppart);store_size(b2, min_ppart);
  821. store_size(b3, max_ppart);
  822. store_size(b4, total_partial * 100 / total_slabs);
  823. printf("%%PartSlab%10s%% %10s%% %10s%% %10s%%\n",
  824. b1, b2, b3, b4);
  825. store_size(b1, avg_partobj);store_size(b2, min_partobj);
  826. store_size(b3, max_partobj);
  827. store_size(b4, total_partobj);
  828. printf("PartObjs %10s %10s %10s %10s\n",
  829. b1, b2, b3, b4);
  830. store_size(b1, avg_ppartobj);store_size(b2, min_ppartobj);
  831. store_size(b3, max_ppartobj);
  832. store_size(b4, total_partobj * 100 / total_objects);
  833. printf("%% PartObj%10s%% %10s%% %10s%% %10s%%\n",
  834. b1, b2, b3, b4);
  835. store_size(b1, avg_size);store_size(b2, min_size);
  836. store_size(b3, max_size);store_size(b4, total_size);
  837. printf("Memory %10s %10s %10s %10s\n",
  838. b1, b2, b3, b4);
  839. store_size(b1, avg_used);store_size(b2, min_used);
  840. store_size(b3, max_used);store_size(b4, total_used);
  841. printf("Used %10s %10s %10s %10s\n",
  842. b1, b2, b3, b4);
  843. store_size(b1, avg_waste);store_size(b2, min_waste);
  844. store_size(b3, max_waste);store_size(b4, total_waste);
  845. printf("Loss %10s %10s %10s %10s\n",
  846. b1, b2, b3, b4);
  847. printf("\n");
  848. printf("Per Object Average Min Max\n");
  849. printf("---------------------------------------------\n");
  850. store_size(b1, avg_memobj);store_size(b2, min_memobj);
  851. store_size(b3, max_memobj);
  852. printf("Memory %10s %10s %10s\n",
  853. b1, b2, b3);
  854. store_size(b1, avg_objsize);store_size(b2, min_objsize);
  855. store_size(b3, max_objsize);
  856. printf("User %10s %10s %10s\n",
  857. b1, b2, b3);
  858. store_size(b1, avg_objwaste);store_size(b2, min_objwaste);
  859. store_size(b3, max_objwaste);
  860. printf("Loss %10s %10s %10s\n",
  861. b1, b2, b3);
  862. }
  863. static void sort_slabs(void)
  864. {
  865. struct slabinfo *s1,*s2;
  866. for (s1 = slabinfo; s1 < slabinfo + slabs; s1++) {
  867. for (s2 = s1 + 1; s2 < slabinfo + slabs; s2++) {
  868. int result;
  869. if (sort_size)
  870. result = slab_size(s1) < slab_size(s2);
  871. else if (sort_active)
  872. result = slab_activity(s1) < slab_activity(s2);
  873. else
  874. result = strcasecmp(s1->name, s2->name);
  875. if (show_inverted)
  876. result = -result;
  877. if (result > 0) {
  878. struct slabinfo t;
  879. memcpy(&t, s1, sizeof(struct slabinfo));
  880. memcpy(s1, s2, sizeof(struct slabinfo));
  881. memcpy(s2, &t, sizeof(struct slabinfo));
  882. }
  883. }
  884. }
  885. }
  886. static void sort_aliases(void)
  887. {
  888. struct aliasinfo *a1,*a2;
  889. for (a1 = aliasinfo; a1 < aliasinfo + aliases; a1++) {
  890. for (a2 = a1 + 1; a2 < aliasinfo + aliases; a2++) {
  891. char *n1, *n2;
  892. n1 = a1->name;
  893. n2 = a2->name;
  894. if (show_alias && !show_inverted) {
  895. n1 = a1->ref;
  896. n2 = a2->ref;
  897. }
  898. if (strcasecmp(n1, n2) > 0) {
  899. struct aliasinfo t;
  900. memcpy(&t, a1, sizeof(struct aliasinfo));
  901. memcpy(a1, a2, sizeof(struct aliasinfo));
  902. memcpy(a2, &t, sizeof(struct aliasinfo));
  903. }
  904. }
  905. }
  906. }
  907. static void link_slabs(void)
  908. {
  909. struct aliasinfo *a;
  910. struct slabinfo *s;
  911. for (a = aliasinfo; a < aliasinfo + aliases; a++) {
  912. for (s = slabinfo; s < slabinfo + slabs; s++)
  913. if (strcmp(a->ref, s->name) == 0) {
  914. a->slab = s;
  915. s->refs++;
  916. break;
  917. }
  918. if (s == slabinfo + slabs)
  919. fatal("Unresolved alias %s\n", a->ref);
  920. }
  921. }
  922. static void alias(void)
  923. {
  924. struct aliasinfo *a;
  925. char *active = NULL;
  926. sort_aliases();
  927. link_slabs();
  928. for(a = aliasinfo; a < aliasinfo + aliases; a++) {
  929. if (!show_single_ref && a->slab->refs == 1)
  930. continue;
  931. if (!show_inverted) {
  932. if (active) {
  933. if (strcmp(a->slab->name, active) == 0) {
  934. printf(" %s", a->name);
  935. continue;
  936. }
  937. }
  938. printf("\n%-12s <- %s", a->slab->name, a->name);
  939. active = a->slab->name;
  940. }
  941. else
  942. printf("%-20s -> %s\n", a->name, a->slab->name);
  943. }
  944. if (active)
  945. printf("\n");
  946. }
  947. static void rename_slabs(void)
  948. {
  949. struct slabinfo *s;
  950. struct aliasinfo *a;
  951. for (s = slabinfo; s < slabinfo + slabs; s++) {
  952. if (*s->name != ':')
  953. continue;
  954. if (s->refs > 1 && !show_first_alias)
  955. continue;
  956. a = find_one_alias(s);
  957. if (a)
  958. s->name = a->name;
  959. else {
  960. s->name = "*";
  961. actual_slabs--;
  962. }
  963. }
  964. }
  965. static int slab_mismatch(char *slab)
  966. {
  967. return regexec(&pattern, slab, 0, NULL, 0);
  968. }
  969. static void read_slab_dir(void)
  970. {
  971. DIR *dir;
  972. struct dirent *de;
  973. struct slabinfo *slab = slabinfo;
  974. struct aliasinfo *alias = aliasinfo;
  975. char *p;
  976. char *t;
  977. int count;
  978. if (chdir("/sys/kernel/slab") && chdir("/sys/slab"))
  979. fatal("SYSFS support for SLUB not active\n");
  980. dir = opendir(".");
  981. while ((de = readdir(dir))) {
  982. if (de->d_name[0] == '.' ||
  983. (de->d_name[0] != ':' && slab_mismatch(de->d_name)))
  984. continue;
  985. switch (de->d_type) {
  986. case DT_LNK:
  987. alias->name = strdup(de->d_name);
  988. count = readlink(de->d_name, buffer, sizeof(buffer)-1);
  989. if (count < 0)
  990. fatal("Cannot read symlink %s\n", de->d_name);
  991. buffer[count] = 0;
  992. p = buffer + count;
  993. while (p > buffer && p[-1] != '/')
  994. p--;
  995. alias->ref = strdup(p);
  996. alias++;
  997. break;
  998. case DT_DIR:
  999. if (chdir(de->d_name))
  1000. fatal("Unable to access slab %s\n", slab->name);
  1001. slab->name = strdup(de->d_name);
  1002. slab->alias = 0;
  1003. slab->refs = 0;
  1004. slab->aliases = get_obj("aliases");
  1005. slab->align = get_obj("align");
  1006. slab->cache_dma = get_obj("cache_dma");
  1007. slab->cpu_slabs = get_obj("cpu_slabs");
  1008. slab->destroy_by_rcu = get_obj("destroy_by_rcu");
  1009. slab->hwcache_align = get_obj("hwcache_align");
  1010. slab->object_size = get_obj("object_size");
  1011. slab->objects = get_obj("objects");
  1012. slab->objects_partial = get_obj("objects_partial");
  1013. slab->objects_total = get_obj("objects_total");
  1014. slab->objs_per_slab = get_obj("objs_per_slab");
  1015. slab->order = get_obj("order");
  1016. slab->partial = get_obj("partial");
  1017. slab->partial = get_obj_and_str("partial", &t);
  1018. decode_numa_list(slab->numa_partial, t);
  1019. free(t);
  1020. slab->poison = get_obj("poison");
  1021. slab->reclaim_account = get_obj("reclaim_account");
  1022. slab->red_zone = get_obj("red_zone");
  1023. slab->sanity_checks = get_obj("sanity_checks");
  1024. slab->slab_size = get_obj("slab_size");
  1025. slab->slabs = get_obj_and_str("slabs", &t);
  1026. decode_numa_list(slab->numa, t);
  1027. free(t);
  1028. slab->store_user = get_obj("store_user");
  1029. slab->trace = get_obj("trace");
  1030. slab->alloc_fastpath = get_obj("alloc_fastpath");
  1031. slab->alloc_slowpath = get_obj("alloc_slowpath");
  1032. slab->free_fastpath = get_obj("free_fastpath");
  1033. slab->free_slowpath = get_obj("free_slowpath");
  1034. slab->free_frozen= get_obj("free_frozen");
  1035. slab->free_add_partial = get_obj("free_add_partial");
  1036. slab->free_remove_partial = get_obj("free_remove_partial");
  1037. slab->alloc_from_partial = get_obj("alloc_from_partial");
  1038. slab->alloc_slab = get_obj("alloc_slab");
  1039. slab->alloc_refill = get_obj("alloc_refill");
  1040. slab->free_slab = get_obj("free_slab");
  1041. slab->cpuslab_flush = get_obj("cpuslab_flush");
  1042. slab->deactivate_full = get_obj("deactivate_full");
  1043. slab->deactivate_empty = get_obj("deactivate_empty");
  1044. slab->deactivate_to_head = get_obj("deactivate_to_head");
  1045. slab->deactivate_to_tail = get_obj("deactivate_to_tail");
  1046. slab->deactivate_remote_frees = get_obj("deactivate_remote_frees");
  1047. slab->order_fallback = get_obj("order_fallback");
  1048. slab->cmpxchg_double_cpu_fail = get_obj("cmpxchg_double_cpu_fail");
  1049. slab->cmpxchg_double_fail = get_obj("cmpxchg_double_fail");
  1050. slab->cpu_partial_alloc = get_obj("cpu_partial_alloc");
  1051. slab->cpu_partial_free = get_obj("cpu_partial_free");
  1052. slab->alloc_node_mismatch = get_obj("alloc_node_mismatch");
  1053. slab->deactivate_bypass = get_obj("deactivate_bypass");
  1054. chdir("..");
  1055. if (slab->name[0] == ':')
  1056. alias_targets++;
  1057. slab++;
  1058. break;
  1059. default :
  1060. fatal("Unknown file type %lx\n", de->d_type);
  1061. }
  1062. }
  1063. closedir(dir);
  1064. slabs = slab - slabinfo;
  1065. actual_slabs = slabs;
  1066. aliases = alias - aliasinfo;
  1067. if (slabs > MAX_SLABS)
  1068. fatal("Too many slabs\n");
  1069. if (aliases > MAX_ALIASES)
  1070. fatal("Too many aliases\n");
  1071. }
  1072. static void output_slabs(void)
  1073. {
  1074. struct slabinfo *slab;
  1075. for (slab = slabinfo; slab < slabinfo + slabs; slab++) {
  1076. if (slab->alias)
  1077. continue;
  1078. if (show_numa)
  1079. slab_numa(slab, 0);
  1080. else if (show_track)
  1081. show_tracking(slab);
  1082. else if (validate)
  1083. slab_validate(slab);
  1084. else if (shrink)
  1085. slab_shrink(slab);
  1086. else if (set_debug)
  1087. slab_debug(slab);
  1088. else if (show_ops)
  1089. ops(slab);
  1090. else if (show_slab)
  1091. slabcache(slab);
  1092. else if (show_report)
  1093. report(slab);
  1094. }
  1095. }
  1096. struct option opts[] = {
  1097. { "aliases", 0, NULL, 'a' },
  1098. { "activity", 0, NULL, 'A' },
  1099. { "debug", 2, NULL, 'd' },
  1100. { "display-activity", 0, NULL, 'D' },
  1101. { "empty", 0, NULL, 'e' },
  1102. { "first-alias", 0, NULL, 'f' },
  1103. { "help", 0, NULL, 'h' },
  1104. { "inverted", 0, NULL, 'i'},
  1105. { "numa", 0, NULL, 'n' },
  1106. { "ops", 0, NULL, 'o' },
  1107. { "report", 0, NULL, 'r' },
  1108. { "shrink", 0, NULL, 's' },
  1109. { "slabs", 0, NULL, 'l' },
  1110. { "track", 0, NULL, 't'},
  1111. { "validate", 0, NULL, 'v' },
  1112. { "zero", 0, NULL, 'z' },
  1113. { "1ref", 0, NULL, '1'},
  1114. { NULL, 0, NULL, 0 }
  1115. };
  1116. int main(int argc, char *argv[])
  1117. {
  1118. int c;
  1119. int err;
  1120. char *pattern_source;
  1121. page_size = getpagesize();
  1122. while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTS",
  1123. opts, NULL)) != -1)
  1124. switch (c) {
  1125. case '1':
  1126. show_single_ref = 1;
  1127. break;
  1128. case 'a':
  1129. show_alias = 1;
  1130. break;
  1131. case 'A':
  1132. sort_active = 1;
  1133. break;
  1134. case 'd':
  1135. set_debug = 1;
  1136. if (!debug_opt_scan(optarg))
  1137. fatal("Invalid debug option '%s'\n", optarg);
  1138. break;
  1139. case 'D':
  1140. show_activity = 1;
  1141. break;
  1142. case 'e':
  1143. show_empty = 1;
  1144. break;
  1145. case 'f':
  1146. show_first_alias = 1;
  1147. break;
  1148. case 'h':
  1149. usage();
  1150. return 0;
  1151. case 'i':
  1152. show_inverted = 1;
  1153. break;
  1154. case 'n':
  1155. show_numa = 1;
  1156. break;
  1157. case 'o':
  1158. show_ops = 1;
  1159. break;
  1160. case 'r':
  1161. show_report = 1;
  1162. break;
  1163. case 's':
  1164. shrink = 1;
  1165. break;
  1166. case 'l':
  1167. show_slab = 1;
  1168. break;
  1169. case 't':
  1170. show_track = 1;
  1171. break;
  1172. case 'v':
  1173. validate = 1;
  1174. break;
  1175. case 'z':
  1176. skip_zero = 0;
  1177. break;
  1178. case 'T':
  1179. show_totals = 1;
  1180. break;
  1181. case 'S':
  1182. sort_size = 1;
  1183. break;
  1184. default:
  1185. fatal("%s: Invalid option '%c'\n", argv[0], optopt);
  1186. }
  1187. if (!show_slab && !show_alias && !show_track && !show_report
  1188. && !validate && !shrink && !set_debug && !show_ops)
  1189. show_slab = 1;
  1190. if (argc > optind)
  1191. pattern_source = argv[optind];
  1192. else
  1193. pattern_source = ".*";
  1194. err = regcomp(&pattern, pattern_source, REG_ICASE|REG_NOSUB);
  1195. if (err)
  1196. fatal("%s: Invalid pattern '%s' code %d\n",
  1197. argv[0], pattern_source, err);
  1198. read_slab_dir();
  1199. if (show_alias)
  1200. alias();
  1201. else
  1202. if (show_totals)
  1203. totals();
  1204. else {
  1205. link_slabs();
  1206. rename_slabs();
  1207. sort_slabs();
  1208. output_slabs();
  1209. }
  1210. return 0;
  1211. }