Skip to contentSkip to conversation

mm/kmemleak: Minor cleanup & performance tuning

PATCH Applied Waiman Long 2 participants 5 messages Mar 7, 2024 – Mar 26, 2024

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

cover mm/kmemleak: Minor cleanup & performance tuning

This series contains 2 simple cleanup patches to slightly reduce memory and performance overhead.

Waiman Long (2):
mm/kmemleak: Compact kmemleak_object further mm/kmemleak: Disable KASAN instrumentation in kmemleak

 mm/Makefile   | 1 +
 mm/kmemleak.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.39.3
#1 lore raw

PATCH 1/2 mm/kmemleak: Compact kmemleak_object further

With commit 56a61617dd22 ("mm: use stack_depot for recording kmemleak's backtrace"), the size of kmemleak_object has been reduced by 128 bytes for 64-bit arches. The replacement "depot_stack_handle_t trace_handle" is actually just 4 bytes long leaving a hole of 4 bytes. By moving up trace_handle to another existing 4-byte hold, we can save 8 more bytes from kmemleak_object reducing its overall size from 248 to 240 bytes.

---
 mm/kmemleak.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kmemleak.c +1 -1
index 4f58f6170cdf..0114a694e520 100644
@@ -158,9 +158,9 @@ struct kmemleak_object {
 	int count;
 	/* checksum for detecting modified objects */
 	u32 checksum;
+	depot_stack_handle_t trace_handle;
 	/* memory ranges to be scanned inside an object (empty for all) */
 	struct hlist_head area_list;
-	depot_stack_handle_t trace_handle;
 	unsigned long jiffies;		/* creation timestamp */
 	pid_t pid;			/* pid of the current task */
 	char comm[TASK_COMM_LEN];	/* executable name */
Signature · 1 line
2.39.3
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] mm/kmemleak: Compact kmemleak_object further

Quoted 8 lines · Waiman Long

With commit 56a61617dd22 ("mm: use stack_depot for recording kmemleak's backtrace"), the size of kmemleak_object has been reduced by 128 bytes for 64-bit arches. The replacement "depot_stack_handle_t trace_handle" is actually just 4 bytes long leaving a hole of 4 bytes. By moving up trace_handle to another existing 4-byte hold, we can save 8 more bytes from kmemleak_object reducing its overall size from 248 to 240 bytes.

#3 lore raw

PATCH 2/2 mm/kmemleak: Disable KASAN instrumentation in kmemleak

In reply to Waiman Long

Kmemleak ia a memory leak checker. KASAN is also a memory checker but it focuses more on finding out-of-bounds and use-after-free bugs. Since kmemleak is inherently slow especially on systems with large number of CPUs, adding KASAN instrumentation will make it slower even more. As kmemleak is not for production use, the utility of enabling KASAN there is questionable.

This patch disables KASAN instrumentation for configurations that enable both of them to slightly reduce performance overhead.

---
 mm/Makefile | 1 +
 1 file changed, 1 insertion(+)
mm/Makefile +1 -0
index e4b5b75aaec9..fc0f9a63a61e 100644
@@ -5,6 +5,7 @@
 
 KASAN_SANITIZE_slab_common.o := n
 KASAN_SANITIZE_slub.o := n
+KASAN_SANITIZE_kmemleak.o := n
 KCSAN_SANITIZE_kmemleak.o := n
 
 # These produce frequent data race reports: most of them are due to races on
Signature · 1 line
2.39.3
maintainer Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] mm/kmemleak: Disable KASAN instrumentation in kmemleak

Quoted 11 lines · Waiman Long

Kmemleak ia a memory leak checker. KASAN is also a memory checker but it focuses more on finding out-of-bounds and use-after-free bugs. Since kmemleak is inherently slow especially on systems with large number of CPUs, adding KASAN instrumentation will make it slower even more. As kmemleak is not for production use, the utility of enabling KASAN there is questionable.

This patch disables KASAN instrumentation for configurations that enable both of them to slightly reduce performance overhead.