mm: slub: test: Use the kunit_get_current_test() function
authorDavid Gow <davidgow@google.com>
Fri, 25 Nov 2022 08:43:06 +0000 (16:43 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 12 Dec 2022 21:13:47 +0000 (14:13 -0700)
Use the newly-added function kunit_get_current_test() instead of
accessing current->kunit_test directly. This function uses a static key
to return more quickly when KUnit is enabled, but no tests are actively
running. There should therefore be a negligible performance impact to
enabling the slub KUnit tests.

Other than the performance improvement, this should be a no-op.

Cc: Oliver Glitta <glittao@gmail.com>
Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David Gow <davidgow@google.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
lib/slub_kunit.c
mm/slub.c

index 7a0564d7cb7aeb3e0fbf886a2a12a3720214cff3..8fd19c8301adf746139d5207cfdcd5dd68ab9aff 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <kunit/test.h>
+#include <kunit/test-bug.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/module.h>
index 157527d7101be0da54026376ff4f4095deb9ec2d..1887996cb703035f2b993ff398a44395aa66fd20 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -39,6 +39,7 @@
 #include <linux/memcontrol.h>
 #include <linux/random.h>
 #include <kunit/test.h>
+#include <kunit/test-bug.h>
 #include <linux/sort.h>
 
 #include <linux/debugfs.h>
@@ -603,7 +604,7 @@ static bool slab_add_kunit_errors(void)
 {
        struct kunit_resource *resource;
 
-       if (likely(!current->kunit_test))
+       if (!kunit_get_current_test())
                return false;
 
        resource = kunit_find_named_resource(current->kunit_test, "slab_errors");