Re: [PATCH RFC] kmemleak vs. memory hotplug

From: Catalin Marinas
Date: Tue Mar 23 2010 - 05:26:12 EST


On Mon, 2010-03-22 at 19:51 +0000, Jason Baron wrote:
> I noticed in the Kconfig that kmemleak can not be set without
> MEMORY_HOTPLUG being unset. I'd like to be able to enable both. Below,
> is an rfc patch, completely untested, as a starting point. Hopefully,
> ppl more knowledgeable in this area can comment.
[...]
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index 5b069e4..509a728 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -102,6 +102,9 @@
> #include <linux/kmemcheck.h>
> #include <linux/kmemleak.h>
>
> +/* exlcludes memory hotplug */
> +DEFINE_MUTEX(kmemleak_hotplug);
> +
> /*
> * Kmemleak configuration and common defines.
> */
> @@ -1178,6 +1181,7 @@ static void kmemleak_scan(void)
> * Struct page scanning for each node. The code below is not yet safe
> * with MEMORY_HOTPLUG.
> */
> + mutex_lock(&kmemleak_hotplug);
> for_each_online_node(i) {
> pg_data_t *pgdat = NODE_DATA(i);
> unsigned long start_pfn = pgdat->node_start_pfn;
> @@ -1196,6 +1200,7 @@ static void kmemleak_scan(void)
> scan_block(page, page + 1, NULL, 1);
> }
> }
> + mutex_unlock(&kmemleak_hotplug);

An alternative (not sure whether it's feasible) may be to inform
kmemleak about the pg_data_t objects (via kmemleak_alloc) sometime
during initialisation and add hooks to memory hotplug to remove or add
such objects from kmemleak during hotplug events.

> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 78e34e6..01fc57d 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -34,6 +34,23 @@
>
> #include "internal.h"
>
> +/* exclude subsystems that hotplug might conflict with */
> +static void lock_hotplug_exlucde(void)
> +{
> + /* exclude hotplug */
> + lock_system_sleep();
> + /* exlucde kmemleak */
> + lock_system_kmemleak();
> +}
> +
> +static void unlock_hotplug_exlucde(void)
> +{
> + /* exclude hotplug */
> + unlock_system_sleep();
> + /* exlucde kmemleak */
> + unlock_system_kmemleak();
> +}

I think the unlocking should be done in the reversed order.

Thanks.

--
Catalin

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/