From: "Pekka Enberg" <penberg@cs.helsinki.fi>
To: "Catalin Marinas" <catalin.marinas@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2.6.17-rc6 1/9] Base support for kmemleak
Date: Tue, 13 Jun 2006 14:14:01 +0300 [thread overview]
Message-ID: <84144f020606130414m9f1cdaq2a0ccb29a5c3b2dd@mail.gmail.com> (raw)
In-Reply-To: <20060611112105.8641.31038.stgit@localhost.localdomain>
Hi Catalin,
On 6/11/06, Catalin Marinas <catalin.marinas@gmail.com> wrote:
> This patch adds the base support for the kernel memory leak detector. It
> traces the memory allocation/freeing in a way similar to the Boehm's
> conservative garbage collector, the difference being that the orphan
> pointers are not freed but only shown in /proc/memleak. Enabling this
> feature would introduce an overhead to memory allocations.
Some coding style comments below.
> --- /dev/null
> +++ b/include/linux/memleak.h
> @@ -0,0 +1,83 @@
> +extern void memleak_scan_area(const void *ptr, unsigned long offset, size_t length);
> +extern void memleak_insert_aliases(struct memleak_offset *ml_off_start,
> + struct memleak_offset *ml_off_end);
> +
> +#define memleak_erase(ptr) do { (ptr) = NULL; } while (0)
Use static inline functions instead of macros, please.
> +#define memleak_init()
> +#define memleak_alloc(ptr, size, ref_count)
> +#define memleak_free(ptr)
> +#define memleak_padding(ptr, offset, size)
> +#define memleak_not_leak(ptr)
> +#define memleak_ignore(ptr)
> +#define memleak_scan_area(ptr, offset, length)
> +#define memleak_insert_aliases(ml_off_start, ml_off_end)
> +#define memleak_erase(ptr)
> +#define memleak_container(type, member)
Ditto.
> --- /dev/null
> +++ b/mm/memleak.c
> @@ -0,0 +1,1166 @@
> +typedef enum {
> + MEMLEAK_ALLOC,
> + MEMLEAK_FREE,
> + MEMLEAK_PADDING,
> + MEMLEAK_NOT_LEAK,
> + MEMLEAK_IGNORE,
> + MEMLEAK_SCAN_AREA
> +} memleak_action_t;
Please drop the typedef.
> +/* Pointer colors, encoded with count and ref_count:
> + * - white - orphan block, i.e. not enough references to it (ref_count >= 1)
> + * - gray - referred at least once and therefore non-orphan (ref_count == 0)
> + * - black - ignore; it doesn't contain references (text section) (ref_count == -1)
> + */
> +#define COLOR_WHITE(pointer) ((pointer)->count != -1 && (pointer)->count < (pointer)->ref_count)
> +#define COLOR_GRAY(pointer) ((pointer)->ref_count != -1 && (pointer)->count >= (pointer)->ref_count)
> +#define COLOR_BLACK(pointer) ((pointer)->ref_count == -1)
Use static inline functions instead of macros, please.
> +
> +static kmem_cache_t *pointer_cache;
Please use struct kmem_cache instead of the typedef.
> +static int __initdata preinit_pos = 0;
Unnecessary initialization to zero.
> +static struct memleak_pointer *last_pointer = NULL;
Same here for NULL.
> +
> +static void dump_pointer_info(struct memleak_pointer *pointer)
> +{
> +#ifdef CONFIG_KALLSYMS
> + char namebuf[KSYM_NAME_LEN + 1] = "";
> + char *modname;
> + unsigned long symsize;
> + unsigned long offset = 0;
> +#endif
> +#ifdef DEBUG
> + struct memleak_alias *alias;
> + struct hlist_node *elem;
> +#endif
> + int i;
> +
> + printk(KERN_NOTICE "kmemleak: pointer 0x%08lx:\n", pointer->pointer);
> +#ifdef DEBUG
> + printk(KERN_NOTICE " size = %d\n", pointer->size);
> + printk(KERN_NOTICE " ref_count = %d\n", pointer->ref_count);
> + printk(KERN_NOTICE " count = %d\n", pointer->count);
> + printk(KERN_NOTICE " aliases:\n");
> + if (pointer->alias_list)
> + hlist_for_each_entry(alias, elem, pointer->alias_list, node)
> + printk(KERN_NOTICE " 0x%lx\n", alias->offset);
> + printk(KERN_NOTICE " trace:\n");
> +#endif
> + for (i = 0; i < MAX_TRACE; i++) {
> + unsigned long trace = pointer->trace[i];
> +
> + if (!trace)
> + break;
> +#ifdef CONFIG_KALLSYMS
> + kallsyms_lookup(trace, &symsize, &offset, &modname, namebuf);
> + printk(KERN_NOTICE " %lx: <%s>\n", trace, namebuf);
> +#else
> + printk(KERN_NOTICE " %lx\n", trace);
> +#endif
Please move both #ifdef cases into separate functions and provide a
stub for the case where they're not enabled for readability.
> +static int insert_alias(unsigned long size, unsigned long offset)
> +{
> + int ret = 0;
Unnecessary initialization to zero.
> +/* KMemLeak initialization. Set up the radix tree for the pointer aliases */
> +void __init memleak_init(void)
> +{
> + int i = 0;
Unnecessary initialization to zero.
next prev parent reply other threads:[~2006-06-13 11:14 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-11 11:18 [PATCH 2.6.17-rc6 0/9] Kernel memory leak detector 0.7 Catalin Marinas
2006-06-11 11:21 ` [PATCH 2.6.17-rc6 1/9] Base support for kmemleak Catalin Marinas
2006-06-13 11:14 ` Pekka Enberg [this message]
2006-06-13 12:47 ` Catalin Marinas
2006-06-11 11:21 ` [PATCH 2.6.17-rc6 2/9] Some documentation " Catalin Marinas
2006-06-11 11:21 ` [PATCH 2.6.17-rc6 3/9] Add the memory allocation/freeing hooks " Catalin Marinas
2006-06-11 11:21 ` [PATCH 2.6.17-rc6 4/9] Modules support " Catalin Marinas
2006-06-11 11:21 ` [PATCH 2.6.17-rc6 5/9] Add kmemleak support for i386 Catalin Marinas
2006-06-11 11:21 ` [PATCH 2.6.17-rc6 6/9] Add kmemleak support for ARM Catalin Marinas
2006-06-11 11:21 ` [PATCH 2.6.17-rc6 7/9] Remove some of the kmemleak false positives Catalin Marinas
2006-06-12 5:19 ` Pekka Enberg
2006-06-12 8:11 ` Catalin Marinas
2006-06-12 8:17 ` Pekka J Enberg
2006-06-12 8:43 ` Catalin Marinas
2006-06-12 10:53 ` Ingo Molnar
2006-06-12 11:08 ` Pekka J Enberg
2006-06-12 11:36 ` Ingo Molnar
2006-06-12 11:56 ` Pekka J Enberg
2006-06-12 12:53 ` Catalin Marinas
2006-06-12 13:12 ` Ingo Molnar
2006-06-12 14:38 ` Catalin Marinas
2006-06-12 22:29 ` Catalin Marinas
2006-06-12 12:56 ` Catalin Marinas
2006-06-12 19:22 ` Ingo Molnar
2006-06-12 22:24 ` Catalin Marinas
2006-06-13 5:53 ` Pekka J Enberg
2006-06-13 6:59 ` Catalin Marinas
2006-06-13 7:57 ` Pekka J Enberg
2006-06-13 9:45 ` Catalin Marinas
2006-06-13 10:04 ` Pekka Enberg
2006-06-13 10:37 ` Catalin Marinas
2006-06-13 7:26 ` Ingo Molnar
2006-06-13 8:11 ` Pekka J Enberg
2006-06-13 10:49 ` Catalin Marinas
2006-06-14 4:07 ` Ingo Molnar
2006-06-14 5:46 ` Andi Kleen
2006-06-14 5:53 ` Jeremy Fitzhardinge
2006-06-14 12:03 ` Ingo Molnar
2006-06-14 13:46 ` Catalin Marinas
2006-06-14 13:35 ` Catalin Marinas
2006-06-14 13:21 ` Catalin Marinas
2006-06-12 9:17 ` Peter Zijlstra
2006-06-12 9:35 ` Catalin Marinas
2006-06-24 10:20 ` Catalin Marinas
2006-06-24 10:22 ` Ingo Molnar
2006-06-24 10:55 ` Catalin Marinas
2006-07-24 11:15 ` Ingo Molnar
2006-07-24 13:28 ` Catalin Marinas
2006-08-03 6:32 ` Jakub Jelinek
2006-08-03 8:31 ` Catalin Marinas
2006-06-11 11:22 ` [PATCH 2.6.17-rc6 8/9] Simple testing for kmemleak Catalin Marinas
2006-06-11 11:22 ` [PATCH 2.6.17-rc6 9/9] Keep the __init functions after initialization Catalin Marinas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=84144f020606130414m9f1cdaq2a0ccb29a5c3b2dd@mail.gmail.com \
--to=penberg@cs.helsinki.fi \
--cc=catalin.marinas@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®