slub.txt 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. Short users guide for SLUB
  2. --------------------------
  3. The basic philosophy of SLUB is very different from SLAB. SLAB
  4. requires rebuilding the kernel to activate debug options for all
  5. slab caches. SLUB always includes full debugging but it is off by default.
  6. SLUB can enable debugging only for selected slabs in order to avoid
  7. an impact on overall system performance which may make a bug more
  8. difficult to find.
  9. In order to switch debugging on one can add a option "slub_debug"
  10. to the kernel command line. That will enable full debugging for
  11. all slabs.
  12. Typically one would then use the "slabinfo" command to get statistical
  13. data and perform operation on the slabs. By default slabinfo only lists
  14. slabs that have data in them. See "slabinfo -h" for more options when
  15. running the command. slabinfo can be compiled with
  16. gcc -o slabinfo Documentation/vm/slabinfo.c
  17. Some of the modes of operation of slabinfo require that slub debugging
  18. be enabled on the command line. F.e. no tracking information will be
  19. available without debugging on and validation can only partially
  20. be performed if debugging was not switched on.
  21. Some more sophisticated uses of slub_debug:
  22. -------------------------------------------
  23. Parameters may be given to slub_debug. If none is specified then full
  24. debugging is enabled. Format:
  25. slub_debug=<Debug-Options> Enable options for all slabs
  26. slub_debug=<Debug-Options>,<slab name>
  27. Enable options only for select slabs
  28. Possible debug options are
  29. F Sanity checks on (enables SLAB_DEBUG_FREE. Sorry
  30. SLAB legacy issues)
  31. Z Red zoning
  32. P Poisoning (object and padding)
  33. U User tracking (free and alloc)
  34. T Trace (please only use on single slabs)
  35. - Switch all debugging off (useful if the kernel is
  36. configured with CONFIG_SLUB_DEBUG_ON)
  37. F.e. in order to boot just with sanity checks and red zoning one would specify:
  38. slub_debug=FZ
  39. Trying to find an issue in the dentry cache? Try
  40. slub_debug=,dentry_cache
  41. to only enable debugging on the dentry cache.
  42. Red zoning and tracking may realign the slab. We can just apply sanity checks
  43. to the dentry cache with
  44. slub_debug=F,dentry_cache
  45. In case you forgot to enable debugging on the kernel command line: It is
  46. possible to enable debugging manually when the kernel is up. Look at the
  47. contents of:
  48. /sys/slab/<slab name>/
  49. Look at the writable files. Writing 1 to them will enable the
  50. corresponding debug option. All options can be set on a slab that does
  51. not contain objects. If the slab already contains objects then sanity checks
  52. and tracing may only be enabled. The other options may cause the realignment
  53. of objects.
  54. Careful with tracing: It may spew out lots of information and never stop if
  55. used on the wrong slab.
  56. Slab merging
  57. ------------
  58. If no debug options are specified then SLUB may merge similar slabs together
  59. in order to reduce overhead and increase cache hotness of objects.
  60. slabinfo -a displays which slabs were merged together.
  61. Slab validation
  62. ---------------
  63. SLUB can validate all object if the kernel was booted with slub_debug. In
  64. order to do so you must have the slabinfo tool. Then you can do
  65. slabinfo -v
  66. which will test all objects. Output will be generated to the syslog.
  67. This also works in a more limited way if boot was without slab debug.
  68. In that case slabinfo -v simply tests all reachable objects. Usually
  69. these are in the cpu slabs and the partial slabs. Full slabs are not
  70. tracked by SLUB in a non debug situation.
  71. Getting more performance
  72. ------------------------
  73. To some degree SLUB's performance is limited by the need to take the
  74. list_lock once in a while to deal with partial slabs. That overhead is
  75. governed by the order of the allocation for each slab. The allocations
  76. can be influenced by kernel parameters:
  77. slub_min_objects=x (default 4)
  78. slub_min_order=x (default 0)
  79. slub_max_order=x (default 1)
  80. slub_min_objects allows to specify how many objects must at least fit
  81. into one slab in order for the allocation order to be acceptable.
  82. In general slub will be able to perform this number of allocations
  83. on a slab without consulting centralized resources (list_lock) where
  84. contention may occur.
  85. slub_min_order specifies a minim order of slabs. A similar effect like
  86. slub_min_objects.
  87. slub_max_order specified the order at which slub_min_objects should no
  88. longer be checked. This is useful to avoid SLUB trying to generate
  89. super large order pages to fit slub_min_objects of a slab cache with
  90. large object sizes into one high order page.
  91. SLUB Debug output
  92. -----------------
  93. Here is a sample of slub debug output:
  94. *** SLUB kmalloc-8: Redzone Active@0xc90f6d20 slab 0xc528c530 offset=3360 flags=0x400000c3 inuse=61 freelist=0xc90f6d58
  95. Bytes b4 0xc90f6d10: 00 00 00 00 00 00 00 00 5a 5a 5a 5a 5a 5a 5a 5a ........ZZZZZZZZ
  96. Object 0xc90f6d20: 31 30 31 39 2e 30 30 35 1019.005
  97. Redzone 0xc90f6d28: 00 cc cc cc .
  98. FreePointer 0xc90f6d2c -> 0xc90f6d58
  99. Last alloc: get_modalias+0x61/0xf5 jiffies_ago=53 cpu=1 pid=554
  100. Filler 0xc90f6d50: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ
  101. [<c010523d>] dump_trace+0x63/0x1eb
  102. [<c01053df>] show_trace_log_lvl+0x1a/0x2f
  103. [<c010601d>] show_trace+0x12/0x14
  104. [<c0106035>] dump_stack+0x16/0x18
  105. [<c017e0fa>] object_err+0x143/0x14b
  106. [<c017e2cc>] check_object+0x66/0x234
  107. [<c017eb43>] __slab_free+0x239/0x384
  108. [<c017f446>] kfree+0xa6/0xc6
  109. [<c02e2335>] get_modalias+0xb9/0xf5
  110. [<c02e23b7>] dmi_dev_uevent+0x27/0x3c
  111. [<c027866a>] dev_uevent+0x1ad/0x1da
  112. [<c0205024>] kobject_uevent_env+0x20a/0x45b
  113. [<c020527f>] kobject_uevent+0xa/0xf
  114. [<c02779f1>] store_uevent+0x4f/0x58
  115. [<c027758e>] dev_attr_store+0x29/0x2f
  116. [<c01bec4f>] sysfs_write_file+0x16e/0x19c
  117. [<c0183ba7>] vfs_write+0xd1/0x15a
  118. [<c01841d7>] sys_write+0x3d/0x72
  119. [<c0104112>] sysenter_past_esp+0x5f/0x99
  120. [<b7f7b410>] 0xb7f7b410
  121. =======================
  122. @@@ SLUB kmalloc-8: Restoring redzone (0xcc) from 0xc90f6d28-0xc90f6d2b
  123. If SLUB encounters a corrupted object then it will perform the following
  124. actions:
  125. 1. Isolation and report of the issue
  126. This will be a message in the system log starting with
  127. *** SLUB <slab cache affected>: <What went wrong>@<object address>
  128. offset=<offset of object into slab> flags=<slabflags>
  129. inuse=<objects in use in this slab> freelist=<first free object in slab>
  130. 2. Report on how the problem was dealt with in order to ensure the continued
  131. operation of the system.
  132. These are messages in the system log beginning with
  133. @@@ SLUB <slab cache affected>: <corrective action taken>
  134. In the above sample SLUB found that the Redzone of an active object has
  135. been overwritten. Here a string of 8 characters was written into a slab that
  136. has the length of 8 characters. However, a 8 character string needs a
  137. terminating 0. That zero has overwritten the first byte of the Redzone field.
  138. After reporting the details of the issue encountered the @@@ SLUB message
  139. tell us that SLUB has restored the redzone to its proper value and then
  140. system operations continue.
  141. Various types of lines can follow the @@@ SLUB line:
  142. Bytes b4 <address> : <bytes>
  143. Show a few bytes before the object where the problem was detected.
  144. Can be useful if the corruption does not stop with the start of the
  145. object.
  146. Object <address> : <bytes>
  147. The bytes of the object. If the object is inactive then the bytes
  148. typically contain poisoning values. Any non-poison value shows a
  149. corruption by a write after free.
  150. Redzone <address> : <bytes>
  151. The redzone following the object. The redzone is used to detect
  152. writes after the object. All bytes should always have the same
  153. value. If there is any deviation then it is due to a write after
  154. the object boundary.
  155. Freepointer
  156. The pointer to the next free object in the slab. May become
  157. corrupted if overwriting continues after the red zone.
  158. Last alloc:
  159. Last free:
  160. Shows the address from which the object was allocated/freed last.
  161. We note the pid, the time and the CPU that did so. This is usually
  162. the most useful information to figure out where things went wrong.
  163. Here get_modalias() did an kmalloc(8) instead of a kmalloc(9).
  164. Filler <address> : <bytes>
  165. Unused data to fill up the space in order to get the next object
  166. properly aligned. In the debug case we make sure that there are
  167. at least 4 bytes of filler. This allow for the detection of writes
  168. before the object.
  169. Following the filler will be a stackdump. That stackdump describes the
  170. location where the error was detected. The cause of the corruption is more
  171. likely to be found by looking at the information about the last alloc / free.
  172. Christoph Lameter, <clameter@sgi.com>, May 23, 2007