Skip to content

Commit 5eeb2d2

Browse files
author
Matthew Wilcox
committed
radix tree test suite: Introduce kmalloc_verbose
To help track down where memory leaks may be, add the ability to turn on/off printing allocations, frees and delayed frees. Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
1 parent d3e709e commit 5eeb2d2

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎tools/testing/radix-tree/linux.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
int nr_allocated;
1515
int preempt_count;
16+
int kmalloc_verbose;
1617

1718
struct kmem_cache {
1819
pthread_mutex_t lock;
@@ -44,13 +45,17 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, int flags)
4445
}
4546

4647
uatomic_inc(&nr_allocated);
48+
if (kmalloc_verbose)
49+
printf("Allocating %p from slab\n", node);
4750
return node;
4851
}
4952

5053
void kmem_cache_free(struct kmem_cache *cachep, void *objp)
5154
{
5255
assert(objp);
5356
uatomic_dec(&nr_allocated);
57+
if (kmalloc_verbose)
58+
printf("Freeing %p to slab\n", objp);
5459
pthread_mutex_lock(&cachep->lock);
5560
if (cachep->nr_objs > 10) {
5661
memset(objp, POISON_FREE, cachep->size);
@@ -68,6 +73,8 @@ void *kmalloc(size_t size, gfp_t gfp)
6873
{
6974
void *ret = malloc(size);
7075
uatomic_inc(&nr_allocated);
76+
if (kmalloc_verbose)
77+
printf("Allocating %p from malloc\n", ret);
7178
return ret;
7279
}
7380

@@ -76,6 +83,8 @@ void kfree(void *p)
7683
if (!p)
7784
return;
7885
uatomic_dec(&nr_allocated);
86+
if (kmalloc_verbose)
87+
printf("Freeing %p to malloc\n", p);
7988
free(p);
8089
}
8190

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1+
#ifndef _TEST_RADIX_TREE_H
2+
#define _TEST_RADIX_TREE_H
13
#include "../../../../include/linux/radix-tree.h"
4+
5+
extern int kmalloc_verbose;
6+
7+
static inline void trace_call_rcu(struct rcu_head *head,
8+
void (*func)(struct rcu_head *head))
9+
{
10+
if (kmalloc_verbose)
11+
printf("Delaying free of %p to slab\n", (char *)head -
12+
offsetof(struct radix_tree_node, rcu_head));
13+
call_rcu(head, func);
14+
}
15+
#undef call_rcu
16+
#define call_rcu(x, y) trace_call_rcu(x, y)
17+
18+
#endif /* _TEST_RADIX_TREE_H */

0 commit comments

Comments
 (0)