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