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