@@ -1276,16 +1276,54 @@ static int __init setup_slub_debug(char *str)
1276
1276
1277
1277
__setup ("slub_debug" , setup_slub_debug );
1278
1278
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
+ */
1279
1291
slab_flags_t kmem_cache_flags (unsigned int object_size ,
1280
1292
slab_flags_t flags , const char * name ,
1281
1293
void (* ctor )(void * ))
1282
1294
{
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
+ }
1289
1327
1290
1328
return flags ;
1291
1329
}
0 commit comments