mm/kmemleak: add support for re-enable kmemleak at runtime
Subsystems (3)
PATCH 1/1 mm/kmemleak: add support for re-enable kmemleak at runtime
Now disabling kmemleak is an irreversible operation, but sometimes we may need to re-enable kmemleak at runtime. So add a knob to enable kmemleak at runtime:
echo on > /sys/kernel/debug/kmemleak
--- Documentation/kmemleak.txt | 3 ++- mm/kmemleak.c | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-)
Documentation/kmemleak.txt +2 -1
@@ -44,7 +44,8 @@ objects to be reported as orphan. 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) + off - disable kmemleak + on - enable kmemleak stack=on - enable the task stacks scanning (default) stack=off - disable the tasks stacks scanning scan=on - start the automatic memory scanning thread (default)
mm/kmemleak.c +33 -4
@@ -260,6 +260,7 @@ static struct early_logstatic int crt_early_log__initdata ;static void kmemleak_disable (void ); +static void kmemleak_enable (void );/* * Print a warning and dump the stack trace.
@@ -1616,9 +1617,6 @@ static ssize_t kmemleak_write(struct file *file, const char __user *user_buf,int buf_size;int ret; -if (!atomic_read (&kmemleak_enabled)) -return -EBUSY ; - buf_size =min (size, (sizeof (buf) -1 ));if (strncpy_from_user (buf, user_buf, buf_size) <0 )return -EFAULT ;
@@ -1628,6 +1626,19 @@ static ssize_t kmemleak_write(struct file *file, const char __user *user_buf,if (ret <0 )return ret; +if (strncmp (buf,"on" ,2 ) ==0 ) { +if (atomic_read (&kmemleak_enabled)) + ret = -EBUSY ; +else +kmemleak_enable (); + goto out; + } + +if (!atomic_read (&kmemleak_enabled)) { + ret = -EBUSY ; + goto out; + } +if (strncmp (buf,"off" ,3 ) ==0 )kmemleak_disable ();else if (strncmp (buf,"stack=on" ,8 ) ==0 )
@@ -1703,7 +1714,7 @@ static DECLARE_WORK(cleanup_work, kmemleak_do_cleanup);/* * Disable kmemleak. No memory allocation/freeing will be traced once this -* function is called. Disabling kmemleak is an irreversible operation. +* function is called. */ static void kmemleak_disable (void ) {
@@ -1721,6 +1732,24 @@ static void kmemleak_disable(void)pr_info ("Kernel memory leak detector disabled\n" ); } +static void kmemleak_enable (void ) +{ +struct kmemleak_object *object; + +/* free the kmemleak internal objects the previous thread scanned */ +rcu_read_lock (); +list_for_each_entry_rcu (object, &object_list, object_list) +delete_object_full (object->pointer); +rcu_read_unlock (); + +atomic_set (&kmemleak_enabled,1 ); +atomic_set (&kmemleak_error,0 ); + +start_scan_thread (); + +pr_info ("Kernel memory leak detector enabled\n" ); +} +/* * Allow boot-time kmemleak disabling (enabled by default). */
Signature · 1 line
1.7.7
Catalin Marinas
maintainerQuoted 4 lines · Jianguo Wu
Now disabling kmemleak is an irreversible operation, but sometimes we may need to re-enable kmemleak at runtime. So add a knob to enable kmemleak at runtime:
echo on >/sys/kernel/debug/kmemleak
It is irreversible for very good reason: once it missed the initial memory allocations, there is no way for kmemleak to build the object reference graph and you'll get lots of false positives, pretty much making it unusable.
Signature · 7 lines
Catalin -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Catalin Marinas
Quoted 4 lines · Jianguo Wu
Now disabling kmemleak is an irreversible operation, but sometimes we may need to re-enable kmemleak at runtime. So add a knob to enable kmemleak at runtime:
echo on >/sys/kernel/debug/kmemleakIt is irreversible for very good reason: once it missed the initial memory allocations, there is no way for kmemleak to build the object reference graph and you'll get lots of false positives, pretty much making it unusable.
Do you mean we didn't trace memory allocations during kmemleak disable period, and these memory may reference to new allocated objects after re-enable?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Catalin Marinas
maintainerQuoted 7 lines · Jianguo Wu
Quoted 6 lines · Catalin Marinas
Quoted 4 lines · Jianguo Wu
Now disabling kmemleak is an irreversible operation, but sometimes we may need to re-enable kmemleak at runtime. So add a knob to enable kmemleak at runtime:
echo on >/sys/kernel/debug/kmemleak
Quoted 7 lines
Quoted 4 lines
It is irreversible for very good reason: once it missed the initial memory allocations, there is no way for kmemleak to build the object reference graph and you'll get lots of false positives, pretty much making it unusable.
Do you mean we didn't trace memory allocations during kmemleak disable period, and these memory may reference to new allocated objects after re-enable?
Yes. Those newly allocated objects would be reported as leaks.
Catalin
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>