Skip to contentSkip to conversation

Patch for slab leak debugging

PATCH Alexander Nyberg 3 participants 6 messages Jul 8, 2005 – Jul 9, 2005

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

I think we really need an option in the kernel to help users in tracking slab leaks so that they can be brought down easier. This patch tracks the caller of the first five objects to be created within a slab. This is not much but as slab leaks normally are quite obvious with the exception that we don't know who the caller is, I think this approach will do fine.

No NUMA handling, only looks at nodelists[0] at the moment

list_ff() is distasteful, but I've yet to come up with a better approach and at the same time not screwing up the slab core too much (I've not seen too big latencies even with 7M size-32 objects, with that size it took around 1 minute to cat /proc/slab_owner > meepmeep.txt on a 1.2Ghz athlon. We could even limit the size of the output as it'll be pretty repetetive anyway).

To use it, look at /proc/slabinfo to identify the cache that looks to have leakin callers. Then echo cachename > /proc/slab_owner; cat /proc/slab_owner > unsorted_slab_owner

Although glancing at this file will likely reveal the leaking caller, there's a user-space program called slab_owner.c in Documentation/ to help sort the output in the same manner as page_owner

lib/Kconfig.debug +8 -0
Index: akpm/lib/Kconfig.debug
===================================================================
@@ -85,6 +85,14 @@
 	  allocation as well as poisoning memory on free to catch use of freed
 	  memory. This can make kmalloc/kfree-intensive workloads much slower.
 
+config SLAB_OWNER
+	bool "Track owner of slab objects"
+	depends on DEBUG_KERNEL && DEBUG_SLAB
+	help
+	  Say Y here to make the kernel keep track of some of the functions 
+	  allocating slab objects. Expensive, should only be used to track 
+	  down slab leaks.
+
 config DEBUG_PREEMPT
 	bool "Debug preemptible kernel"
 	depends on DEBUG_KERNEL && PREEMPT
mm/slab.c +142 -1

164 lines not on this page · raw message

fs/proc/proc_misc.c +8 -0
Index: akpm/fs/proc/proc_misc.c
===================================================================
@@ -704,4 +704,12 @@
 		entry->size = 1024;
 	}
 #endif
+#ifdef CONFIG_SLAB_OWNER
+	extern struct file_operations proc_slab_owner_operations;
+	entry = create_proc_entry("slab_owner", S_IWUSR | S_IRUGO, NULL);
+	if (entry) {
+		entry->proc_fops = &proc_slab_owner_operations;
+		entry->size = 4096;
+	}
+#endif
 }
Documentation/slab_owner.c new file +135 -0

135 lines not on this page · raw message

#1 lore raw

lib/Kconfig.debug line 90

Quoted 4 lines · Alexander Nyberg
lib/Kconfig.debug +3 -0
+config SLAB_OWNER
+	bool "Track owner of slab objects"
+	depends on DEBUG_KERNEL && DEBUG_SLAB

I guess this should select CONFIG_KALLSYMS

#2 lore raw
In reply to Alexander Nyberg
Quoted 3 lines · Alexander Nyberg

I think we really need an option in the kernel to help users in tracking slab leaks so that they can be brought down easier.

Well we already have slab-leak-detector.patch, whcih I appear to have been sitting on since 2.6.0-test8. it fell out of -mm after 2.6.12-rc5-mm2 due to various ravaging of slab.c, but could be brought back.

pc/2.6.12-rc5-mm2-series:slab-leak-detector.patch pc/2.6.12-rc5-mm2-series:slab-leak-detector-warning-fixes.patch

#3 lore raw

fre 2005-07-08 klockan 16:55 -0700 skrev Andrew Morton:

Quoted 11 lines
Quoted 3 lines · Alexander Nyberg

I think we really need an option in the kernel to help users in tracking slab leaks so that they can be brought down easier.

Well we already have slab-leak-detector.patch, whcih I appear to have been sitting on since 2.6.0-test8. it fell out of -mm after 2.6.12-rc5-mm2 due to various ravaging of slab.c, but could be brought back.

pc/2.6.12-rc5-mm2-series:slab-leak-detector.patch pc/2.6.12-rc5-mm2-series:slab-leak-detector-warning-fixes.patch

Yeah I knew there was one, but I thought that was a standalone patch (the one turning all bufctl to unsigned long, turning off irqs and printing all slabs_full to console), my intention with this was a proper /proc entry, something that could be a simple config option.

But if something like this already exists, would you please send me what you have and I'll fix the numa changes

#4 lore raw
Quoted 7 lines · Alexander Nyberg

Yeah I knew there was one, but I thought that was a standalone patch (the one turning all bufctl to unsigned long, turning off irqs and printing all slabs_full to console), my intention with this was a proper /proc entry, something that could be a simple config option.

No, I never wrote a proper /proc interface. But I think the bufctl approach is the better solution than storing the first 5 entries in the slab structure:
What if there is a leak on a cache with more than 5 entries per slab?

--
Manfred

#5 lore raw
Quoted 11 lines
Quoted 7 lines

Yeah I knew there was one, but I thought that was a standalone patch (the one turning all bufctl to unsigned long, turning off irqs and printing all slabs_full to console), my intention with this was a proper /proc entry, something that could be a simple config option.

No, I never wrote a proper /proc interface. But I think the bufctl approach is the better solution than storing the first 5 entries in the slab structure:
What if there is a leak on a cache with more than 5 entries per slab?

As slab leaks usually go out of control I think it will be enough to show what is leaking anyway, but you're right on the bufctl approach I think. I may have misundersood the bufctl thing a bit before doing this.