Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp621232imm; Fri, 28 Sep 2018 04:13:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV631k62K1+O+I+ms/I7aF1vW5YL3wZZWFlFIxlJJzfb7ApWjguTxHR94IrcNF8CKhwnozrCy X-Received: by 2002:a17:902:a03:: with SMTP id 3-v6mr15828080plo.323.1538133228911; Fri, 28 Sep 2018 04:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538133228; cv=none; d=google.com; s=arc-20160816; b=jAd0ELY5YWFvljDRHJU9Iehs5QxmOESQGgSzhmC1aMEJFvhOff7cJ58Cy0IVgjuNL9 7SpPZjA+P0foV0mvYFQPVXBdE4J06VV+b2LNiqkloqWw+AKTKHNsGO0sns30995Q6AVT TdV5EmojyTpZpe9etyQ5dCCgiE19iGcB1XiFYWtBzZPSQHgoH61XeSnVtEVZRXXvsdTt GScVOWBJQKgIBSdFWg1c8QoZ+s2g4Z6Xt2uobAxGOQ1Gbs0RUSPtYyO1/OKSEJyyCuwr NRYlNZBkfEhfO5/H8FEGDCpYZANRR/vWg/Q1NncIbAAbBHVfW/x1ixCVeHIJSRjO9onQ MxDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=DdMrOd1vGJXpR1H0Nxrj5UIVTrQm0seXiPTs+tYZ0+4=; b=QIvPQkaZ+xNBPUDAUIqRlkbJJ/RXLzdchBVcNVDRFZUQr2kD2zkElZGD+luDQfn2lL Ge0YE3u4erVuIzbg95qIIY4httVLMVDEfQmCZmv7IS5ANEZ8KA2isYpshUn3RSr2dPJt 661eG2qakdgG/7X5S8IZjia+ktDLGls8EPt/CIXYcK9TeS0W7AkD5xq26Esr4XhO6tHx cYT36az3cMESWl79yIDHtDeUnTJv/G7gcYJ9+k6tL/xAsoLQw71cs1XLjO6tLaQmPavp wH0hfhYuKvEI8FUGMTw4KRn38fLRWhEVF9LQA3Ivewk5OZD6idAICKUq0ZjvzW+itZOY 4quA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si4491042plp.428.2018.09.28.04.13.32; Fri, 28 Sep 2018 04:13:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729390AbeI1Re7 (ORCPT + 99 others); Fri, 28 Sep 2018 13:34:59 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43532 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729089AbeI1Re6 (ORCPT ); Fri, 28 Sep 2018 13:34:58 -0400 Received: by mail-wr1-f66.google.com with SMTP id z14-v6so5924231wrs.10 for ; Fri, 28 Sep 2018 04:11:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DdMrOd1vGJXpR1H0Nxrj5UIVTrQm0seXiPTs+tYZ0+4=; b=aOljlyFSb+1i/R3OxCkSB6W5IXVabQt/wAxW9VHXKN3GRB/UKRcTTvkuejGB6u9eSu N0nm+pcjs4a0p/4whswCsLlJ14pQkVd3ii4lFIACRsgSe01P2lGevvu41oIDdNmS1BNo 3jZMSdwXrq7JHYONUOZipF1JaUv4LwHHGO4n0VNhjc6mzcKinRCRLY8Ev3Xmn3Xs//jY W4pAvi7qXgkKfk4d9iGjIdBEHVOmt8SZMnBpGU9WUH8iuvWf5bSJpAoeFk+54LvWoEFO 3FhWtmnQ7xaGkXxESh2W0vUrvVqDc7Q0bMPGdRethPLSl70IfJW13VsHrGZOz6WBr+Nq ZuNQ== X-Gm-Message-State: ABuFfohlzg2+nADxymunMEtTW4ziy97u2EXv0KzBqZymUE+eVUzl/zYh CqgS604A43h4z1aJK6KVPnia X-Received: by 2002:adf:e882:: with SMTP id d2-v6mr11549768wrm.43.1538133101468; Fri, 28 Sep 2018 04:11:41 -0700 (PDT) Received: from localhost (cpc111743-lutn13-2-0-cust844.9-3.cable.virginm.net. [82.17.115.77]) by smtp.gmail.com with ESMTPSA id u185-v6sm1667615wmf.9.2018.09.28.04.11.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 04:11:40 -0700 (PDT) From: Aaron Tomlin To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, atomlin@redhat.com, malchev@google.com Subject: [PATCH v3] slub: extend slub debug to handle multiple slabs Date: Fri, 28 Sep 2018 12:11:39 +0100 Message-Id: <20180928111139.27962-1-atomlin@redhat.com> X-Mailer: git-send-email 2.14.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extend the slub_debug syntax to "slub_debug=[,]*", where 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 Signed-off-by: Aaron Tomlin --- Changes from v2 [2]: - Add a function and kernel-doc comment - Refactor code - Use the appropriate helper function max_t() Changes from v1 [1]: - Add appropriate cast to address compiler warning [1]: https://marc.info/?l=linux-kernel&m=153657804506284&w=2 [2]: https://marc.info/?l=linux-kernel&m=153747362316965&w=2 --- Documentation/vm/slub.rst | 12 +++++++++--- mm/slub.c | 50 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/Documentation/vm/slub.rst b/Documentation/vm/slub.rst index 3a775fd64e2d..195928808bac 100644 --- a/Documentation/vm/slub.rst +++ b/Documentation/vm/slub.rst @@ -36,9 +36,10 @@ debugging is enabled. Format: slub_debug= Enable options for all slabs -slub_debug=, - Enable options only for select slabs +slub_debug=,,,... + 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:: diff --git a/mm/slub.c b/mm/slub.c index 8da34a8af53d..7927f971df0d 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1276,16 +1276,54 @@ static int __init setup_slub_debug(char *str) __setup("slub_debug", setup_slub_debug); +/* + * kmem_cache_flags - apply debugging options to the cache + * @object_size: the size of an object without meta data + * @flags: flags to set + * @name: name of the cache + * @ctor: constructor function + * + * Debug option(s) are applied to @flags. In addition to the debug + * option(s), if a slab name (or multiple) is specified i.e. + * slub_debug=,, ... + * then only the select slabs will receive the debug option(s). + */ slab_flags_t kmem_cache_flags(unsigned int object_size, slab_flags_t flags, const char *name, void (*ctor)(void *)) { - /* - * 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 *iter; + size_t len; + + /* If slub_debug = 0, it folds into the if conditional. */ + if (!slub_debug_slabs) + return flags | slub_debug; + + len = strlen(name); + iter = slub_debug_slabs; + while (*iter) { + char *end, *glob; + size_t cmplen; + + end = strchr(iter, ','); + if (!end) + end = iter + strlen(iter); + + glob = strnchr(iter, end - iter, '*'); + if (glob) + cmplen = glob - iter; + else + cmplen = max_t(size_t, len, (end - iter)); + + if (!strncmp(name, iter, cmplen)) { + flags |= slub_debug; + break; + } + + if (!*end) + break; + iter = end + 1; + } return flags; } -- 2.14.4