Commit e83c2b0f authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'kmemleak' of git://linux-arm.org/linux-2.6

* 'kmemleak' of git://linux-arm.org/linux-2.6:
  kmemleak: Inform kmemleak about pid_hash
  kmemleak: Do not warn if an unknown object is freed
  kmemleak: Do not report new leaked objects if the scanning was stopped
  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
  kmemleak: Allow the early log buffer to be configurable.
parents 9fcfc91b 12de38b1
...@@ -16,13 +16,17 @@ Usage ...@@ -16,13 +16,17 @@ Usage
----- -----
CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel 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 thread scans the memory every 10 minutes (by default) and prints the
unreferenced objects found. To trigger an intermediate scan and display number of new unreferenced objects found. To display the details of all
all the possible memory leaks: the possible memory leaks:
# mount -t debugfs nodev /sys/kernel/debug/ # mount -t debugfs nodev /sys/kernel/debug/
# cat /sys/kernel/debug/kmemleak # 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 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 and one object at the beginning of the list may cause other subsequent
objects to be reported as orphan. objects to be reported as orphan.
...@@ -31,16 +35,21 @@ Memory scanning parameters can be modified at run-time by writing to the ...@@ -31,16 +35,21 @@ Memory scanning parameters can be modified at run-time by writing to the
/sys/kernel/debug/kmemleak file. The following parameters are supported: /sys/kernel/debug/kmemleak file. The following parameters are supported:
off - disable kmemleak (irreversible) 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 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=off - stop the automatic memory scanning thread
scan=<secs> - set the automatic memory scanning period in seconds (0 scan=<secs> - set the automatic memory scanning period in seconds
to disable it) (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 Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on
the kernel command line. the kernel command line.
Memory may be allocated or freed before kmemleak is initialised and
these actions are stored in an early log buffer. The size of this buffer
is configured via the CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE option.
Basic Algorithm Basic Algorithm
--------------- ---------------
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <linux/pid_namespace.h> #include <linux/pid_namespace.h>
#include <linux/init_task.h> #include <linux/init_task.h>
#include <linux/syscalls.h> #include <linux/syscalls.h>
#include <linux/kmemleak.h>
#define pid_hashfn(nr, ns) \ #define pid_hashfn(nr, ns) \
hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift) hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
...@@ -512,6 +513,12 @@ void __init pidhash_init(void) ...@@ -512,6 +513,12 @@ void __init pidhash_init(void)
pid_hash = alloc_bootmem(pidhash_size * sizeof(*(pid_hash))); pid_hash = alloc_bootmem(pidhash_size * sizeof(*(pid_hash)));
if (!pid_hash) if (!pid_hash)
panic("Could not alloc pidhash!\n"); panic("Could not alloc pidhash!\n");
/*
* pid_hash contains references to allocated struct pid objects and it
* must be scanned by kmemleak to avoid false positives.
*/
kmemleak_alloc(pid_hash, pidhash_size * sizeof(*(pid_hash)), 0,
GFP_KERNEL);
for (i = 0; i < pidhash_size; i++) for (i = 0; i < pidhash_size; i++)
INIT_HLIST_HEAD(&pid_hash[i]); INIT_HLIST_HEAD(&pid_hash[i]);
} }
......
...@@ -359,6 +359,18 @@ config DEBUG_KMEMLEAK ...@@ -359,6 +359,18 @@ config DEBUG_KMEMLEAK
In order to access the kmemleak file, debugfs needs to be In order to access the kmemleak file, debugfs needs to be
mounted (usually at /sys/kernel/debug). mounted (usually at /sys/kernel/debug).
config DEBUG_KMEMLEAK_EARLY_LOG_SIZE
int "Maximum kmemleak early log entries"
depends on DEBUG_KMEMLEAK
range 200 2000
default 400
help
Kmemleak must track all the memory allocations to avoid
reporting false positives. Since memory may be allocated or
freed before kmemleak is initialised, an early log buffer is
used to store these actions. If kmemleak reports "early log
buffer exceeded", please increase this value.
config DEBUG_KMEMLEAK_TEST config DEBUG_KMEMLEAK_TEST
tristate "Simple test for the kernel memory leak detector" tristate "Simple test for the kernel memory leak detector"
depends on DEBUG_KMEMLEAK depends on DEBUG_KMEMLEAK
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment