diff options
author | Matthew Wilcox <mawilcox@microsoft.com> | 2016-12-24 07:49:18 -0500 |
---|---|---|
committer | Matthew Wilcox <mawilcox@microsoft.com> | 2017-02-13 21:44:03 -0500 |
commit | 5eeb2d23df29212f901a36dabf16f93d8bd50814 (patch) | |
tree | 378aac4a3639c24343014a58c5c492a1bd886491 /tools | |
parent | d3e709e63e97e5f3f129b639991cfe266da60bae (diff) |
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/radix-tree/linux.c | 9 | ||||
-rw-r--r-- | tools/testing/radix-tree/linux/radix-tree.h | 17 |
2 files changed, 26 insertions, 0 deletions
diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c index 93f06614e91b..3e4f9f36da2e 100644 --- a/tools/testing/radix-tree/linux.c +++ b/tools/testing/radix-tree/linux.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | int nr_allocated; | 14 | int nr_allocated; |
15 | int preempt_count; | 15 | int preempt_count; |
16 | int kmalloc_verbose; | ||
16 | 17 | ||
17 | struct kmem_cache { | 18 | struct kmem_cache { |
18 | pthread_mutex_t lock; | 19 | pthread_mutex_t lock; |
@@ -44,6 +45,8 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, int flags) | |||
44 | } | 45 | } |
45 | 46 | ||
46 | uatomic_inc(&nr_allocated); | 47 | uatomic_inc(&nr_allocated); |
48 | if (kmalloc_verbose) | ||
49 | printf("Allocating %p from slab\n", node); | ||
47 | return node; | 50 | return node; |
48 | } | 51 | } |
49 | 52 | ||
@@ -51,6 +54,8 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp) | |||
51 | { | 54 | { |
52 | assert(objp); | 55 | assert(objp); |
53 | uatomic_dec(&nr_allocated); | 56 | uatomic_dec(&nr_allocated); |
57 | if (kmalloc_verbose) | ||
58 | printf("Freeing %p to slab\n", objp); | ||
54 | pthread_mutex_lock(&cachep->lock); | 59 | pthread_mutex_lock(&cachep->lock); |
55 | if (cachep->nr_objs > 10) { | 60 | if (cachep->nr_objs > 10) { |
56 | memset(objp, POISON_FREE, cachep->size); | 61 | memset(objp, POISON_FREE, cachep->size); |
@@ -68,6 +73,8 @@ void *kmalloc(size_t size, gfp_t gfp) | |||
68 | { | 73 | { |
69 | void *ret = malloc(size); | 74 | void *ret = malloc(size); |
70 | uatomic_inc(&nr_allocated); | 75 | uatomic_inc(&nr_allocated); |
76 | if (kmalloc_verbose) | ||
77 | printf("Allocating %p from malloc\n", ret); | ||
71 | return ret; | 78 | return ret; |
72 | } | 79 | } |
73 | 80 | ||
@@ -76,6 +83,8 @@ void kfree(void *p) | |||
76 | if (!p) | 83 | if (!p) |
77 | return; | 84 | return; |
78 | uatomic_dec(&nr_allocated); | 85 | uatomic_dec(&nr_allocated); |
86 | if (kmalloc_verbose) | ||
87 | printf("Freeing %p to malloc\n", p); | ||
79 | free(p); | 88 | free(p); |
80 | } | 89 | } |
81 | 90 | ||
diff --git a/tools/testing/radix-tree/linux/radix-tree.h b/tools/testing/radix-tree/linux/radix-tree.h index ce694ddd4aea..f4d8532e1bef 100644 --- a/tools/testing/radix-tree/linux/radix-tree.h +++ b/tools/testing/radix-tree/linux/radix-tree.h | |||
@@ -1 +1,18 @@ | |||
1 | #ifndef _TEST_RADIX_TREE_H | ||
2 | #define _TEST_RADIX_TREE_H | ||
1 | #include "../../../../include/linux/radix-tree.h" | 3 | #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 */ | ||