Kmemleak improvements on false positives
Subsystems (3)
Catalin Marinas
maintainercover Kmemleak improvements on false positives
Hi,
This set of patches are aimed at reducing the amount of false positives and the verbosity of the kmemleak reports. The task stack scanning is no enabled by default but this can be disabled at run-time with a risk of more false positives.
I haven't looked into Sergey's function filtering patch yet.
Thanks for your comments.
Catalin Marinas (4):
kmemleak: Slightly change the policy on newly allocated objects
kmemleak: Do not trigger a scan when reading the debug/kmemleak file
kmemleak: Simplify the reports logged by the scanning thread
kmemleak: Enable task stacks scanning by default
Documentation/kmemleak.txt | 19 ++++-- mm/kmemleak.c | 144 +++++++++++++++++--------------------------- 2 files changed, 67 insertions(+), 96 deletions(-)
Signature · 1 line
Catalin
Catalin Marinas
maintainerPATCH 1/4 kmemleak: Enable task stacks scanning by default
This is to reduce the number of false positives reported.
--- Documentation/kmemleak.txt | 8 ++++---- mm/kmemleak.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
Documentation/kmemleak.txt +4 -4
@@ -31,12 +31,12 @@ Memory scanning parameters can be modified at run-time by writing to the /sys/kernel/debug/kmemleak file. The following parameters are supported: off - disable kmemleak (irreversible) - stack=on - enable the task stacks scanning + stack=on - enable the task stacks scanning (default) stack=off - disable the tasks stacks scanning - scan=on - start the automatic memory scanning thread + scan=on - start the automatic memory scanning thread (default) scan=off - stop the automatic memory scanning thread - scan=<secs> - set the automatic memory scanning period in seconds (0 - to disable it) + scan=<secs> - set the automatic memory scanning period in seconds + (default 600, 0 to stop the automatic scanning) Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on the kernel command line.
mm/kmemleak.c +1 -1
@@ -194,7 +194,7 @@ static unsigned long jiffies_min_age;/* delay between automatic memory scannings */ static signed long jiffies_scan_wait;/* enables or disables the task stacks scanning */ -static int kmemleak_stack_scan; +static int kmemleak_stack_scan =1 ;/* mutex protecting the memory scanning */ static DEFINE_MUTEX (scan_mutex);/* mutex protecting the access to the /sys/kernel/debug/kmemleak file */
Catalin Marinas
maintainerPATCH 2/4 kmemleak: Simplify the reports logged by the scanning thread
In reply to Catalin MarinasBecause of false positives, the memory scanning thread may print too much information. This patch changes the scanning thread to only print the number of newly suspected leaks. Further information can be read from the /sys/kernel/debug/kmemleak file.
--- Documentation/kmemleak.txt | 6 ++-- mm/kmemleak.c | 61 ++++++++++++-------------------------------- 2 files changed, 19 insertions(+), 48 deletions(-)
Documentation/kmemleak.txt +3 -3
@@ -16,9 +16,9 @@ Usage ----- CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel -thread scans the memory every 10 minutes (by default) and prints any new -unreferenced objects found. To trigger an intermediate scan and display -all the possible memory leaks: +thread scans the memory every 10 minutes (by default) and prints the +number of new unreferenced objects found. To trigger an intermediate +scan and display the details of all the possible memory leaks: # mount -t debugfs nodev /sys/kernel/debug/ # cat /sys/kernel/debug/kmemleak
mm/kmemleak.c +16 -45
110 lines not on this page · raw message
Catalin Marinas
maintainerPATCH 3/4 kmemleak: Do not trigger a scan when reading the debug/kmemleak file
In reply to Catalin MarinasSince there is a kernel thread for automatically scanning the memory, it makes sense for the debug/kmemleak file to only show its findings. This patch also adds support for "echo scan > debug/kmemleak" to trigger an intermediate memory scan and eliminates the kmemleak_mutex (scan_mutex covers all the cases now).
--- Documentation/kmemleak.txt | 9 +++- mm/kmemleak.c | 90 ++++++++++++++++++++------------------------ 2 files changed, 47 insertions(+), 52 deletions(-)
Documentation/kmemleak.txt +7 -2
@@ -17,12 +17,16 @@ Usage CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel thread scans the memory every 10 minutes (by default) and prints the -number of new unreferenced objects found. To trigger an intermediate -scan and display the details of all the possible memory leaks: +number of new unreferenced objects found. To display the details of all +the possible memory leaks: # mount -t debugfs nodev /sys/kernel/debug/ # cat /sys/kernel/debug/kmemleak +To trigger an intermediate memory scan: + + # echo scan > /sys/kernel/debug/kmemleak + Note that the orphan objects are listed in the order they were allocated and one object at the beginning of the list may cause other subsequent objects to be reported as orphan.
@@ -37,6 +41,7 @@ Memory scanning parameters can be modified at run-time by writing to the scan=off - stop the automatic memory scanning thread scan=<secs> - set the automatic memory scanning period in seconds (default 600, 0 to stop the automatic scanning) + scan - trigger a memory scan Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on the kernel command line.
mm/kmemleak.c +40 -50
194 lines not on this page · raw message
Catalin Marinas
maintainerPATCH 4/4 kmemleak: Slightly change the policy on newly allocated objects
In reply to Catalin MarinasNewly allocated objects are more likely to be reported as false positives. Kmemleak ignores the reporting of objects younger than 5 seconds. However, this age was calculated after the memory scanning completed which usually takes longer than 5 seconds. This patch make the minimum object age calculation in relation to the start of the memory scanning.
--- mm/kmemleak.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
mm/kmemleak.c +6 -1
@@ -190,7 +190,9 @@ static unsigned long max_addr;static unsigned long next_scan_yield;static struct task_struct *scan_thread;static unsigned long jiffies_scan_yield; +/* used to avoid reporting of recently allocated objects */ static unsigned long jiffies_min_age; +static unsigned long jiffies_last_scan;/* delay between automatic memory scannings */ static signed long jiffies_scan_wait;/* enables or disables the task stacks scanning */
@@ -284,7 +286,8 @@ static int color_gray(const struct kmemleak_object *object)static int unreferenced_object (struct kmemleak_object *object) {return (object->flags &OBJECT_ALLOCATED ) &&color_white (object) && -time_is_before_eq_jiffies (object->jiffies + jiffies_min_age); +time_before_eq (object->jiffies + jiffies_min_age, + jiffies_last_scan); }/*
@@ -927,6 +930,8 @@ static void kmemleak_scan(void)int i;int new_leaks =0 ; + jiffies_last_scan = jiffies; +/* prepare the kmemleak_object's */ rcu_read_lock ();list_for_each_entry_rcu (object, &object_list, object_list) {