]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
mm/slub: disable user tracing for kmemleak caches by default
authorJohannes Berg <johannes.berg@intel.com>
Wed, 24 Feb 2021 20:01:04 +0000 (12:01 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 24 Feb 2021 21:38:27 +0000 (13:38 -0800)
If kmemleak is enabled, it uses a kmem cache for its own objects.  These
objects are used to hold information kmemleak uses, including a stack
trace.  If slub_debug is also turned on, each of them has *another* stack
trace, so the overhead adds up, and on my tests (on ARCH=um, admittedly)
2/3rds of the allocations end up being doing the stack tracing.

Turn off SLAB_STORE_USER if SLAB_NOLEAKTRACE was given, to avoid storing
the essentially same data twice.

Link: https://lkml.kernel.org/r/20210113215114.d94efa13ba30.I117b6764e725b3192318bbcf4269b13b709539ae@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/slub.c

index 5d8d5d21e5d32bdda254e47221b27579107b91e2..a7c453bf71567174240d58d37d943760278de08a 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1413,6 +1413,15 @@ slab_flags_t kmem_cache_flags(unsigned int object_size,
        size_t len;
        char *next_block;
        slab_flags_t block_flags;
+       slab_flags_t slub_debug_local = slub_debug;
+
+       /*
+        * If the slab cache is for debugging (e.g. kmemleak) then
+        * don't store user (stack trace) information by default,
+        * but let the user enable it via the command line below.
+        */
+       if (flags & SLAB_NOLEAKTRACE)
+               slub_debug_local &= ~SLAB_STORE_USER;
 
        len = strlen(name);
        next_block = slub_debug_string;
@@ -1447,7 +1456,7 @@ slab_flags_t kmem_cache_flags(unsigned int object_size,
                }
        }
 
-       return flags | slub_debug;
+       return flags | slub_debug_local;
 }
 #else /* !CONFIG_SLUB_DEBUG */
 static inline void setup_object_debug(struct kmem_cache *s,