From patchwork Fri Sep 28 11:11:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Tomlin X-Patchwork-Id: 10619659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5AA1C913 for ; Fri, 28 Sep 2018 11:11:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50B032B2F1 for ; Fri, 28 Sep 2018 11:11:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42DF82B312; Fri, 28 Sep 2018 11:11:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B52D62B2F1 for ; Fri, 28 Sep 2018 11:11:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40E4E8E0002; Fri, 28 Sep 2018 07:11:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3BD678E0001; Fri, 28 Sep 2018 07:11:44 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2871D8E0002; Fri, 28 Sep 2018 07:11:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by kanga.kvack.org (Postfix) with ESMTP id C1CA68E0001 for ; Fri, 28 Sep 2018 07:11:43 -0400 (EDT) Received: by mail-wm1-f72.google.com with SMTP id i8-v6so929025wma.9 for ; Fri, 28 Sep 2018 04:11:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=DdMrOd1vGJXpR1H0Nxrj5UIVTrQm0seXiPTs+tYZ0+4=; b=nfKyFTZRz8d5ta4srdb6cEDWF43mSlhucPrWNwk8dT00II4Q5sFCsN1zdn64PZRzec MXMJFN4oVz2aQx4FvLrxWTV5roplgLmMfWdwL/s0cWyYEuKjmoxTvPcEQWkIoySPdP4F +vNdQF6ehoR58q3zGdrEEnh8WZNjr6FlRe1Wzl7PGeskGgTjynasOEwaE3s30S6l2v8A e0tXJf/49Lbx5aaZd3B5I8ZiVp9UF8ZxBIwq3OBlqasyJqbR+QrScVFLgls0eVjsI2BG CF6sGHz6ak9PXdMqpSAxYHRrOAJK0SOfmmcOgzxNMW+umLtv7bBFzWsf1kNEOwby4aaE ykUg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of atomlin@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=atomlin@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: ABuFfoiurJIc6sPMPxZqiuaiXAGnQIVZp5rVGdUbWWIszUvVbjxf0AaM lUXfVTo1F3lZHi0pKc9mW8Tsa72NYtxJH8uy8KMcT3VOahf5Bmh0YmL6uT5veCPY4s5S5rnPf9l AotuZfcZQa0BSXma5s0F24OxDR3OyXZs9wUZ2+Zw6mI8QzioA0z8pkA8SaVVRX2cBgno2+s4Q14 arrtWJcCrvEnphboJbqzsKZ/YOLykNXHGPtp7cVdOT+RHQUuaNBm2HnJ2wP2DFPpGzcK+C+Xik+ PnYdTCzFqV8pLd69LrS5O5V4wKa59pFNqaxYzfVTJwOAEHLo3JG7DVOwN7SpuyQYGVBq9Lu5YU8 l2mZTRWkIfhtYtSHT40YLRv14TCqe0HTYYzFQQzSunj1f6yDn8GNWMKqctKCsagoNXKRacoPMB9 J X-Received: by 2002:a1c:c011:: with SMTP id q17-v6mr1407401wmf.37.1538133103275; Fri, 28 Sep 2018 04:11:43 -0700 (PDT) X-Received: by 2002:a1c:c011:: with SMTP id q17-v6mr1407333wmf.37.1538133101996; Fri, 28 Sep 2018 04:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538133101; cv=none; d=google.com; s=arc-20160816; b=TW9ttOdJYAKHKKI89kQQc+JUpA0tzPieAcHmyFEBtwT5KdzPbZj6LeLyrnNyKl1nRS B2FkGBPcuvoiNmKm1qirk4b9BIYnmcAo1+OG48pvEYa2GzrVVmbdi/tyY8UoIjXoL1FS SRnM+RfZzfX1bCm37/woYkjShsc03pWlTc6a30ffYSiKLk3dXC1kYbth2qg7k/41B3T1 G6aMTzO1uxlzkJaJmUvT/xrl8DaKJvNy3/FI5rn/3UHM/3kQ0XEOqJHoK5yArr5EZes/ hn5lHD7o+4pm3pm1FnlW/WMx1KIKKPrTSbvq47Ng0GQzKg199pMKR3FmMe9a4wmem36Y F3IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=DdMrOd1vGJXpR1H0Nxrj5UIVTrQm0seXiPTs+tYZ0+4=; b=VHtgxC3fQ6M4y4u2NbxkfZuHWdvMp5ZwXsI3kvzzajRY/J/8tPJWHAKdKlfEFpoSSg Zrg9RWNOT0Tzytp3PtuJv+lCmBCDmQI7P6UixrfbOeFgJC/WrJbD9t0RL6G8J4YXN+r+ OhAwGNTfHSl+37bUtwy2X8yQP/MtTrUPLCHyv11A4/uzlA8l3Wl7sHn3IHyp3AEpJ/tn WjVxuJ+WwXuXbKN1lBFPG95sKAyLCX5lDQyH2VdzUyYbusjuc/XCo7yvnam1ZPrWf7Xl zEkFK/3lZvJMe71JBdERLe4sfWjM6LtaI5daZ0CJxEpe3wslyffuwqbuDPGwzsgrRbAe ftkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of atomlin@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=atomlin@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id j6-v6sor3507878wru.33.2018.09.28.04.11.41 for (Google Transport Security); Fri, 28 Sep 2018 04:11:41 -0700 (PDT) Received-SPF: pass (google.com: domain of atomlin@redhat.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of atomlin@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=atomlin@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Google-Smtp-Source: ACcGV62KGLScxRNlK/MigV8hYuMKL0E90A3soBuFbXrsOXMCzWcJ/eUPmMe+KproZlOm4ziPVSEqOg== 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Christoph Lameter --- 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; }