Skip to content

Commit c5fd3ca

Browse files
Aaron Tomlintorvalds
authored andcommitted
slub: extend slub debug to handle multiple slabs
Extend the slub_debug syntax to "slub_debug=<flags>[,<slub>]*", where <slub> may contain an asterisk at the end. For example, the following would poison all kmalloc slabs: slub_debug=P,kmalloc* and the following would apply the default flags to all kmalloc and all block IO slabs: slub_debug=,bio*,kmalloc* Please note that a similar patch was posted by Iliyan Malchev some time ago but was never merged: https://marc.info/?l=linux-mm&m=131283905330474&w=2 Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Aaron Tomlin <[email protected]> Acked-by: Christoph Lameter <[email protected]> Cc: Pekka Enberg <[email protected]> Cc: David Rientjes <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Iliyan Malchev <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6144847 commit c5fd3ca

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

Documentation/vm/slub.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ debugging is enabled. Format:
3636

3737
slub_debug=<Debug-Options>
3838
Enable options for all slabs
39-
slub_debug=<Debug-Options>,<slab name>
40-
Enable options only for select slabs
4139

40+
slub_debug=<Debug-Options>,<slab name1>,<slab name2>,...
41+
Enable options only for select slabs (no spaces
42+
after a comma)
4243

4344
Possible debug options are::
4445

@@ -62,7 +63,12 @@ Trying to find an issue in the dentry cache? Try::
6263

6364
slub_debug=,dentry
6465

65-
to only enable debugging on the dentry cache.
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
69+
slabs:
70+
71+
slub_debug=P,kmalloc-*,dentry
6672
6773
Red zoning and tracking may realign the slab. We can just apply sanity checks
6874
to the dentry cache with::

mm/slub.c

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,16 +1276,54 @@ static int __init setup_slub_debug(char *str)
12761276

12771277
__setup("slub_debug", setup_slub_debug);
12781278

1279+
/*
1280+
* kmem_cache_flags - apply debugging options to the cache
1281+
* @object_size: the size of an object without meta data
1282+
* @flags: flags to set
1283+
* @name: name of the cache
1284+
* @ctor: constructor function
1285+
*
1286+
* Debug option(s) are applied to @flags. In addition to the debug
1287+
* option(s), if a slab name (or multiple) is specified i.e.
1288+
* slub_debug=<Debug-Options>,<slab name1>,<slab name2> ...
1289+
* then only the select slabs will receive the debug option(s).
1290+
*/
12791291
slab_flags_t kmem_cache_flags(unsigned int object_size,
12801292
slab_flags_t flags, const char *name,
12811293
void (*ctor)(void *))
12821294
{
1283-
/*
1284-
* Enable debugging if selected on the kernel commandline.
1285-
*/
1286-
if (slub_debug && (!slub_debug_slabs || (name &&
1287-
!strncmp(slub_debug_slabs, name, strlen(slub_debug_slabs)))))
1288-
flags |= slub_debug;
1295+
char *iter;
1296+
size_t len;
1297+
1298+
/* If slub_debug = 0, it folds into the if conditional. */
1299+
if (!slub_debug_slabs)
1300+
return flags | slub_debug;
1301+
1302+
len = strlen(name);
1303+
iter = slub_debug_slabs;
1304+
while (*iter) {
1305+
char *end, *glob;
1306+
size_t cmplen;
1307+
1308+
end = strchr(iter, ',');
1309+
if (!end)
1310+
end = iter + strlen(iter);
1311+
1312+
glob = strnchr(iter, end - iter, '*');
1313+
if (glob)
1314+
cmplen = glob - iter;
1315+
else
1316+
cmplen = max_t(size_t, len, (end - iter));
1317+
1318+
if (!strncmp(name, iter, cmplen)) {
1319+
flags |= slub_debug;
1320+
break;
1321+
}
1322+
1323+
if (!*end)
1324+
break;
1325+
iter = end + 1;
1326+
}
12891327

12901328
return flags;
12911329
}

0 commit comments

Comments
 (0)