Skip to contentSkip to conversation

slab.c ATOMIC debug check to immediately trap atomic abuse while debugging

PATCH New Henrik Nordstrom 1 participant 1 message May 26, 2003 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slab.c ATOMIC debug check to immediately trap atomic abuse while debugging

Hi.

The attached patch extends slab debugging with an early check if ATOMIC is required. The patch is relative to 2.4.20 but may also be interesting for 2.5.

Normally the atomic requirement is only verified when the slab cache needs to grow, but with this patch such errors is detected immediately on first call if slab debugging is enabled.

This patch would have saved me from panic bug hunting after a system was sent into production as the errors then would have been trapped immediately during development. Probably many others would be helped by this slab debugging to trap stupid memory allocation / locking errors early on in development.

Regards
Henrik Nordström
MARA Systems AB, Sweden

mm/slab.c +6 -0
@@ -1338,6 +1338,12 @@
 	unsigned long save_flags;
 	void* objp;
 
+#if DEBUG
+	/* trap atomic bugs early on when debugging */
+	if (in_interrupt() && (flags & SLAB_LEVEL_MASK) != SLAB_ATOMIC)
+		BUG();
+#endif
+
 	kmem_cache_alloc_head(cachep, flags);
 try_again:
 	local_irq_save(save_flags);