Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 1 | .. _slub: |
| 2 | |
| 3 | ========================== |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 4 | Short users guide for SLUB |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 5 | ========================== |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 6 | |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 7 | The basic philosophy of SLUB is very different from SLAB. SLAB |
| 8 | requires rebuilding the kernel to activate debug options for all |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 9 | slab caches. SLUB always includes full debugging but it is off by default. |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 10 | SLUB can enable debugging only for selected slabs in order to avoid |
| 11 | an impact on overall system performance which may make a bug more |
| 12 | difficult to find. |
| 13 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 14 | In order to switch debugging on one can add an option ``slub_debug`` |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 15 | to the kernel command line. That will enable full debugging for |
| 16 | all slabs. |
| 17 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 18 | Typically one would then use the ``slabinfo`` command to get statistical |
| 19 | data and perform operation on the slabs. By default ``slabinfo`` only lists |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 20 | slabs that have data in them. See "slabinfo -h" for more options when |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 21 | running the command. ``slabinfo`` can be compiled with |
| 22 | :: |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 23 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 24 | gcc -o slabinfo tools/vm/slabinfo.c |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 25 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 26 | Some of the modes of operation of ``slabinfo`` require that slub debugging |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 27 | be enabled on the command line. F.e. no tracking information will be |
| 28 | available without debugging on and validation can only partially |
| 29 | be performed if debugging was not switched on. |
| 30 | |
| 31 | Some more sophisticated uses of slub_debug: |
| 32 | ------------------------------------------- |
| 33 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 34 | Parameters may be given to ``slub_debug``. If none is specified then full |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 35 | debugging is enabled. Format: |
| 36 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 37 | slub_debug=<Debug-Options> |
| 38 | Enable options for all slabs |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 39 | |
Aaron Tomlin | c5fd3ca | 2018-10-26 15:03:15 -0700 | [diff] [blame] | 40 | slub_debug=<Debug-Options>,<slab name1>,<slab name2>,... |
| 41 | Enable options only for select slabs (no spaces |
| 42 | after a comma) |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 43 | |
| 44 | Possible debug options are:: |
| 45 | |
Laura Abbott | becfda6 | 2016-03-15 14:55:06 -0700 | [diff] [blame] | 46 | F Sanity checks on (enables SLAB_DEBUG_CONSISTENCY_CHECKS |
| 47 | Sorry SLAB legacy issues) |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 48 | Z Red zoning |
| 49 | P Poisoning (object and padding) |
| 50 | U User tracking (free and alloc) |
| 51 | T Trace (please only use on single slabs) |
Andrew Morton | a3df692 | 2020-06-01 21:46:00 -0700 | [diff] [blame] | 52 | A Enable failslab filter mark for the cache |
David Rientjes | fa5ec8a | 2009-07-07 00:14:14 -0700 | [diff] [blame] | 53 | O Switch debugging off for caches that would have |
| 54 | caused higher minimum slab orders |
Christoph Lameter | f0630ff | 2007-07-15 23:38:14 -0700 | [diff] [blame] | 55 | - Switch all debugging off (useful if the kernel is |
| 56 | configured with CONFIG_SLUB_DEBUG_ON) |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 57 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 58 | F.e. in order to boot just with sanity checks and red zoning one would specify:: |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 59 | |
| 60 | slub_debug=FZ |
| 61 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 62 | Trying to find an issue in the dentry cache? Try:: |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 63 | |
Itaru Kitayama | 989a724 | 2008-03-05 15:07:30 -0800 | [diff] [blame] | 64 | slub_debug=,dentry |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 65 | |
Aaron Tomlin | c5fd3ca | 2018-10-26 15:03:15 -0700 | [diff] [blame] | 66 | to only enable debugging on the dentry cache. You may use an asterisk at the |
| 67 | end of the slab name, in order to cover all slabs with the same prefix. For |
| 68 | example, here's how you can poison the dentry cache as well as all kmalloc |
Tobin C. Harding | 11ede50 | 2019-01-31 15:06:22 +1100 | [diff] [blame] | 69 | slabs:: |
Aaron Tomlin | c5fd3ca | 2018-10-26 15:03:15 -0700 | [diff] [blame] | 70 | |
| 71 | slub_debug=P,kmalloc-*,dentry |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 72 | |
| 73 | Red zoning and tracking may realign the slab. We can just apply sanity checks |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 74 | to the dentry cache with:: |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 75 | |
Itaru Kitayama | 989a724 | 2008-03-05 15:07:30 -0800 | [diff] [blame] | 76 | slub_debug=F,dentry |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 77 | |
David Rientjes | fa5ec8a | 2009-07-07 00:14:14 -0700 | [diff] [blame] | 78 | Debugging options may require the minimum possible slab order to increase as |
| 79 | a result of storing the metadata (for example, caches with PAGE_SIZE object |
| 80 | sizes). This has a higher liklihood of resulting in slab allocation errors |
| 81 | in low memory situations or if there's high fragmentation of memory. To |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 82 | switch off debugging for such caches by default, use:: |
David Rientjes | fa5ec8a | 2009-07-07 00:14:14 -0700 | [diff] [blame] | 83 | |
| 84 | slub_debug=O |
| 85 | |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 86 | In case you forgot to enable debugging on the kernel command line: It is |
| 87 | possible to enable debugging manually when the kernel is up. Look at the |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 88 | contents of:: |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 89 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 90 | /sys/kernel/slab/<slab name>/ |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 91 | |
| 92 | Look at the writable files. Writing 1 to them will enable the |
| 93 | corresponding debug option. All options can be set on a slab that does |
| 94 | not contain objects. If the slab already contains objects then sanity checks |
| 95 | and tracing may only be enabled. The other options may cause the realignment |
| 96 | of objects. |
| 97 | |
| 98 | Careful with tracing: It may spew out lots of information and never stop if |
| 99 | used on the wrong slab. |
| 100 | |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 101 | Slab merging |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 102 | ============ |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 103 | |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 104 | If no debug options are specified then SLUB may merge similar slabs together |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 105 | in order to reduce overhead and increase cache hotness of objects. |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 106 | ``slabinfo -a`` displays which slabs were merged together. |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 107 | |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 108 | Slab validation |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 109 | =============== |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 110 | |
| 111 | SLUB can validate all object if the kernel was booted with slub_debug. In |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 112 | order to do so you must have the ``slabinfo`` tool. Then you can do |
| 113 | :: |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 114 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 115 | slabinfo -v |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 116 | |
| 117 | which will test all objects. Output will be generated to the syslog. |
| 118 | |
| 119 | This also works in a more limited way if boot was without slab debug. |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 120 | In that case ``slabinfo -v`` simply tests all reachable objects. Usually |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 121 | these are in the cpu slabs and the partial slabs. Full slabs are not |
| 122 | tracked by SLUB in a non debug situation. |
| 123 | |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 124 | Getting more performance |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 125 | ======================== |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 126 | |
| 127 | To some degree SLUB's performance is limited by the need to take the |
| 128 | list_lock once in a while to deal with partial slabs. That overhead is |
| 129 | governed by the order of the allocation for each slab. The allocations |
| 130 | can be influenced by kernel parameters: |
| 131 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 132 | .. slub_min_objects=x (default 4) |
| 133 | .. slub_min_order=x (default 0) |
| 134 | .. slub_max_order=x (default 3 (PAGE_ALLOC_COSTLY_ORDER)) |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 135 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 136 | ``slub_min_objects`` |
| 137 | allows to specify how many objects must at least fit into one |
| 138 | slab in order for the allocation order to be acceptable. In |
| 139 | general slub will be able to perform this number of |
| 140 | allocations on a slab without consulting centralized resources |
| 141 | (list_lock) where contention may occur. |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 142 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 143 | ``slub_min_order`` |
Tobin C. Harding | 358b6ba | 2019-01-31 15:06:21 +1100 | [diff] [blame] | 144 | specifies a minimum order of slabs. A similar effect like |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 145 | ``slub_min_objects``. |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 146 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 147 | ``slub_max_order`` |
| 148 | specified the order at which ``slub_min_objects`` should no |
| 149 | longer be checked. This is useful to avoid SLUB trying to |
| 150 | generate super large order pages to fit ``slub_min_objects`` |
| 151 | of a slab cache with large object sizes into one high order |
| 152 | page. Setting command line parameter |
| 153 | ``debug_guardpage_minorder=N`` (N > 0), forces setting |
| 154 | ``slub_max_order`` to 0, what cause minimum possible order of |
| 155 | slabs allocation. |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 156 | |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 157 | SLUB Debug output |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 158 | ================= |
Christoph Lameter | 3524342 | 2007-05-06 14:49:47 -0700 | [diff] [blame] | 159 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 160 | Here is a sample of slub debug output:: |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 161 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 162 | ==================================================================== |
| 163 | BUG kmalloc-8: Redzone overwritten |
| 164 | -------------------------------------------------------------------- |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 165 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 166 | INFO: 0xc90f6d28-0xc90f6d2b. First byte 0x00 instead of 0xcc |
| 167 | INFO: Slab 0xc528c530 flags=0x400000c3 inuse=61 fp=0xc90f6d58 |
| 168 | INFO: Object 0xc90f6d20 @offset=3360 fp=0xc90f6d58 |
| 169 | INFO: Allocated in get_modalias+0x61/0xf5 age=53 cpu=1 pid=554 |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 170 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 171 | Bytes b4 0xc90f6d10: 00 00 00 00 00 00 00 00 5a 5a 5a 5a 5a 5a 5a 5a ........ZZZZZZZZ |
| 172 | Object 0xc90f6d20: 31 30 31 39 2e 30 30 35 1019.005 |
| 173 | Redzone 0xc90f6d28: 00 cc cc cc . |
| 174 | Padding 0xc90f6d50: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 175 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 176 | [<c010523d>] dump_trace+0x63/0x1eb |
| 177 | [<c01053df>] show_trace_log_lvl+0x1a/0x2f |
| 178 | [<c010601d>] show_trace+0x12/0x14 |
| 179 | [<c0106035>] dump_stack+0x16/0x18 |
| 180 | [<c017e0fa>] object_err+0x143/0x14b |
| 181 | [<c017e2cc>] check_object+0x66/0x234 |
| 182 | [<c017eb43>] __slab_free+0x239/0x384 |
| 183 | [<c017f446>] kfree+0xa6/0xc6 |
| 184 | [<c02e2335>] get_modalias+0xb9/0xf5 |
| 185 | [<c02e23b7>] dmi_dev_uevent+0x27/0x3c |
| 186 | [<c027866a>] dev_uevent+0x1ad/0x1da |
| 187 | [<c0205024>] kobject_uevent_env+0x20a/0x45b |
| 188 | [<c020527f>] kobject_uevent+0xa/0xf |
| 189 | [<c02779f1>] store_uevent+0x4f/0x58 |
| 190 | [<c027758e>] dev_attr_store+0x29/0x2f |
| 191 | [<c01bec4f>] sysfs_write_file+0x16e/0x19c |
| 192 | [<c0183ba7>] vfs_write+0xd1/0x15a |
| 193 | [<c01841d7>] sys_write+0x3d/0x72 |
| 194 | [<c0104112>] sysenter_past_esp+0x5f/0x99 |
| 195 | [<b7f7b410>] 0xb7f7b410 |
| 196 | ======================= |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 197 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 198 | FIX kmalloc-8: Restoring Redzone 0xc90f6d28-0xc90f6d2b=0xcc |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 199 | |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 200 | If SLUB encounters a corrupted object (full detection requires the kernel |
| 201 | to be booted with slub_debug) then the following output will be dumped |
| 202 | into the syslog: |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 203 | |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 204 | 1. Description of the problem encountered |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 205 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 206 | This will be a message in the system log starting with:: |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 207 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 208 | =============================================== |
| 209 | BUG <slab cache affected>: <What went wrong> |
| 210 | ----------------------------------------------- |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 211 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 212 | INFO: <corruption start>-<corruption_end> <more info> |
| 213 | INFO: Slab <address> <slab information> |
| 214 | INFO: Object <address> <object information> |
| 215 | INFO: Allocated in <kernel function> age=<jiffies since alloc> cpu=<allocated by |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 216 | cpu> pid=<pid of the process> |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 217 | INFO: Freed in <kernel function> age=<jiffies since free> cpu=<freed by cpu> |
| 218 | pid=<pid of the process> |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 219 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 220 | (Object allocation / free information is only available if SLAB_STORE_USER is |
| 221 | set for the slab. slub_debug sets that option) |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 222 | |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 223 | 2. The object contents if an object was involved. |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 224 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 225 | Various types of lines can follow the BUG SLUB line: |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 226 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 227 | Bytes b4 <address> : <bytes> |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 228 | Shows a few bytes before the object where the problem was detected. |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 229 | Can be useful if the corruption does not stop with the start of the |
| 230 | object. |
| 231 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 232 | Object <address> : <bytes> |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 233 | The bytes of the object. If the object is inactive then the bytes |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 234 | typically contain poison values. Any non-poison value shows a |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 235 | corruption by a write after free. |
| 236 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 237 | Redzone <address> : <bytes> |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 238 | The Redzone following the object. The Redzone is used to detect |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 239 | writes after the object. All bytes should always have the same |
| 240 | value. If there is any deviation then it is due to a write after |
| 241 | the object boundary. |
| 242 | |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 243 | (Redzone information is only available if SLAB_RED_ZONE is set. |
| 244 | slub_debug sets that option) |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 245 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 246 | Padding <address> : <bytes> |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 247 | Unused data to fill up the space in order to get the next object |
| 248 | properly aligned. In the debug case we make sure that there are |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 249 | at least 4 bytes of padding. This allows the detection of writes |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 250 | before the object. |
| 251 | |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 252 | 3. A stackdump |
Christoph Lameter | c1aee21 | 2007-05-31 00:40:47 -0700 | [diff] [blame] | 253 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 254 | The stackdump describes the location where the error was detected. The cause |
| 255 | of the corruption is may be more likely found by looking at the function that |
| 256 | allocated or freed the object. |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 257 | |
| 258 | 4. Report on how the problem was dealt with in order to ensure the continued |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 259 | operation of the system. |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 260 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 261 | These are messages in the system log beginning with:: |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 262 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 263 | FIX <slab cache affected>: <corrective action taken> |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 264 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 265 | In the above sample SLUB found that the Redzone of an active object has |
| 266 | been overwritten. Here a string of 8 characters was written into a slab that |
| 267 | has the length of 8 characters. However, a 8 character string needs a |
| 268 | terminating 0. That zero has overwritten the first byte of the Redzone field. |
| 269 | After reporting the details of the issue encountered the FIX SLUB message |
| 270 | tells us that SLUB has restored the Redzone to its proper value and then |
| 271 | system operations continue. |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 272 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 273 | Emergency operations |
| 274 | ==================== |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 275 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 276 | Minimal debugging (sanity checks alone) can be enabled by booting with:: |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 277 | |
| 278 | slub_debug=F |
| 279 | |
| 280 | This will be generally be enough to enable the resiliency features of slub |
| 281 | which will keep the system running even if a bad kernel component will |
| 282 | keep corrupting objects. This may be important for production systems. |
| 283 | Performance will be impacted by the sanity checks and there will be a |
| 284 | continual stream of error messages to the syslog but no additional memory |
| 285 | will be used (unlike full debugging). |
| 286 | |
| 287 | No guarantees. The kernel component still needs to be fixed. Performance |
| 288 | may be optimized further by locating the slab that experiences corruption |
| 289 | and enabling debugging only for that cache |
| 290 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 291 | I.e.:: |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 292 | |
| 293 | slub_debug=F,dentry |
| 294 | |
| 295 | If the corruption occurs by writing after the end of the object then it |
| 296 | may be advisable to enable a Redzone to avoid corrupting the beginning |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 297 | of other objects:: |
Christoph Lameter | 2492268 | 2007-07-17 04:03:18 -0700 | [diff] [blame] | 298 | |
| 299 | slub_debug=FZ,dentry |
| 300 | |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 301 | Extended slabinfo mode and plotting |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 302 | =================================== |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 303 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 304 | The ``slabinfo`` tool has a special 'extended' ('-X') mode that includes: |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 305 | - Slabcache Totals |
| 306 | - Slabs sorted by size (up to -N <num> slabs, default 1) |
| 307 | - Slabs sorted by loss (up to -N <num> slabs, default 1) |
| 308 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 309 | Additionally, in this mode ``slabinfo`` does not dynamically scale |
| 310 | sizes (G/M/K) and reports everything in bytes (this functionality is |
| 311 | also available to other slabinfo modes via '-B' option) which makes |
| 312 | reporting more precise and accurate. Moreover, in some sense the `-X' |
| 313 | mode also simplifies the analysis of slabs' behaviour, because its |
| 314 | output can be plotted using the ``slabinfo-gnuplot.sh`` script. So it |
| 315 | pushes the analysis from looking through the numbers (tons of numbers) |
| 316 | to something easier -- visual analysis. |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 317 | |
| 318 | To generate plots: |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 319 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 320 | a) collect slabinfo extended records, for example:: |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 321 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 322 | while [ 1 ]; do slabinfo -X >> FOO_STATS; sleep 1; done |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 323 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 324 | b) pass stats file(-s) to ``slabinfo-gnuplot.sh`` script:: |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 325 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 326 | slabinfo-gnuplot.sh FOO_STATS [FOO_STATS2 .. FOO_STATSN] |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 327 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 328 | The ``slabinfo-gnuplot.sh`` script will pre-processes the collected records |
| 329 | and generates 3 png files (and 3 pre-processing cache files) per STATS |
| 330 | file: |
| 331 | - Slabcache Totals: FOO_STATS-totals.png |
| 332 | - Slabs sorted by size: FOO_STATS-slabs-by-size.png |
| 333 | - Slabs sorted by loss: FOO_STATS-slabs-by-loss.png |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 334 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 335 | Another use case, when ``slabinfo-gnuplot.sh`` can be useful, is when you |
| 336 | need to compare slabs' behaviour "prior to" and "after" some code |
| 337 | modification. To help you out there, ``slabinfo-gnuplot.sh`` script |
| 338 | can 'merge' the `Slabcache Totals` sections from different |
| 339 | measurements. To visually compare N plots: |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 340 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 341 | a) Collect as many STATS1, STATS2, .. STATSN files as you need:: |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 342 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 343 | while [ 1 ]; do slabinfo -X >> STATS<X>; sleep 1; done |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 344 | |
Mike Rapoport | 0c14398 | 2018-03-21 21:22:37 +0200 | [diff] [blame] | 345 | b) Pre-process those STATS files:: |
| 346 | |
| 347 | slabinfo-gnuplot.sh STATS1 STATS2 .. STATSN |
| 348 | |
| 349 | c) Execute ``slabinfo-gnuplot.sh`` in '-t' mode, passing all of the |
| 350 | generated pre-processed \*-totals:: |
| 351 | |
| 352 | slabinfo-gnuplot.sh -t STATS1-totals STATS2-totals .. STATSN-totals |
| 353 | |
| 354 | This will produce a single plot (png file). |
| 355 | |
| 356 | Plots, expectedly, can be large so some fluctuations or small spikes |
| 357 | can go unnoticed. To deal with that, ``slabinfo-gnuplot.sh`` has two |
| 358 | options to 'zoom-in'/'zoom-out': |
| 359 | |
| 360 | a) ``-s %d,%d`` -- overwrites the default image width and heigh |
| 361 | b) ``-r %d,%d`` -- specifies a range of samples to use (for example, |
| 362 | in ``slabinfo -X >> FOO_STATS; sleep 1;`` case, using a ``-r |
| 363 | 40,60`` range will plot only samples collected between 40th and |
| 364 | 60th seconds). |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 365 | |
Christoph Lameter | cde5353 | 2008-07-04 09:59:22 -0700 | [diff] [blame] | 366 | Christoph Lameter, May 30, 2007 |
Sergey Senozhatsky | 05be961 | 2015-10-23 08:51:45 +0900 | [diff] [blame] | 367 | Sergey Senozhatsky, October 23, 2015 |