Skip to content

Commit 000a449

Browse files
howlettakpm00
authored andcommitted
radix tree test suite: add allocation counts and size to kmem_cache
Add functions to get the number of allocations, and total allocations from a kmem_cache. Also add a function to get the allocated size and a way to zero the total allocations. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Liam R. Howlett <[email protected]> Tested-by: Yu Zhao <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: David Howells <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: "Matthew Wilcox (Oracle)" <[email protected]> Cc: SeongJae Park <[email protected]> Cc: Sven Schnelle <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e73cb36 commit 000a449

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tools/testing/radix-tree/linux.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,37 @@ struct kmem_cache {
2424
void *objs;
2525
void (*ctor)(void *);
2626
unsigned int non_kernel;
27+
unsigned long nr_allocated;
28+
unsigned long nr_tallocated;
2729
};
2830

2931
void kmem_cache_set_non_kernel(struct kmem_cache *cachep, unsigned int val)
3032
{
3133
cachep->non_kernel = val;
3234
}
3335

36+
unsigned long kmem_cache_get_alloc(struct kmem_cache *cachep)
37+
{
38+
return cachep->size * cachep->nr_allocated;
39+
}
40+
41+
unsigned long kmem_cache_nr_allocated(struct kmem_cache *cachep)
42+
{
43+
return cachep->nr_allocated;
44+
}
45+
46+
unsigned long kmem_cache_nr_tallocated(struct kmem_cache *cachep)
47+
{
48+
return cachep->nr_tallocated;
49+
}
50+
51+
void kmem_cache_zero_nr_tallocated(struct kmem_cache *cachep)
52+
{
53+
cachep->nr_tallocated = 0;
54+
}
55+
3456
void *kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
3557
int gfp)
36-
3758
{
3859
void *p;
3960

@@ -64,7 +85,9 @@ void *kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
6485
memset(p, 0, cachep->size);
6586
}
6687

88+
uatomic_inc(&cachep->nr_allocated);
6789
uatomic_inc(&nr_allocated);
90+
uatomic_inc(&cachep->nr_tallocated);
6891
if (kmalloc_verbose)
6992
printf("Allocating %p from slab\n", p);
7093
return p;
@@ -74,6 +97,7 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp)
7497
{
7598
assert(objp);
7699
uatomic_dec(&nr_allocated);
100+
uatomic_dec(&cachep->nr_allocated);
77101
if (kmalloc_verbose)
78102
printf("Freeing %p to slab\n", objp);
79103
pthread_mutex_lock(&cachep->lock);
@@ -99,6 +123,8 @@ kmem_cache_create(const char *name, unsigned int size, unsigned int align,
99123
ret->size = size;
100124
ret->align = align;
101125
ret->nr_objs = 0;
126+
ret->nr_allocated = 0;
127+
ret->nr_tallocated = 0;
102128
ret->objs = NULL;
103129
ret->ctor = ctor;
104130
ret->non_kernel = 0;

0 commit comments

Comments
 (0)