Linux Audio

Check our new training course

Loading...
v6.13.7
 
 
  1==========================
  2Short users guide for SLUB
  3==========================
  4
  5The basic philosophy of SLUB is very different from SLAB. SLAB
  6requires rebuilding the kernel to activate debug options for all
  7slab caches. SLUB always includes full debugging but it is off by default.
  8SLUB can enable debugging only for selected slabs in order to avoid
  9an impact on overall system performance which may make a bug more
 10difficult to find.
 11
 12In order to switch debugging on one can add an option ``slab_debug``
 13to the kernel command line. That will enable full debugging for
 14all slabs.
 15
 16Typically one would then use the ``slabinfo`` command to get statistical
 17data and perform operation on the slabs. By default ``slabinfo`` only lists
 18slabs that have data in them. See "slabinfo -h" for more options when
 19running the command. ``slabinfo`` can be compiled with
 20::
 21
 22	gcc -o slabinfo tools/mm/slabinfo.c
 23
 24Some of the modes of operation of ``slabinfo`` require that slub debugging
 25be enabled on the command line. F.e. no tracking information will be
 26available without debugging on and validation can only partially
 27be performed if debugging was not switched on.
 28
 29Some more sophisticated uses of slab_debug:
 30-------------------------------------------
 31
 32Parameters may be given to ``slab_debug``. If none is specified then full
 33debugging is enabled. Format:
 34
 35slab_debug=<Debug-Options>
 36	Enable options for all slabs
 37
 38slab_debug=<Debug-Options>,<slab name1>,<slab name2>,...
 39	Enable options only for select slabs (no spaces
 40	after a comma)
 41
 42Multiple blocks of options for all slabs or selected slabs can be given, with
 43blocks of options delimited by ';'. The last of "all slabs" blocks is applied
 44to all slabs except those that match one of the "select slabs" block. Options
 45of the first "select slabs" blocks that matches the slab's name are applied.
 46
 47Possible debug options are::
 48
 49	F		Sanity checks on (enables SLAB_DEBUG_CONSISTENCY_CHECKS
 50			Sorry SLAB legacy issues)
 51	Z		Red zoning
 52	P		Poisoning (object and padding)
 53	U		User tracking (free and alloc)
 54	T		Trace (please only use on single slabs)
 55	A		Enable failslab filter mark for the cache
 56	O		Switch debugging off for caches that would have
 57			caused higher minimum slab orders
 58	-		Switch all debugging off (useful if the kernel is
 59			configured with CONFIG_SLUB_DEBUG_ON)
 60
 61F.e. in order to boot just with sanity checks and red zoning one would specify::
 62
 63	slab_debug=FZ
 64
 65Trying to find an issue in the dentry cache? Try::
 66
 67	slab_debug=,dentry
 68
 69to only enable debugging on the dentry cache.  You may use an asterisk at the
 70end of the slab name, in order to cover all slabs with the same prefix.  For
 71example, here's how you can poison the dentry cache as well as all kmalloc
 72slabs::
 73
 74	slab_debug=P,kmalloc-*,dentry
 75
 76Red zoning and tracking may realign the slab.  We can just apply sanity checks
 77to the dentry cache with::
 78
 79	slab_debug=F,dentry
 80
 81Debugging options may require the minimum possible slab order to increase as
 82a result of storing the metadata (for example, caches with PAGE_SIZE object
 83sizes).  This has a higher likelihood of resulting in slab allocation errors
 84in low memory situations or if there's high fragmentation of memory.  To
 85switch off debugging for such caches by default, use::
 86
 87	slab_debug=O
 88
 89You can apply different options to different list of slab names, using blocks
 90of options. This will enable red zoning for dentry and user tracking for
 91kmalloc. All other slabs will not get any debugging enabled::
 92
 93	slab_debug=Z,dentry;U,kmalloc-*
 94
 95You can also enable options (e.g. sanity checks and poisoning) for all caches
 96except some that are deemed too performance critical and don't need to be
 97debugged by specifying global debug options followed by a list of slab names
 98with "-" as options::
 99
100	slab_debug=FZ;-,zs_handle,zspage
101
102The state of each debug option for a slab can be found in the respective files
103under::
104
105	/sys/kernel/slab/<slab name>/
106
107If the file contains 1, the option is enabled, 0 means disabled. The debug
108options from the ``slab_debug`` parameter translate to the following files::
109
110	F	sanity_checks
111	Z	red_zone
112	P	poison
113	U	store_user
114	T	trace
115	A	failslab
116
117failslab file is writable, so writing 1 or 0 will enable or disable
118the option at runtime. Write returns -EINVAL if cache is an alias.
119Careful with tracing: It may spew out lots of information and never stop if
120used on the wrong slab.
121
122Slab merging
123============
124
125If no debug options are specified then SLUB may merge similar slabs together
126in order to reduce overhead and increase cache hotness of objects.
127``slabinfo -a`` displays which slabs were merged together.
128
129Slab validation
130===============
131
132SLUB can validate all object if the kernel was booted with slab_debug. In
133order to do so you must have the ``slabinfo`` tool. Then you can do
134::
135
136	slabinfo -v
137
138which will test all objects. Output will be generated to the syslog.
139
140This also works in a more limited way if boot was without slab debug.
141In that case ``slabinfo -v`` simply tests all reachable objects. Usually
142these are in the cpu slabs and the partial slabs. Full slabs are not
143tracked by SLUB in a non debug situation.
144
145Getting more performance
146========================
147
148To some degree SLUB's performance is limited by the need to take the
149list_lock once in a while to deal with partial slabs. That overhead is
150governed by the order of the allocation for each slab. The allocations
151can be influenced by kernel parameters:
152
153.. slab_min_objects=x		(default: automatically scaled by number of cpus)
154.. slab_min_order=x		(default 0)
155.. slab_max_order=x		(default 3 (PAGE_ALLOC_COSTLY_ORDER))
156
157``slab_min_objects``
158	allows to specify how many objects must at least fit into one
159	slab in order for the allocation order to be acceptable.  In
160	general slub will be able to perform this number of
161	allocations on a slab without consulting centralized resources
162	(list_lock) where contention may occur.
163
164``slab_min_order``
165	specifies a minimum order of slabs. A similar effect like
166	``slab_min_objects``.
167
168``slab_max_order``
169	specified the order at which ``slab_min_objects`` should no
170	longer be checked. This is useful to avoid SLUB trying to
171	generate super large order pages to fit ``slab_min_objects``
172	of a slab cache with large object sizes into one high order
173	page. Setting command line parameter
174	``debug_guardpage_minorder=N`` (N > 0), forces setting
175	``slab_max_order`` to 0, what cause minimum possible order of
176	slabs allocation.
177
178``slab_strict_numa``
179        Enables the application of memory policies on each
180        allocation. This results in more accurate placement of
181        objects which may result in the reduction of accesses
182        to remote nodes. The default is to only apply memory
183        policies at the folio level when a new folio is acquired
184        or a folio is retrieved from the lists. Enabling this
185        option reduces the fastpath performance of the slab allocator.
186
187SLUB Debug output
188=================
189
190Here is a sample of slub debug output::
191
192 ====================================================================
193 BUG kmalloc-8: Right Redzone overwritten
194 --------------------------------------------------------------------
195
196 INFO: 0xc90f6d28-0xc90f6d2b. First byte 0x00 instead of 0xcc
197 INFO: Slab 0xc528c530 flags=0x400000c3 inuse=61 fp=0xc90f6d58
198 INFO: Object 0xc90f6d20 @offset=3360 fp=0xc90f6d58
199 INFO: Allocated in get_modalias+0x61/0xf5 age=53 cpu=1 pid=554
200
201 Bytes b4 (0xc90f6d10): 00 00 00 00 00 00 00 00 5a 5a 5a 5a 5a 5a 5a 5a ........ZZZZZZZZ
202 Object   (0xc90f6d20): 31 30 31 39 2e 30 30 35                         1019.005
203 Redzone  (0xc90f6d28): 00 cc cc cc                                     .
204 Padding  (0xc90f6d50): 5a 5a 5a 5a 5a 5a 5a 5a                         ZZZZZZZZ
205
206   [<c010523d>] dump_trace+0x63/0x1eb
207   [<c01053df>] show_trace_log_lvl+0x1a/0x2f
208   [<c010601d>] show_trace+0x12/0x14
209   [<c0106035>] dump_stack+0x16/0x18
210   [<c017e0fa>] object_err+0x143/0x14b
211   [<c017e2cc>] check_object+0x66/0x234
212   [<c017eb43>] __slab_free+0x239/0x384
213   [<c017f446>] kfree+0xa6/0xc6
214   [<c02e2335>] get_modalias+0xb9/0xf5
215   [<c02e23b7>] dmi_dev_uevent+0x27/0x3c
216   [<c027866a>] dev_uevent+0x1ad/0x1da
217   [<c0205024>] kobject_uevent_env+0x20a/0x45b
218   [<c020527f>] kobject_uevent+0xa/0xf
219   [<c02779f1>] store_uevent+0x4f/0x58
220   [<c027758e>] dev_attr_store+0x29/0x2f
221   [<c01bec4f>] sysfs_write_file+0x16e/0x19c
222   [<c0183ba7>] vfs_write+0xd1/0x15a
223   [<c01841d7>] sys_write+0x3d/0x72
224   [<c0104112>] sysenter_past_esp+0x5f/0x99
225   [<b7f7b410>] 0xb7f7b410
226   =======================
227
228 FIX kmalloc-8: Restoring Redzone 0xc90f6d28-0xc90f6d2b=0xcc
229
230If SLUB encounters a corrupted object (full detection requires the kernel
231to be booted with slab_debug) then the following output will be dumped
232into the syslog:
233
2341. Description of the problem encountered
235
236   This will be a message in the system log starting with::
237
238     ===============================================
239     BUG <slab cache affected>: <What went wrong>
240     -----------------------------------------------
241
242     INFO: <corruption start>-<corruption_end> <more info>
243     INFO: Slab <address> <slab information>
244     INFO: Object <address> <object information>
245     INFO: Allocated in <kernel function> age=<jiffies since alloc> cpu=<allocated by
246	cpu> pid=<pid of the process>
247     INFO: Freed in <kernel function> age=<jiffies since free> cpu=<freed by cpu>
248	pid=<pid of the process>
249
250   (Object allocation / free information is only available if SLAB_STORE_USER is
251   set for the slab. slab_debug sets that option)
252
2532. The object contents if an object was involved.
254
255   Various types of lines can follow the BUG SLUB line:
256
257   Bytes b4 <address> : <bytes>
258	Shows a few bytes before the object where the problem was detected.
259	Can be useful if the corruption does not stop with the start of the
260	object.
261
262   Object <address> : <bytes>
263	The bytes of the object. If the object is inactive then the bytes
264	typically contain poison values. Any non-poison value shows a
265	corruption by a write after free.
266
267   Redzone <address> : <bytes>
268	The Redzone following the object. The Redzone is used to detect
269	writes after the object. All bytes should always have the same
270	value. If there is any deviation then it is due to a write after
271	the object boundary.
272
273	(Redzone information is only available if SLAB_RED_ZONE is set.
274	slab_debug sets that option)
275
276   Padding <address> : <bytes>
277	Unused data to fill up the space in order to get the next object
278	properly aligned. In the debug case we make sure that there are
279	at least 4 bytes of padding. This allows the detection of writes
280	before the object.
281
2823. A stackdump
283
284   The stackdump describes the location where the error was detected. The cause
285   of the corruption is may be more likely found by looking at the function that
286   allocated or freed the object.
287
2884. Report on how the problem was dealt with in order to ensure the continued
289   operation of the system.
290
291   These are messages in the system log beginning with::
292
293	FIX <slab cache affected>: <corrective action taken>
294
295   In the above sample SLUB found that the Redzone of an active object has
296   been overwritten. Here a string of 8 characters was written into a slab that
297   has the length of 8 characters. However, a 8 character string needs a
298   terminating 0. That zero has overwritten the first byte of the Redzone field.
299   After reporting the details of the issue encountered the FIX SLUB message
300   tells us that SLUB has restored the Redzone to its proper value and then
301   system operations continue.
302
303Emergency operations
304====================
305
306Minimal debugging (sanity checks alone) can be enabled by booting with::
307
308	slab_debug=F
309
310This will be generally be enough to enable the resiliency features of slub
311which will keep the system running even if a bad kernel component will
312keep corrupting objects. This may be important for production systems.
313Performance will be impacted by the sanity checks and there will be a
314continual stream of error messages to the syslog but no additional memory
315will be used (unlike full debugging).
316
317No guarantees. The kernel component still needs to be fixed. Performance
318may be optimized further by locating the slab that experiences corruption
319and enabling debugging only for that cache
320
321I.e.::
322
323	slab_debug=F,dentry
324
325If the corruption occurs by writing after the end of the object then it
326may be advisable to enable a Redzone to avoid corrupting the beginning
327of other objects::
328
329	slab_debug=FZ,dentry
330
331Extended slabinfo mode and plotting
332===================================
333
334The ``slabinfo`` tool has a special 'extended' ('-X') mode that includes:
335 - Slabcache Totals
336 - Slabs sorted by size (up to -N <num> slabs, default 1)
337 - Slabs sorted by loss (up to -N <num> slabs, default 1)
338
339Additionally, in this mode ``slabinfo`` does not dynamically scale
340sizes (G/M/K) and reports everything in bytes (this functionality is
341also available to other slabinfo modes via '-B' option) which makes
342reporting more precise and accurate. Moreover, in some sense the `-X'
343mode also simplifies the analysis of slabs' behaviour, because its
344output can be plotted using the ``slabinfo-gnuplot.sh`` script. So it
345pushes the analysis from looking through the numbers (tons of numbers)
346to something easier -- visual analysis.
347
348To generate plots:
349
350a) collect slabinfo extended records, for example::
351
352	while [ 1 ]; do slabinfo -X >> FOO_STATS; sleep 1; done
353
354b) pass stats file(-s) to ``slabinfo-gnuplot.sh`` script::
355
356	slabinfo-gnuplot.sh FOO_STATS [FOO_STATS2 .. FOO_STATSN]
357
358   The ``slabinfo-gnuplot.sh`` script will pre-processes the collected records
359   and generates 3 png files (and 3 pre-processing cache files) per STATS
360   file:
361   - Slabcache Totals: FOO_STATS-totals.png
362   - Slabs sorted by size: FOO_STATS-slabs-by-size.png
363   - Slabs sorted by loss: FOO_STATS-slabs-by-loss.png
364
365Another use case, when ``slabinfo-gnuplot.sh`` can be useful, is when you
366need to compare slabs' behaviour "prior to" and "after" some code
367modification.  To help you out there, ``slabinfo-gnuplot.sh`` script
368can 'merge' the `Slabcache Totals` sections from different
369measurements. To visually compare N plots:
370
371a) Collect as many STATS1, STATS2, .. STATSN files as you need::
372
373	while [ 1 ]; do slabinfo -X >> STATS<X>; sleep 1; done
374
375b) Pre-process those STATS files::
376
377	slabinfo-gnuplot.sh STATS1 STATS2 .. STATSN
378
379c) Execute ``slabinfo-gnuplot.sh`` in '-t' mode, passing all of the
380   generated pre-processed \*-totals::
381
382	slabinfo-gnuplot.sh -t STATS1-totals STATS2-totals .. STATSN-totals
383
384   This will produce a single plot (png file).
385
386   Plots, expectedly, can be large so some fluctuations or small spikes
387   can go unnoticed. To deal with that, ``slabinfo-gnuplot.sh`` has two
388   options to 'zoom-in'/'zoom-out':
389
390   a) ``-s %d,%d`` -- overwrites the default image width and height
391   b) ``-r %d,%d`` -- specifies a range of samples to use (for example,
392      in ``slabinfo -X >> FOO_STATS; sleep 1;`` case, using a ``-r
393      40,60`` range will plot only samples collected between 40th and
394      60th seconds).
395
396
397DebugFS files for SLUB
398======================
399
400For more information about current state of SLUB caches with the user tracking
401debug option enabled, debugfs files are available, typically under
402/sys/kernel/debug/slab/<cache>/ (created only for caches with enabled user
403tracking). There are 2 types of these files with the following debug
404information:
405
4061. alloc_traces::
407
408    Prints information about unique allocation traces of the currently
409    allocated objects. The output is sorted by frequency of each trace.
410
411    Information in the output:
412    Number of objects, allocating function, possible memory wastage of
413    kmalloc objects(total/per-object), minimal/average/maximal jiffies
414    since alloc, pid range of the allocating processes, cpu mask of
415    allocating cpus, numa node mask of origins of memory, and stack trace.
416
417    Example:::
418
419    338 pci_alloc_dev+0x2c/0xa0 waste=521872/1544 age=290837/291891/293509 pid=1 cpus=106 nodes=0-1
420        __kmem_cache_alloc_node+0x11f/0x4e0
421        kmalloc_trace+0x26/0xa0
422        pci_alloc_dev+0x2c/0xa0
423        pci_scan_single_device+0xd2/0x150
424        pci_scan_slot+0xf7/0x2d0
425        pci_scan_child_bus_extend+0x4e/0x360
426        acpi_pci_root_create+0x32e/0x3b0
427        pci_acpi_scan_root+0x2b9/0x2d0
428        acpi_pci_root_add.cold.11+0x110/0xb0a
429        acpi_bus_attach+0x262/0x3f0
430        device_for_each_child+0xb7/0x110
431        acpi_dev_for_each_child+0x77/0xa0
432        acpi_bus_attach+0x108/0x3f0
433        device_for_each_child+0xb7/0x110
434        acpi_dev_for_each_child+0x77/0xa0
435        acpi_bus_attach+0x108/0x3f0
436
4372. free_traces::
438
439    Prints information about unique freeing traces of the currently allocated
440    objects. The freeing traces thus come from the previous life-cycle of the
441    objects and are reported as not available for objects allocated for the first
442    time. The output is sorted by frequency of each trace.
443
444    Information in the output:
445    Number of objects, freeing function, minimal/average/maximal jiffies since free,
446    pid range of the freeing processes, cpu mask of freeing cpus, and stack trace.
447
448    Example:::
449
450    1980 <not-available> age=4294912290 pid=0 cpus=0
451    51 acpi_ut_update_ref_count+0x6a6/0x782 age=236886/237027/237772 pid=1 cpus=1
452	kfree+0x2db/0x420
453	acpi_ut_update_ref_count+0x6a6/0x782
454	acpi_ut_update_object_reference+0x1ad/0x234
455	acpi_ut_remove_reference+0x7d/0x84
456	acpi_rs_get_prt_method_data+0x97/0xd6
457	acpi_get_irq_routing_table+0x82/0xc4
458	acpi_pci_irq_find_prt_entry+0x8e/0x2e0
459	acpi_pci_irq_lookup+0x3a/0x1e0
460	acpi_pci_irq_enable+0x77/0x240
461	pcibios_enable_device+0x39/0x40
462	do_pci_enable_device.part.0+0x5d/0xe0
463	pci_enable_device_flags+0xfc/0x120
464	pci_enable_device+0x13/0x20
465	virtio_pci_probe+0x9e/0x170
466	local_pci_probe+0x48/0x80
467	pci_device_probe+0x105/0x1c0
468
469Christoph Lameter, May 30, 2007
470Sergey Senozhatsky, October 23, 2015
v6.2
  1.. _slub:
  2
  3==========================
  4Short users guide for SLUB
  5==========================
  6
  7The basic philosophy of SLUB is very different from SLAB. SLAB
  8requires rebuilding the kernel to activate debug options for all
  9slab caches. SLUB always includes full debugging but it is off by default.
 10SLUB can enable debugging only for selected slabs in order to avoid
 11an impact on overall system performance which may make a bug more
 12difficult to find.
 13
 14In order to switch debugging on one can add an option ``slub_debug``
 15to the kernel command line. That will enable full debugging for
 16all slabs.
 17
 18Typically one would then use the ``slabinfo`` command to get statistical
 19data and perform operation on the slabs. By default ``slabinfo`` only lists
 20slabs that have data in them. See "slabinfo -h" for more options when
 21running the command. ``slabinfo`` can be compiled with
 22::
 23
 24	gcc -o slabinfo tools/vm/slabinfo.c
 25
 26Some of the modes of operation of ``slabinfo`` require that slub debugging
 27be enabled on the command line. F.e. no tracking information will be
 28available without debugging on and validation can only partially
 29be performed if debugging was not switched on.
 30
 31Some more sophisticated uses of slub_debug:
 32-------------------------------------------
 33
 34Parameters may be given to ``slub_debug``. If none is specified then full
 35debugging is enabled. Format:
 36
 37slub_debug=<Debug-Options>
 38	Enable options for all slabs
 39
 40slub_debug=<Debug-Options>,<slab name1>,<slab name2>,...
 41	Enable options only for select slabs (no spaces
 42	after a comma)
 43
 44Multiple blocks of options for all slabs or selected slabs can be given, with
 45blocks of options delimited by ';'. The last of "all slabs" blocks is applied
 46to all slabs except those that match one of the "select slabs" block. Options
 47of the first "select slabs" blocks that matches the slab's name are applied.
 48
 49Possible debug options are::
 50
 51	F		Sanity checks on (enables SLAB_DEBUG_CONSISTENCY_CHECKS
 52			Sorry SLAB legacy issues)
 53	Z		Red zoning
 54	P		Poisoning (object and padding)
 55	U		User tracking (free and alloc)
 56	T		Trace (please only use on single slabs)
 57	A		Enable failslab filter mark for the cache
 58	O		Switch debugging off for caches that would have
 59			caused higher minimum slab orders
 60	-		Switch all debugging off (useful if the kernel is
 61			configured with CONFIG_SLUB_DEBUG_ON)
 62
 63F.e. in order to boot just with sanity checks and red zoning one would specify::
 64
 65	slub_debug=FZ
 66
 67Trying to find an issue in the dentry cache? Try::
 68
 69	slub_debug=,dentry
 70
 71to only enable debugging on the dentry cache.  You may use an asterisk at the
 72end of the slab name, in order to cover all slabs with the same prefix.  For
 73example, here's how you can poison the dentry cache as well as all kmalloc
 74slabs::
 75
 76	slub_debug=P,kmalloc-*,dentry
 77
 78Red zoning and tracking may realign the slab.  We can just apply sanity checks
 79to the dentry cache with::
 80
 81	slub_debug=F,dentry
 82
 83Debugging options may require the minimum possible slab order to increase as
 84a result of storing the metadata (for example, caches with PAGE_SIZE object
 85sizes).  This has a higher liklihood of resulting in slab allocation errors
 86in low memory situations or if there's high fragmentation of memory.  To
 87switch off debugging for such caches by default, use::
 88
 89	slub_debug=O
 90
 91You can apply different options to different list of slab names, using blocks
 92of options. This will enable red zoning for dentry and user tracking for
 93kmalloc. All other slabs will not get any debugging enabled::
 94
 95	slub_debug=Z,dentry;U,kmalloc-*
 96
 97You can also enable options (e.g. sanity checks and poisoning) for all caches
 98except some that are deemed too performance critical and don't need to be
 99debugged by specifying global debug options followed by a list of slab names
100with "-" as options::
101
102	slub_debug=FZ;-,zs_handle,zspage
103
104The state of each debug option for a slab can be found in the respective files
105under::
106
107	/sys/kernel/slab/<slab name>/
108
109If the file contains 1, the option is enabled, 0 means disabled. The debug
110options from the ``slub_debug`` parameter translate to the following files::
111
112	F	sanity_checks
113	Z	red_zone
114	P	poison
115	U	store_user
116	T	trace
117	A	failslab
118
119failslab file is writable, so writing 1 or 0 will enable or disable
120the option at runtime. Write returns -EINVAL if cache is an alias.
121Careful with tracing: It may spew out lots of information and never stop if
122used on the wrong slab.
123
124Slab merging
125============
126
127If no debug options are specified then SLUB may merge similar slabs together
128in order to reduce overhead and increase cache hotness of objects.
129``slabinfo -a`` displays which slabs were merged together.
130
131Slab validation
132===============
133
134SLUB can validate all object if the kernel was booted with slub_debug. In
135order to do so you must have the ``slabinfo`` tool. Then you can do
136::
137
138	slabinfo -v
139
140which will test all objects. Output will be generated to the syslog.
141
142This also works in a more limited way if boot was without slab debug.
143In that case ``slabinfo -v`` simply tests all reachable objects. Usually
144these are in the cpu slabs and the partial slabs. Full slabs are not
145tracked by SLUB in a non debug situation.
146
147Getting more performance
148========================
149
150To some degree SLUB's performance is limited by the need to take the
151list_lock once in a while to deal with partial slabs. That overhead is
152governed by the order of the allocation for each slab. The allocations
153can be influenced by kernel parameters:
154
155.. slub_min_objects=x		(default 4)
156.. slub_min_order=x		(default 0)
157.. slub_max_order=x		(default 3 (PAGE_ALLOC_COSTLY_ORDER))
158
159``slub_min_objects``
160	allows to specify how many objects must at least fit into one
161	slab in order for the allocation order to be acceptable.  In
162	general slub will be able to perform this number of
163	allocations on a slab without consulting centralized resources
164	(list_lock) where contention may occur.
165
166``slub_min_order``
167	specifies a minimum order of slabs. A similar effect like
168	``slub_min_objects``.
169
170``slub_max_order``
171	specified the order at which ``slub_min_objects`` should no
172	longer be checked. This is useful to avoid SLUB trying to
173	generate super large order pages to fit ``slub_min_objects``
174	of a slab cache with large object sizes into one high order
175	page. Setting command line parameter
176	``debug_guardpage_minorder=N`` (N > 0), forces setting
177	``slub_max_order`` to 0, what cause minimum possible order of
178	slabs allocation.
179
 
 
 
 
 
 
 
 
 
180SLUB Debug output
181=================
182
183Here is a sample of slub debug output::
184
185 ====================================================================
186 BUG kmalloc-8: Right Redzone overwritten
187 --------------------------------------------------------------------
188
189 INFO: 0xc90f6d28-0xc90f6d2b. First byte 0x00 instead of 0xcc
190 INFO: Slab 0xc528c530 flags=0x400000c3 inuse=61 fp=0xc90f6d58
191 INFO: Object 0xc90f6d20 @offset=3360 fp=0xc90f6d58
192 INFO: Allocated in get_modalias+0x61/0xf5 age=53 cpu=1 pid=554
193
194 Bytes b4 (0xc90f6d10): 00 00 00 00 00 00 00 00 5a 5a 5a 5a 5a 5a 5a 5a ........ZZZZZZZZ
195 Object   (0xc90f6d20): 31 30 31 39 2e 30 30 35                         1019.005
196 Redzone  (0xc90f6d28): 00 cc cc cc                                     .
197 Padding  (0xc90f6d50): 5a 5a 5a 5a 5a 5a 5a 5a                         ZZZZZZZZ
198
199   [<c010523d>] dump_trace+0x63/0x1eb
200   [<c01053df>] show_trace_log_lvl+0x1a/0x2f
201   [<c010601d>] show_trace+0x12/0x14
202   [<c0106035>] dump_stack+0x16/0x18
203   [<c017e0fa>] object_err+0x143/0x14b
204   [<c017e2cc>] check_object+0x66/0x234
205   [<c017eb43>] __slab_free+0x239/0x384
206   [<c017f446>] kfree+0xa6/0xc6
207   [<c02e2335>] get_modalias+0xb9/0xf5
208   [<c02e23b7>] dmi_dev_uevent+0x27/0x3c
209   [<c027866a>] dev_uevent+0x1ad/0x1da
210   [<c0205024>] kobject_uevent_env+0x20a/0x45b
211   [<c020527f>] kobject_uevent+0xa/0xf
212   [<c02779f1>] store_uevent+0x4f/0x58
213   [<c027758e>] dev_attr_store+0x29/0x2f
214   [<c01bec4f>] sysfs_write_file+0x16e/0x19c
215   [<c0183ba7>] vfs_write+0xd1/0x15a
216   [<c01841d7>] sys_write+0x3d/0x72
217   [<c0104112>] sysenter_past_esp+0x5f/0x99
218   [<b7f7b410>] 0xb7f7b410
219   =======================
220
221 FIX kmalloc-8: Restoring Redzone 0xc90f6d28-0xc90f6d2b=0xcc
222
223If SLUB encounters a corrupted object (full detection requires the kernel
224to be booted with slub_debug) then the following output will be dumped
225into the syslog:
226
2271. Description of the problem encountered
228
229   This will be a message in the system log starting with::
230
231     ===============================================
232     BUG <slab cache affected>: <What went wrong>
233     -----------------------------------------------
234
235     INFO: <corruption start>-<corruption_end> <more info>
236     INFO: Slab <address> <slab information>
237     INFO: Object <address> <object information>
238     INFO: Allocated in <kernel function> age=<jiffies since alloc> cpu=<allocated by
239	cpu> pid=<pid of the process>
240     INFO: Freed in <kernel function> age=<jiffies since free> cpu=<freed by cpu>
241	pid=<pid of the process>
242
243   (Object allocation / free information is only available if SLAB_STORE_USER is
244   set for the slab. slub_debug sets that option)
245
2462. The object contents if an object was involved.
247
248   Various types of lines can follow the BUG SLUB line:
249
250   Bytes b4 <address> : <bytes>
251	Shows a few bytes before the object where the problem was detected.
252	Can be useful if the corruption does not stop with the start of the
253	object.
254
255   Object <address> : <bytes>
256	The bytes of the object. If the object is inactive then the bytes
257	typically contain poison values. Any non-poison value shows a
258	corruption by a write after free.
259
260   Redzone <address> : <bytes>
261	The Redzone following the object. The Redzone is used to detect
262	writes after the object. All bytes should always have the same
263	value. If there is any deviation then it is due to a write after
264	the object boundary.
265
266	(Redzone information is only available if SLAB_RED_ZONE is set.
267	slub_debug sets that option)
268
269   Padding <address> : <bytes>
270	Unused data to fill up the space in order to get the next object
271	properly aligned. In the debug case we make sure that there are
272	at least 4 bytes of padding. This allows the detection of writes
273	before the object.
274
2753. A stackdump
276
277   The stackdump describes the location where the error was detected. The cause
278   of the corruption is may be more likely found by looking at the function that
279   allocated or freed the object.
280
2814. Report on how the problem was dealt with in order to ensure the continued
282   operation of the system.
283
284   These are messages in the system log beginning with::
285
286	FIX <slab cache affected>: <corrective action taken>
287
288   In the above sample SLUB found that the Redzone of an active object has
289   been overwritten. Here a string of 8 characters was written into a slab that
290   has the length of 8 characters. However, a 8 character string needs a
291   terminating 0. That zero has overwritten the first byte of the Redzone field.
292   After reporting the details of the issue encountered the FIX SLUB message
293   tells us that SLUB has restored the Redzone to its proper value and then
294   system operations continue.
295
296Emergency operations
297====================
298
299Minimal debugging (sanity checks alone) can be enabled by booting with::
300
301	slub_debug=F
302
303This will be generally be enough to enable the resiliency features of slub
304which will keep the system running even if a bad kernel component will
305keep corrupting objects. This may be important for production systems.
306Performance will be impacted by the sanity checks and there will be a
307continual stream of error messages to the syslog but no additional memory
308will be used (unlike full debugging).
309
310No guarantees. The kernel component still needs to be fixed. Performance
311may be optimized further by locating the slab that experiences corruption
312and enabling debugging only for that cache
313
314I.e.::
315
316	slub_debug=F,dentry
317
318If the corruption occurs by writing after the end of the object then it
319may be advisable to enable a Redzone to avoid corrupting the beginning
320of other objects::
321
322	slub_debug=FZ,dentry
323
324Extended slabinfo mode and plotting
325===================================
326
327The ``slabinfo`` tool has a special 'extended' ('-X') mode that includes:
328 - Slabcache Totals
329 - Slabs sorted by size (up to -N <num> slabs, default 1)
330 - Slabs sorted by loss (up to -N <num> slabs, default 1)
331
332Additionally, in this mode ``slabinfo`` does not dynamically scale
333sizes (G/M/K) and reports everything in bytes (this functionality is
334also available to other slabinfo modes via '-B' option) which makes
335reporting more precise and accurate. Moreover, in some sense the `-X'
336mode also simplifies the analysis of slabs' behaviour, because its
337output can be plotted using the ``slabinfo-gnuplot.sh`` script. So it
338pushes the analysis from looking through the numbers (tons of numbers)
339to something easier -- visual analysis.
340
341To generate plots:
342
343a) collect slabinfo extended records, for example::
344
345	while [ 1 ]; do slabinfo -X >> FOO_STATS; sleep 1; done
346
347b) pass stats file(-s) to ``slabinfo-gnuplot.sh`` script::
348
349	slabinfo-gnuplot.sh FOO_STATS [FOO_STATS2 .. FOO_STATSN]
350
351   The ``slabinfo-gnuplot.sh`` script will pre-processes the collected records
352   and generates 3 png files (and 3 pre-processing cache files) per STATS
353   file:
354   - Slabcache Totals: FOO_STATS-totals.png
355   - Slabs sorted by size: FOO_STATS-slabs-by-size.png
356   - Slabs sorted by loss: FOO_STATS-slabs-by-loss.png
357
358Another use case, when ``slabinfo-gnuplot.sh`` can be useful, is when you
359need to compare slabs' behaviour "prior to" and "after" some code
360modification.  To help you out there, ``slabinfo-gnuplot.sh`` script
361can 'merge' the `Slabcache Totals` sections from different
362measurements. To visually compare N plots:
363
364a) Collect as many STATS1, STATS2, .. STATSN files as you need::
365
366	while [ 1 ]; do slabinfo -X >> STATS<X>; sleep 1; done
367
368b) Pre-process those STATS files::
369
370	slabinfo-gnuplot.sh STATS1 STATS2 .. STATSN
371
372c) Execute ``slabinfo-gnuplot.sh`` in '-t' mode, passing all of the
373   generated pre-processed \*-totals::
374
375	slabinfo-gnuplot.sh -t STATS1-totals STATS2-totals .. STATSN-totals
376
377   This will produce a single plot (png file).
378
379   Plots, expectedly, can be large so some fluctuations or small spikes
380   can go unnoticed. To deal with that, ``slabinfo-gnuplot.sh`` has two
381   options to 'zoom-in'/'zoom-out':
382
383   a) ``-s %d,%d`` -- overwrites the default image width and height
384   b) ``-r %d,%d`` -- specifies a range of samples to use (for example,
385      in ``slabinfo -X >> FOO_STATS; sleep 1;`` case, using a ``-r
386      40,60`` range will plot only samples collected between 40th and
387      60th seconds).
388
389
390DebugFS files for SLUB
391======================
392
393For more information about current state of SLUB caches with the user tracking
394debug option enabled, debugfs files are available, typically under
395/sys/kernel/debug/slab/<cache>/ (created only for caches with enabled user
396tracking). There are 2 types of these files with the following debug
397information:
398
3991. alloc_traces::
400
401    Prints information about unique allocation traces of the currently
402    allocated objects. The output is sorted by frequency of each trace.
403
404    Information in the output:
405    Number of objects, allocating function, possible memory wastage of
406    kmalloc objects(total/per-object), minimal/average/maximal jiffies
407    since alloc, pid range of the allocating processes, cpu mask of
408    allocating cpus, numa node mask of origins of memory, and stack trace.
409
410    Example:::
411
412    338 pci_alloc_dev+0x2c/0xa0 waste=521872/1544 age=290837/291891/293509 pid=1 cpus=106 nodes=0-1
413        __kmem_cache_alloc_node+0x11f/0x4e0
414        kmalloc_trace+0x26/0xa0
415        pci_alloc_dev+0x2c/0xa0
416        pci_scan_single_device+0xd2/0x150
417        pci_scan_slot+0xf7/0x2d0
418        pci_scan_child_bus_extend+0x4e/0x360
419        acpi_pci_root_create+0x32e/0x3b0
420        pci_acpi_scan_root+0x2b9/0x2d0
421        acpi_pci_root_add.cold.11+0x110/0xb0a
422        acpi_bus_attach+0x262/0x3f0
423        device_for_each_child+0xb7/0x110
424        acpi_dev_for_each_child+0x77/0xa0
425        acpi_bus_attach+0x108/0x3f0
426        device_for_each_child+0xb7/0x110
427        acpi_dev_for_each_child+0x77/0xa0
428        acpi_bus_attach+0x108/0x3f0
429
4302. free_traces::
431
432    Prints information about unique freeing traces of the currently allocated
433    objects. The freeing traces thus come from the previous life-cycle of the
434    objects and are reported as not available for objects allocated for the first
435    time. The output is sorted by frequency of each trace.
436
437    Information in the output:
438    Number of objects, freeing function, minimal/average/maximal jiffies since free,
439    pid range of the freeing processes, cpu mask of freeing cpus, and stack trace.
440
441    Example:::
442
443    1980 <not-available> age=4294912290 pid=0 cpus=0
444    51 acpi_ut_update_ref_count+0x6a6/0x782 age=236886/237027/237772 pid=1 cpus=1
445	kfree+0x2db/0x420
446	acpi_ut_update_ref_count+0x6a6/0x782
447	acpi_ut_update_object_reference+0x1ad/0x234
448	acpi_ut_remove_reference+0x7d/0x84
449	acpi_rs_get_prt_method_data+0x97/0xd6
450	acpi_get_irq_routing_table+0x82/0xc4
451	acpi_pci_irq_find_prt_entry+0x8e/0x2e0
452	acpi_pci_irq_lookup+0x3a/0x1e0
453	acpi_pci_irq_enable+0x77/0x240
454	pcibios_enable_device+0x39/0x40
455	do_pci_enable_device.part.0+0x5d/0xe0
456	pci_enable_device_flags+0xfc/0x120
457	pci_enable_device+0x13/0x20
458	virtio_pci_probe+0x9e/0x170
459	local_pci_probe+0x48/0x80
460	pci_device_probe+0x105/0x1c0
461
462Christoph Lameter, May 30, 2007
463Sergey Senozhatsky, October 23, 2015