Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1007668yba; Thu, 4 Apr 2019 02:17:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqHkmz2B9gKotMO0zbXXY7HuXmPCUGKC4M9c1kNKoG8Apts4e1E026PJ+A4fXaK5Q9/W+c X-Received: by 2002:a63:fd07:: with SMTP id d7mr4738323pgh.199.1554369434432; Thu, 04 Apr 2019 02:17:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554369434; cv=none; d=google.com; s=arc-20160816; b=UYUivzxR/cqOWOvK9ZHYgL+LbjaE756oFuToAxZy595qPDORIrXQek7KlSzTNXqgPM KlOaYHVykTV/6m9r8KpEP37SUdYgdRH3ECo1igPqq45lohcLOrpGu/0vtGXgIrqQmgTR pif2B/B3d7haWs8W0ezdSgcUKSfhxOFbRzpkJk9pLTrCMUrh7EDDOc1B3Mo7PU095Wwn tJVTrjaLreCiA/xRXmyRCTZAqVGij/h0riCUIPvwfmn1c8NHyDipy1+gGKwJqXOKr4rP +KMLRLYrnlD0a9B+qiSl9IJ7MQ6+/JXR9exmKb5nod0yE81xjfEnHQY+48buL7e7ng6O EMOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=XKweMPqkN+ZOr5KVD4JMmVpTifSSsIXkDsQZVM5g5zY=; b=mhA9m19eYFJATtDqfLgqngTxp+5zhCMSBITAboTC7YqxyGlQDDBHQU0UNKwV13D7JL ehFOY77Ino/fUNZ0+Y4+nmbYxJujDiQVtGzbcUCQ+55eB4sdwRY8Wa6FGCuee69H8eQN atPWlYoB6ZekHKz4v6pHXlJhGFfLraumqj1Q3wbvGS16H/FWYdP/l65r3V03kw7BxAT0 LQLQl5HpbVEFjfLOjQScR3q2mPtHMGGq2c+gbazn5V/3hIOfPIh4qtrVl9ikuFhGnIkI MMBKADtccg+3Hax74/oX0ionDDkHd/9mUmAgqQWnoPWnfaJTDHdzTi6zXcbpeTp0lb5v yaYA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si15396026pgq.347.2019.04.04.02.16.59; Thu, 04 Apr 2019 02:17:14 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387955AbfDDJPv (ORCPT + 99 others); Thu, 4 Apr 2019 05:15:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:35652 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387931AbfDDJPo (ORCPT ); Thu, 4 Apr 2019 05:15:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4A327AD0A; Thu, 4 Apr 2019 09:15:43 +0000 (UTC) From: Vlastimil Babka To: linux-mm@kvack.org Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Mel Gorman , linux-kernel@vger.kernel.org, Vlastimil Babka Subject: [RFC 1/2] mm, slub: introduce static key for slub_debug Date: Thu, 4 Apr 2019 11:15:30 +0200 Message-Id: <20190404091531.9815-2-vbabka@suse.cz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404091531.9815-1-vbabka@suse.cz> References: <20190404091531.9815-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org One advantage of CONFIG_SLUB_DEBUG is that a generic distro kernel can be built with it, but it's inactive until enabled on boot or at runtime, without rebuilding the kernel. With a static key, we can minimize the overhead of checking whether slub_debug is enabled, as we do for e.g. page_owner. For now and for simplicity, the static key stays enabled for the whole uptime once activated for any cache, although some per-cache debugging options can be also disabled at runtime. This can be improved if there's interest. Signed-off-by: Vlastimil Babka --- mm/slub.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index d30ede89f4a6..398e53e16e2e 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -115,10 +115,21 @@ * the fast path and disables lockless freelists. */ +#ifdef CONFIG_SLUB_DEBUG +#ifdef CONFIG_SLUB_DEBUG_ON +DEFINE_STATIC_KEY_TRUE(slub_debug_enabled); +#else +DEFINE_STATIC_KEY_FALSE(slub_debug_enabled); +#endif +#endif + static inline int kmem_cache_debug(struct kmem_cache *s) { #ifdef CONFIG_SLUB_DEBUG - return unlikely(s->flags & SLAB_DEBUG_FLAGS); + if (static_branch_unlikely(&slub_debug_enabled)) + return s->flags & SLAB_DEBUG_FLAGS; + else + return 0; #else return 0; #endif @@ -1287,6 +1298,9 @@ static int __init setup_slub_debug(char *str) if (*str == ',') slub_debug_slabs = str + 1; out: + if (slub_debug) + static_branch_enable(&slub_debug_enabled); + return 1; } @@ -5193,6 +5207,7 @@ static ssize_t red_zone_store(struct kmem_cache *s, s->flags &= ~SLAB_RED_ZONE; if (buf[0] == '1') { s->flags |= SLAB_RED_ZONE; + static_branch_enable(&slub_debug_enabled); } calculate_sizes(s, -1); return length; @@ -5213,6 +5228,7 @@ static ssize_t poison_store(struct kmem_cache *s, s->flags &= ~SLAB_POISON; if (buf[0] == '1') { s->flags |= SLAB_POISON; + static_branch_enable(&slub_debug_enabled); } calculate_sizes(s, -1); return length; @@ -5234,6 +5250,7 @@ static ssize_t store_user_store(struct kmem_cache *s, if (buf[0] == '1') { s->flags &= ~__CMPXCHG_DOUBLE; s->flags |= SLAB_STORE_USER; + static_branch_enable(&slub_debug_enabled); } calculate_sizes(s, -1); return length; -- 2.21.0