slub: extend slub debug to handle multiple slabs
Subsystems (3)
PATCH 1/1 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
--- Documentation/vm/slub.rst | 12 +++++++++--- mm/slub.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-)
Documentation/vm/slub.rst +9 -3
@@ -36,9 +36,10 @@ debugging is enabled. Format: slub_debug=<Debug-Options> Enable options for all slabs -slub_debug=<Debug-Options>,<slab name> - Enable options only for select slabs +slub_debug=<Debug-Options>,<slab name1>,<slab name2>,... + Enable options only for select slabs (no spaces + after a comma) Possible debug options are::
@@ -62,7 +63,12 @@ Trying to find an issue in the dentry cache? Try:: slub_debug=,dentry -to only enable debugging on the dentry cache. +to only enable debugging on the dentry cache. You may use an asterisk at the +end of the slab name, in order to cover all slabs with the same prefix. For +example, here's how you can poison the dentry cache as well as all kmalloc +slabs: + + slub_debug=P,kmalloc-*,dentry Red zoning and tracking may realign the slab. We can just apply sanity checks to the dentry cache with::
mm/slub.c +31 -3
@@ -1283,9 +1283,37 @@ slab_flags_t kmem_cache_flags(unsigned int object_size,/* * Enable debugging if selected on the kernel commandline. */ -if (slub_debug && (!slub_debug_slabs || (name && - !strncmp (slub_debug_slabs, name,strlen (slub_debug_slabs))))) - flags |= slub_debug; + +char *end, *n, *glob; +int len =strlen (name); + +/* If slub_debug = 0, it folds into the if conditional. */ +if (!slub_debug_slabs) +return flags | slub_debug; + + n = slub_debug_slabs; +while (*n) { +int cmplen; + + end =strchr (n,',' ); +if (!end) + end = n +strlen (n); + + glob =strnchr (n, end - n,'*' ); +if (glob) + cmplen = glob - n; +else + cmplen =max (len, end - n); + +if (!strncmp (name, n, cmplen)) { + flags |= slub_debug; +break ; + } + +if (!*end) +break ; + n = end +1 ; + }return flags; }
Signature · 1 line
2.14.4
kbuild test robot
build botThank you for the patch! Perhaps something to improve:
Hi Aaron,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v4.19-rc3 next-20180910]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Aaron-Tomlin/slub-extend-slub-debug-to-handle-multiple-slabs/20180911-030241
config: x86_64-randconfig-x008-201836 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 All warnings (new ones prefixed by >>):
In file included from include/asm-generic/bug.h:18:0,
from arch/x86/include/asm/bug.h:83,
from include/linux/bug.h:5,
from include/linux/mmdebug.h:5,
from include/linux/mm.h:9,
from mm/slub.c:13:
mm/slub.c: In function 'kmem_cache_flags':
include/linux/kernel.h:845:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:859:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:869:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:885:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> mm/slub.c:1306:13: note: in expansion of macro 'max'
cmplen = max(len, end - n);
^~~vim +/max +1306 mm/slub.c
1278
1279 slab_flags_t kmem_cache_flags(unsigned int object_size,
1280 slab_flags_t flags, const char *name,
1281 void (*ctor)(void *))
1282 {
1283 /*
1284 * Enable debugging if selected on the kernel commandline.
1285 */
1286
1287 char *end, *n, *glob;
1288 int len = strlen(name);
1289
1290 /* If slub_debug = 0, it folds into the if conditional. */
1291 if (!slub_debug_slabs)
1292 return flags | slub_debug;
1293
1294 n = slub_debug_slabs;
1295 while (*n) {
1296 int cmplen;
1297
1298 end = strchr(n, ',');
1299 if (!end)
1300 end = n + strlen(n);
1301
1302 glob = strnchr(n, end - n, '*');
1303 if (glob)
1304 cmplen = glob - n;
1305 else
> 1306 cmplen = max(len, end - n);
1307
1308 if (!strncmp(name, n, cmplen)) {
1309 flags |= slub_debug;
1310 break;
1311 }
1312
1313 if (!*end)
1314 break;
1315 n = end + 1;
1316 }
1317
1318 return flags;
1319 }
1320 #else /* !CONFIG_SLUB_DEBUG */
1321 static inline void setup_object_debug(struct kmem_cache *s,
1322 struct page *page, void *object) {}
1323
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation