From: Liam R. Howlett Date: Sat, 17 Oct 2020 00:05:01 +0000 (-0400) Subject: tools/testing/radix-tree: Add keme_cache_alloc_bulk() support X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1b4f149f0270ef55e5dd684c4a71b3449ca424ab;p=users%2Fjedix%2Flinux-maple.git tools/testing/radix-tree: Add keme_cache_alloc_bulk() support Signed-off-by: Liam R. Howlett --- diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c index f32cc5eac77ef..f7fc20fff9197 100644 --- a/tools/testing/radix-tree/linux.c +++ b/tools/testing/radix-tree/linux.c @@ -101,6 +101,55 @@ void kmem_cache_free_bulk(struct kmem_cache *cachep, size_t size, void **list) kmem_cache_free(cachep, list[i]); } } +int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size, + void **p) +{ + size_t i; + if (kmalloc_verbose) + printk("Bulk alloc %lu\n", size); + + if (!(gfp & __GFP_DIRECT_RECLAIM) && cachep->non_kernel < size) + return 0; + + if (!(gfp & __GFP_DIRECT_RECLAIM)) + cachep->non_kernel-= size; + + pthread_mutex_lock(&cachep->lock); + if (cachep->nr_objs >= size) { + struct radix_tree_node *node = cachep->objs; + for (i = 0; i < size; i++) { + cachep->nr_objs--; + cachep->objs = node->parent; + p[i] = cachep->objs; + } + pthread_mutex_unlock(&cachep->lock); + node->parent = NULL; + } else { + pthread_mutex_unlock(&cachep->lock); + for (i = 0; i < size; i++) { + if (cachep->align) { + posix_memalign(&p[i], cachep->align, + cachep->size * size); + } else { + p[i] = malloc(cachep->size * size); + } + if (cachep->ctor) + cachep->ctor(p[i]); + else if (gfp & __GFP_ZERO) + memset(p[i], 0, cachep->size); + } + } + + for (i = 0; i < size; i++) { + uatomic_inc(&nr_allocated); + uatomic_inc(&nr_tallocated); + if (kmalloc_verbose) + printf("Allocating %p from slab\n", p[i]); + } + + return size; +} + void *kmalloc(size_t size, gfp_t gfp) { diff --git a/tools/testing/radix-tree/linux/slab.h b/tools/testing/radix-tree/linux/slab.h index caef779b30421..42a8f4dd2a63a 100644 --- a/tools/testing/radix-tree/linux/slab.h +++ b/tools/testing/radix-tree/linux/slab.h @@ -24,4 +24,5 @@ struct kmem_cache *kmem_cache_create(const char *name, unsigned int size, unsigned int align, unsigned int flags, void (*ctor)(void *)); void kmem_cache_free_bulk(struct kmem_cache *, size_t, void **); +int kmem_cache_alloc_bulk(struct kmem_cache *, gfp_t, size_t, void **); #endif /* SLAB_H */