2013-10-08 22:59:25

by Tim Bird

[permalink] [raw]
Subject: [PATCH] slub: proper kmemleak tracking if CONFIG_SLUB_DEBUG disabled

From: Roman Bobniev <[email protected]>

Move all kmemleak calls into hook functions, and make it so
that all hooks (both inside and outside of #ifdef CONFIG_SLUB_DEBUG)
call the appropriate kmemleak routines. This allows for kmemleak
to be configured independently of slub debug features.

It also fixes a bug where kmemleak was only partially enabled in some
configurations.

Signed-off-by: Roman Bobniev <[email protected]>
Signed-off-by: Tim Bird <[email protected]>
---
mm/slub.c | 35 +++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index c3eb3d3..0bb8591 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -933,6 +933,16 @@ static void trace(struct kmem_cache *s, struct page *page, void *object,
* Hooks for other subsystems that check memory allocations. In a typical
* production configuration these hooks all should produce no code at all.
*/
+static inline void kmalloc_large_node_hook(void *ptr, size_t size, gfp_t flags)
+{
+ kmemleak_alloc(ptr, size, 1, flags);
+}
+
+static inline void kfree_hook(const void *x)
+{
+ kmemleak_free(x);
+}
+
static inline int slab_pre_alloc_hook(struct kmem_cache *s, gfp_t flags)
{
flags &= gfp_allowed_mask;
@@ -1260,13 +1270,30 @@ static inline void inc_slabs_node(struct kmem_cache *s, int node,
static inline void dec_slabs_node(struct kmem_cache *s, int node,
int objects) {}

+static inline void kmalloc_large_node_hook(void *ptr, size_t size, gfp_t flags)
+{
+ kmemleak_alloc(ptr, size, 1, flags);
+}
+
+static inline void kfree_hook(const void *x)
+{
+ kmemleak_free(x);
+}
+
static inline int slab_pre_alloc_hook(struct kmem_cache *s, gfp_t flags)
{ return 0; }

static inline void slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags,
- void *object) {}
+ void *object)
+{
+ kmemleak_alloc_recursive(object, s->object_size, 1, s->flags,
+ flags & gfp_allowed_mask);
+}

-static inline void slab_free_hook(struct kmem_cache *s, void *x) {}
+static inline void slab_free_hook(struct kmem_cache *s, void *x)
+{
+ kmemleak_free_recursive(x, s->flags);
+}

#endif /* CONFIG_SLUB_DEBUG */

@@ -3272,7 +3299,7 @@ static void *kmalloc_large_node(size_t size, gfp_t flags, int node)
if (page)
ptr = page_address(page);

- kmemleak_alloc(ptr, size, 1, flags);
+ kmalloc_large_node_hook(ptr, size, flags);
return ptr;
}

@@ -3336,7 +3363,7 @@ void kfree(const void *x)
page = virt_to_head_page(x);
if (unlikely(!PageSlab(page))) {
BUG_ON(!PageCompound(page));
- kmemleak_free(x);
+ kfree_hook(x);
__free_memcg_kmem_pages(page, compound_order(page));
return;
}
--
1.7.9.5


2013-10-09 13:28:59

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH] slub: proper kmemleak tracking if CONFIG_SLUB_DEBUG disabled

On Tue, Oct 08, 2013 at 11:58:57PM +0100, Tim Bird wrote:
> From: Roman Bobniev <[email protected]>
>
> Move all kmemleak calls into hook functions, and make it so
> that all hooks (both inside and outside of #ifdef CONFIG_SLUB_DEBUG)
> call the appropriate kmemleak routines. This allows for kmemleak
> to be configured independently of slub debug features.
>
> It also fixes a bug where kmemleak was only partially enabled in some
> configurations.
>
> Signed-off-by: Roman Bobniev <[email protected]>
> Signed-off-by: Tim Bird <[email protected]>

Looks ok to me.

Acked-by: Catalin Marinas <[email protected]>

Subject: Re: [PATCH] slub: proper kmemleak tracking if CONFIG_SLUB_DEBUG disabled

On Tue, 8 Oct 2013, Tim Bird wrote:

> It also fixes a bug where kmemleak was only partially enabled in some
> configurations.

Acked-by: Christoph Lameter <[email protected]>

2013-10-23 11:52:25

by Bobniev, Roman

[permalink] [raw]
Subject: RE: [PATCH] slub: proper kmemleak tracking if CONFIG_SLUB_DEBUG disabled

> On Tue, 8 Oct 2013, Tim Bird wrote:
>
> > It also fixes a bug where kmemleak was only partially enabled in some
> > configurations.
>
> Acked-by: Christoph Lameter <[email protected]>

Could you help me, who the maintainer is that
puts this patch in a tree and pushes it to mainline?
Do we wait on some additional Ack from someone?

With best regards,
Roman.-

2013-10-24 17:21:02

by Pekka Enberg

[permalink] [raw]
Subject: Re: [PATCH] slub: proper kmemleak tracking if CONFIG_SLUB_DEBUG disabled

On Wed, Oct 23, 2013 at 2:52 PM, Bobniev, Roman
<[email protected]> wrote:
>> On Tue, 8 Oct 2013, Tim Bird wrote:
>>
>> > It also fixes a bug where kmemleak was only partially enabled in some
>> > configurations.
>>
>> Acked-by: Christoph Lameter <[email protected]>
>
> Could you help me, who the maintainer is that
> puts this patch in a tree and pushes it to mainline?
> Do we wait on some additional Ack from someone?

That would be me - sorry for the delay!

Applied, thanks!