slub.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. O Switch debugging off for caches that would have
  36. caused higher minimum slab orders
  37. - Switch all debugging off (useful if the kernel is
  38. configured with CONFIG_SLUB_DEBUG_ON)
  39. F.e. in order to boot just with sanity checks and red zoning one would specify:
  40. slub_debug=FZ
  41. Trying to find an issue in the dentry cache? Try
  42. slub_debug=,dentry
  43. to only enable debugging on the dentry cache.
  44. Red zoning and tracking may realign the slab. We can just apply sanity checks
  45. to the dentry cache with
  46. slub_debug=F,dentry
  47. Debugging options may require the minimum possible slab order to increase as
  48. a result of storing the metadata (for example, caches with PAGE_SIZE object
  49. sizes). This has a higher liklihood of resulting in slab allocation errors
  50. in low memory situations or if there's high fragmentation of memory. To
  51. switch off debugging for such caches by default, use
  52. slub_debug=O
  53. In case you forgot to enable debugging on the kernel command line: It is
  54. possible to enable debugging manually when the kernel is up. Look at the
  55. contents of:
  56. /sys/kernel/slab/<slab name>/
  57. Look at the writable files. Writing 1 to them will enable the
  58. corresponding debug option. All options can be set on a slab that does
  59. not contain objects. If the slab already contains objects then sanity checks
  60. and tracing may only be enabled. The other options may cause the realignment
  61. of objects.
  62. Careful with tracing: It may spew out lots of information and never stop if
  63. used on the wrong slab.
  64. Slab merging
  65. ------------
  66. If no debug options are specified then SLUB may merge similar slabs together
  67. in order to reduce overhead and increase cache hotness of objects.
  68. slabinfo -a displays which slabs were merged together.
  69. Slab validation
  70. ---------------
  71. SLUB can validate all object if the kernel was booted with slub_debug. In
  72. order to do so you must have the slabinfo tool. Then you can do
  73. slabinfo -v
  74. which will test all objects. Output will be generated to the syslog.
  75. This also works in a more limited way if boot was without slab debug.
  76. In that case slabinfo -v simply tests all reachable objects. Usually
  77. these are in the cpu slabs and the partial slabs. Full slabs are not
  78. tracked by SLUB in a non debug situation.
  79. Getting more performance
  80. ------------------------
  81. To some degree SLUB's performance is limited by the need to take the
  82. list_lock once in a while to deal with partial slabs. That overhead is
  83. governed by the order of the allocation for each slab. The allocations
  84. can be influenced by kernel parameters:
  85. slub_min_objects=x (default 4)
  86. slub_min_order=x (default 0)
  87. slub_max_order=x (default 1)
  88. slub_min_objects allows to specify how many objects must at least fit
  89. into one slab in order for the allocation order to be acceptable.
  90. In general slub will be able to perform this number of allocations
  91. on a slab without consulting centralized resources (list_lock) where
  92. contention may occur.
  93. slub_min_order specifies a minim order of slabs. A similar effect like
  94. slub_min_objects.
  95. slub_max_order specified the order at which slub_min_objects should no
  96. longer be checked. This is useful to avoid SLUB trying to generate
  97. super large order pages to fit slub_min_objects of a slab cache with
  98. large object sizes into one high order page.
  99. SLUB Debug output
  100. -----------------
  101. Here is a sample of slub debug output:
  102. ====================================================================
  103. BUG kmalloc-8: Redzone overwritten
  104. --------------------------------------------------------------------
  105. INFO: 0xc90f6d28-0xc90f6d2b. First byte 0x00 instead of 0xcc
  106. INFO: Slab 0xc528c530 flags=0x400000c3 inuse=61 fp=0xc90f6d58
  107. INFO: Object 0xc90f6d20 @offset=3360 fp=0xc90f6d58
  108. INFO: Allocated in get_modalias+0x61/0xf5 age=53 cpu=1 pid=554
  109. Bytes b4 0xc90f6d10: 00 00 00 00 00 00 00 00 5a 5a 5a 5a 5a 5a 5a 5a ........ZZZZZZZZ
  110. Object 0xc90f6d20: 31 30 31 39 2e 30 30 35 1019.005
  111. Redzone 0xc90f6d28: 00 cc cc cc .
  112. Padding 0xc90f6d50: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ
  113. [<c010523d>] dump_trace+0x63/0x1eb
  114. [<c01053df>] show_trace_log_lvl+0x1a/0x2f
  115. [<c010601d>] show_trace+0x12/0x14
  116. [<c0106035>] dump_stack+0x16/0x18
  117. [<c017e0fa>] object_err+0x143/0x14b
  118. [<c017e2cc>] check_object+0x66/0x234
  119. [<c017eb43>] __slab_free+0x239/0x384
  120. [<c017f446>] kfree+0xa6/0xc6
  121. [<c02e2335>] get_modalias+0xb9/0xf5
  122. [<c02e23b7>] dmi_dev_uevent+0x27/0x3c
  123. [<c027866a>] dev_uevent+0x1ad/0x1da
  124. [<c0205024>] kobject_uevent_env+0x20a/0x45b
  125. [<c020527f>] kobject_uevent+0xa/0xf
  126. [<c02779f1>] store_uevent+0x4f/0x58
  127. [<c027758e>] dev_attr_store+0x29/0x2f
  128. [<c01bec4f>] sysfs_write_file+0x16e/0x19c
  129. [<c0183ba7>] vfs_write+0xd1/0x15a
  130. [<c01841d7>] sys_write+0x3d/0x72
  131. [<c0104112>] sysenter_past_esp+0x5f/0x99
  132. [<b7f7b410>] 0xb7f7b410
  133. =======================
  134. FIX kmalloc-8: Restoring Redzone 0xc90f6d28-0xc90f6d2b=0xcc
  135. If SLUB encounters a corrupted object (full detection requires the kernel
  136. to be booted with slub_debug) then the following output will be dumped
  137. into the syslog:
  138. 1. Description of the problem encountered
  139. This will be a message in the system log starting with
  140. ===============================================
  141. BUG <slab cache affected>: <What went wrong>
  142. -----------------------------------------------
  143. INFO: <corruption start>-<corruption_end> <more info>
  144. INFO: Slab <address> <slab information>
  145. INFO: Object <address> <object information>
  146. INFO: Allocated in <kernel function> age=<jiffies since alloc> cpu=<allocated by
  147. cpu> pid=<pid of the process>
  148. INFO: Freed in <kernel function> age=<jiffies since free> cpu=<freed by cpu>
  149. pid=<pid of the process>
  150. (Object allocation / free information is only available if SLAB_STORE_USER is
  151. set for the slab. slub_debug sets that option)
  152. 2. The object contents if an object was involved.
  153. Various types of lines can follow the BUG SLUB line:
  154. Bytes b4 <address> : <bytes>
  155. Shows a few bytes before the object where the problem was detected.
  156. Can be useful if the corruption does not stop with the start of the
  157. object.
  158. Object <address> : <bytes>
  159. The bytes of the object. If the object is inactive then the bytes
  160. typically contain poison values. Any non-poison value shows a
  161. corruption by a write after free.
  162. Redzone <address> : <bytes>
  163. The Redzone following the object. The Redzone is used to detect
  164. writes after the object. All bytes should always have the same
  165. value. If there is any deviation then it is due to a write after
  166. the object boundary.
  167. (Redzone information is only available if SLAB_RED_ZONE is set.
  168. slub_debug sets that option)
  169. Padding <address> : <bytes>
  170. Unused data to fill up the space in order to get the next object
  171. properly aligned. In the debug case we make sure that there are
  172. at least 4 bytes of padding. This allows the detection of writes
  173. before the object.
  174. 3. A stackdump
  175. The stackdump describes the location where the error was detected. The cause
  176. of the corruption is may be more likely found by looking at the function that
  177. allocated or freed the object.
  178. 4. Report on how the problem was dealt with in order to ensure the continued
  179. operation of the system.
  180. These are messages in the system log beginning with
  181. FIX <slab cache affected>: <corrective action taken>
  182. In the above sample SLUB found that the Redzone of an active object has
  183. been overwritten. Here a string of 8 characters was written into a slab that
  184. has the length of 8 characters. However, a 8 character string needs a
  185. terminating 0. That zero has overwritten the first byte of the Redzone field.
  186. After reporting the details of the issue encountered the FIX SLUB message
  187. tells us that SLUB has restored the Redzone to its proper value and then
  188. system operations continue.
  189. Emergency operations:
  190. ---------------------
  191. Minimal debugging (sanity checks alone) can be enabled by booting with
  192. slub_debug=F
  193. This will be generally be enough to enable the resiliency features of slub
  194. which will keep the system running even if a bad kernel component will
  195. keep corrupting objects. This may be important for production systems.
  196. Performance will be impacted by the sanity checks and there will be a
  197. continual stream of error messages to the syslog but no additional memory
  198. will be used (unlike full debugging).
  199. No guarantees. The kernel component still needs to be fixed. Performance
  200. may be optimized further by locating the slab that experiences corruption
  201. and enabling debugging only for that cache
  202. I.e.
  203. slub_debug=F,dentry
  204. If the corruption occurs by writing after the end of the object then it
  205. may be advisable to enable a Redzone to avoid corrupting the beginning
  206. of other objects.
  207. slub_debug=FZ,dentry
  208. Christoph Lameter, May 30, 2007