Skip to content

Commit

Permalink
mm: Use __do_krealloc to do the krealloc job
Browse files Browse the repository at this point in the history
Without this patch we can get (many) kmem trace events
with call site at krealloc().

This happens because krealloc is calling __krealloc,
which performs the allocation through kmalloc_track_caller.

Since neither krealloc nor __krealloc are marked inline explicitly,
the caller can be traced as being krealloc, which clearly is not
the intended behavior.

This patch allows to get the real caller of krealloc, by creating
an always inlined function __do_krealloc, thus tracing the
call site accurately.

Acked-by: Christoph Lameter <[email protected]>
Cc: Glauber Costa <[email protected]>
Signed-off-by: Ezequiel Garcia <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
  • Loading branch information
ezequielgarcia authored and penberg committed Sep 4, 2012
1 parent 5b74beb commit e21827a
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions mm/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ void *memdup_user(const void __user *src, size_t len)
}
EXPORT_SYMBOL(memdup_user);

static __always_inline void *__do_krealloc(const void *p, size_t new_size,
gfp_t flags)
{
void *ret;
size_t ks = 0;

if (p)
ks = ksize(p);

if (ks >= new_size)
return (void *)p;

ret = kmalloc_track_caller(new_size, flags);
if (ret && p)
memcpy(ret, p, ks);

return ret;
}

/**
* __krealloc - like krealloc() but don't free @p.
* @p: object to reallocate memory for.
Expand All @@ -117,23 +136,11 @@ EXPORT_SYMBOL(memdup_user);
*/
void *__krealloc(const void *p, size_t new_size, gfp_t flags)
{
void *ret;
size_t ks = 0;

if (unlikely(!new_size))
return ZERO_SIZE_PTR;

if (p)
ks = ksize(p);
return __do_krealloc(p, new_size, flags);

if (ks >= new_size)
return (void *)p;

ret = kmalloc_track_caller(new_size, flags);
if (ret && p)
memcpy(ret, p, ks);

return ret;
}
EXPORT_SYMBOL(__krealloc);

Expand All @@ -157,7 +164,7 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags)
return ZERO_SIZE_PTR;
}

ret = __krealloc(p, new_size, flags);
ret = __do_krealloc(p, new_size, flags);
if (ret && p != ret)
kfree(p);

Expand Down

0 comments on commit e21827a

Please sign in to comment.