From: Vlastimil Babka <vbabka@suse.cz>
To: linux-mm@kvack.org
Cc: Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Andrew Morton <akpm@linux-foundation.org>,
Mel Gorman <mgorman@techsingularity.net>,
linux-kernel@vger.kernel.org, Vlastimil Babka <vbabka@suse.cz>
Subject: [RFC 1/2] mm, slub: introduce static key for slub_debug
Date: Thu, 4 Apr 2019 11:15:30 +0200 [thread overview]
Message-ID: <20190404091531.9815-2-vbabka@suse.cz> (raw)
In-Reply-To: <20190404091531.9815-1-vbabka@suse.cz>
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 <vbabka@suse.cz>
---
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
next prev parent reply other threads:[~2019-04-04 9:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-04 9:15 [RFC 0/2] add " Vlastimil Babka
2019-04-04 9:15 ` Vlastimil Babka [this message]
2019-04-04 9:15 ` [RFC 2/2] mm, slub: add missing kmem_cache_debug() checks Vlastimil Babka
2019-04-04 16:40 ` Christopher Lameter
2019-04-04 15:57 ` [RFC 0/2] add static key for slub_debug Christopher Lameter
2019-04-04 21:52 ` Vlastimil Babka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190404091531.9815-2-vbabka@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox