blob: bb1f5c6e28b3eaf89fc2f8a3b401311c855f8b26 [file] [log] [blame]
Christoph Lameter35243422007-05-06 14:49:47 -07001Short users guide for SLUB
2--------------------------
3
Christoph Lameter35243422007-05-06 14:49:47 -07004The basic philosophy of SLUB is very different from SLAB. SLAB
5requires rebuilding the kernel to activate debug options for all
Christoph Lameterc1aee212007-05-31 00:40:47 -07006slab caches. SLUB always includes full debugging but it is off by default.
Christoph Lameter35243422007-05-06 14:49:47 -07007SLUB 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)
Christoph Lameterf0630ff2007-07-15 23:38:14 -070044 - Switch all debugging off (useful if the kernel is
45 configured with CONFIG_SLUB_DEBUG_ON)
Christoph Lameter35243422007-05-06 14:49:47 -070046
47F.e. in order to boot just with sanity checks and red zoning one would specify:
48
49 slub_debug=FZ
50
51Trying to find an issue in the dentry cache? Try
52
Itaru Kitayama989a7242008-03-05 15:07:30 -080053 slub_debug=,dentry
Christoph Lameter35243422007-05-06 14:49:47 -070054
55to only enable debugging on the dentry cache.
56
57Red zoning and tracking may realign the slab. We can just apply sanity checks
58to the dentry cache with
59
Itaru Kitayama989a7242008-03-05 15:07:30 -080060 slub_debug=F,dentry
Christoph Lameter35243422007-05-06 14:49:47 -070061
62In case you forgot to enable debugging on the kernel command line: It is
63possible to enable debugging manually when the kernel is up. Look at the
64contents of:
65
Greg Kroah-Hartman081248d2007-11-01 09:29:06 -060066/sys/kernel/slab/<slab name>/
Christoph Lameter35243422007-05-06 14:49:47 -070067
68Look at the writable files. Writing 1 to them will enable the
69corresponding debug option. All options can be set on a slab that does
70not contain objects. If the slab already contains objects then sanity checks
71and tracing may only be enabled. The other options may cause the realignment
72of objects.
73
74Careful with tracing: It may spew out lots of information and never stop if
75used on the wrong slab.
76
Christoph Lameterc1aee212007-05-31 00:40:47 -070077Slab merging
Christoph Lameter35243422007-05-06 14:49:47 -070078------------
79
Christoph Lameterc1aee212007-05-31 00:40:47 -070080If no debug options are specified then SLUB may merge similar slabs together
Christoph Lameter35243422007-05-06 14:49:47 -070081in order to reduce overhead and increase cache hotness of objects.
82slabinfo -a displays which slabs were merged together.
83
Christoph Lameterc1aee212007-05-31 00:40:47 -070084Slab validation
85---------------
86
87SLUB can validate all object if the kernel was booted with slub_debug. In
88order to do so you must have the slabinfo tool. Then you can do
89
90slabinfo -v
91
92which will test all objects. Output will be generated to the syslog.
93
94This also works in a more limited way if boot was without slab debug.
95In that case slabinfo -v simply tests all reachable objects. Usually
96these are in the cpu slabs and the partial slabs. Full slabs are not
97tracked by SLUB in a non debug situation.
98
Christoph Lameter35243422007-05-06 14:49:47 -070099Getting more performance
100------------------------
101
102To some degree SLUB's performance is limited by the need to take the
103list_lock once in a while to deal with partial slabs. That overhead is
104governed by the order of the allocation for each slab. The allocations
105can be influenced by kernel parameters:
106
Christoph Lameterc1aee212007-05-31 00:40:47 -0700107slub_min_objects=x (default 4)
Christoph Lameter35243422007-05-06 14:49:47 -0700108slub_min_order=x (default 0)
Christoph Lameterc1aee212007-05-31 00:40:47 -0700109slub_max_order=x (default 1)
Christoph Lameter35243422007-05-06 14:49:47 -0700110
111slub_min_objects allows to specify how many objects must at least fit
112into one slab in order for the allocation order to be acceptable.
113In general slub will be able to perform this number of allocations
114on a slab without consulting centralized resources (list_lock) where
115contention may occur.
116
117slub_min_order specifies a minim order of slabs. A similar effect like
118slub_min_objects.
119
120slub_max_order specified the order at which slub_min_objects should no
121longer be checked. This is useful to avoid SLUB trying to generate
122super large order pages to fit slub_min_objects of a slab cache with
123large object sizes into one high order page.
124
Christoph Lameterc1aee212007-05-31 00:40:47 -0700125SLUB Debug output
126-----------------
Christoph Lameter35243422007-05-06 14:49:47 -0700127
Christoph Lameterc1aee212007-05-31 00:40:47 -0700128Here is a sample of slub debug output:
129
Christoph Lameter24922682007-07-17 04:03:18 -0700130====================================================================
131BUG kmalloc-8: Redzone overwritten
132--------------------------------------------------------------------
133
134INFO: 0xc90f6d28-0xc90f6d2b. First byte 0x00 instead of 0xcc
135INFO: Slab 0xc528c530 flags=0x400000c3 inuse=61 fp=0xc90f6d58
136INFO: Object 0xc90f6d20 @offset=3360 fp=0xc90f6d58
137INFO: Allocated in get_modalias+0x61/0xf5 age=53 cpu=1 pid=554
138
139Bytes b4 0xc90f6d10: 00 00 00 00 00 00 00 00 5a 5a 5a 5a 5a 5a 5a 5a ........ZZZZZZZZ
140 Object 0xc90f6d20: 31 30 31 39 2e 30 30 35 1019.005
141 Redzone 0xc90f6d28: 00 cc cc cc .
142 Padding 0xc90f6d50: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ
143
Christoph Lameterc1aee212007-05-31 00:40:47 -0700144 [<c010523d>] dump_trace+0x63/0x1eb
145 [<c01053df>] show_trace_log_lvl+0x1a/0x2f
146 [<c010601d>] show_trace+0x12/0x14
147 [<c0106035>] dump_stack+0x16/0x18
148 [<c017e0fa>] object_err+0x143/0x14b
149 [<c017e2cc>] check_object+0x66/0x234
150 [<c017eb43>] __slab_free+0x239/0x384
151 [<c017f446>] kfree+0xa6/0xc6
152 [<c02e2335>] get_modalias+0xb9/0xf5
153 [<c02e23b7>] dmi_dev_uevent+0x27/0x3c
154 [<c027866a>] dev_uevent+0x1ad/0x1da
155 [<c0205024>] kobject_uevent_env+0x20a/0x45b
156 [<c020527f>] kobject_uevent+0xa/0xf
157 [<c02779f1>] store_uevent+0x4f/0x58
158 [<c027758e>] dev_attr_store+0x29/0x2f
159 [<c01bec4f>] sysfs_write_file+0x16e/0x19c
160 [<c0183ba7>] vfs_write+0xd1/0x15a
161 [<c01841d7>] sys_write+0x3d/0x72
162 [<c0104112>] sysenter_past_esp+0x5f/0x99
163 [<b7f7b410>] 0xb7f7b410
164 =======================
Christoph Lameterc1aee212007-05-31 00:40:47 -0700165
Christoph Lameter24922682007-07-17 04:03:18 -0700166FIX kmalloc-8: Restoring Redzone 0xc90f6d28-0xc90f6d2b=0xcc
Christoph Lameterc1aee212007-05-31 00:40:47 -0700167
Christoph Lameter24922682007-07-17 04:03:18 -0700168If SLUB encounters a corrupted object (full detection requires the kernel
169to be booted with slub_debug) then the following output will be dumped
170into the syslog:
Christoph Lameterc1aee212007-05-31 00:40:47 -0700171
Christoph Lameter24922682007-07-17 04:03:18 -07001721. Description of the problem encountered
Christoph Lameterc1aee212007-05-31 00:40:47 -0700173
174This will be a message in the system log starting with
175
Christoph Lameter24922682007-07-17 04:03:18 -0700176===============================================
177BUG <slab cache affected>: <What went wrong>
178-----------------------------------------------
Christoph Lameterc1aee212007-05-31 00:40:47 -0700179
Christoph Lameter24922682007-07-17 04:03:18 -0700180INFO: <corruption start>-<corruption_end> <more info>
181INFO: Slab <address> <slab information>
182INFO: Object <address> <object information>
183INFO: Allocated in <kernel function> age=<jiffies since alloc> cpu=<allocated by
184 cpu> pid=<pid of the process>
185INFO: Freed in <kernel function> age=<jiffies since free> cpu=<freed by cpu>
186 pid=<pid of the process>
Christoph Lameterc1aee212007-05-31 00:40:47 -0700187
Christoph Lameter24922682007-07-17 04:03:18 -0700188(Object allocation / free information is only available if SLAB_STORE_USER is
189set for the slab. slub_debug sets that option)
Christoph Lameterc1aee212007-05-31 00:40:47 -0700190
Christoph Lameter24922682007-07-17 04:03:18 -07001912. The object contents if an object was involved.
Christoph Lameterc1aee212007-05-31 00:40:47 -0700192
Christoph Lameter24922682007-07-17 04:03:18 -0700193Various types of lines can follow the BUG SLUB line:
Christoph Lameterc1aee212007-05-31 00:40:47 -0700194
195Bytes b4 <address> : <bytes>
Christoph Lameter24922682007-07-17 04:03:18 -0700196 Shows a few bytes before the object where the problem was detected.
Christoph Lameterc1aee212007-05-31 00:40:47 -0700197 Can be useful if the corruption does not stop with the start of the
198 object.
199
200Object <address> : <bytes>
201 The bytes of the object. If the object is inactive then the bytes
Christoph Lameter24922682007-07-17 04:03:18 -0700202 typically contain poison values. Any non-poison value shows a
Christoph Lameterc1aee212007-05-31 00:40:47 -0700203 corruption by a write after free.
204
205Redzone <address> : <bytes>
Christoph Lameter24922682007-07-17 04:03:18 -0700206 The Redzone following the object. The Redzone is used to detect
Christoph Lameterc1aee212007-05-31 00:40:47 -0700207 writes after the object. All bytes should always have the same
208 value. If there is any deviation then it is due to a write after
209 the object boundary.
210
Christoph Lameter24922682007-07-17 04:03:18 -0700211 (Redzone information is only available if SLAB_RED_ZONE is set.
212 slub_debug sets that option)
Christoph Lameterc1aee212007-05-31 00:40:47 -0700213
Christoph Lameter24922682007-07-17 04:03:18 -0700214Padding <address> : <bytes>
Christoph Lameterc1aee212007-05-31 00:40:47 -0700215 Unused data to fill up the space in order to get the next object
216 properly aligned. In the debug case we make sure that there are
Christoph Lameter24922682007-07-17 04:03:18 -0700217 at least 4 bytes of padding. This allows the detection of writes
Christoph Lameterc1aee212007-05-31 00:40:47 -0700218 before the object.
219
Christoph Lameter24922682007-07-17 04:03:18 -07002203. A stackdump
Christoph Lameterc1aee212007-05-31 00:40:47 -0700221
Christoph Lameter24922682007-07-17 04:03:18 -0700222The stackdump describes the location where the error was detected. The cause
223of the corruption is may be more likely found by looking at the function that
224allocated or freed the object.
225
2264. Report on how the problem was dealt with in order to ensure the continued
227operation of the system.
228
229These are messages in the system log beginning with
230
231FIX <slab cache affected>: <corrective action taken>
232
233In the above sample SLUB found that the Redzone of an active object has
234been overwritten. Here a string of 8 characters was written into a slab that
235has the length of 8 characters. However, a 8 character string needs a
236terminating 0. That zero has overwritten the first byte of the Redzone field.
237After reporting the details of the issue encountered the FIX SLUB message
238tell us that SLUB has restored the Redzone to its proper value and then
239system operations continue.
240
241Emergency operations:
242---------------------
243
244Minimal debugging (sanity checks alone) can be enabled by booting with
245
246 slub_debug=F
247
248This will be generally be enough to enable the resiliency features of slub
249which will keep the system running even if a bad kernel component will
250keep corrupting objects. This may be important for production systems.
251Performance will be impacted by the sanity checks and there will be a
252continual stream of error messages to the syslog but no additional memory
253will be used (unlike full debugging).
254
255No guarantees. The kernel component still needs to be fixed. Performance
256may be optimized further by locating the slab that experiences corruption
257and enabling debugging only for that cache
258
259I.e.
260
261 slub_debug=F,dentry
262
263If the corruption occurs by writing after the end of the object then it
264may be advisable to enable a Redzone to avoid corrupting the beginning
265of other objects.
266
267 slub_debug=FZ,dentry
268
Christoph Lametercde53532008-07-04 09:59:22 -0700269Christoph Lameter, May 30, 2007