From 548ae07696cf726a942dd69349197f0ad81c74b8 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Wed, 4 Dec 2024 15:26:10 -0500 Subject: [PATCH] tools: Add other sheaf functions who knows if they're needed? Signed-off-by: Liam R. Howlett --- tools/include/linux/slab.h | 8 ++++++++ tools/testing/shared/linux.c | 27 ++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/tools/include/linux/slab.h b/tools/include/linux/slab.h index 46ae97e875177..49363a7c7105c 100644 --- a/tools/include/linux/slab.h +++ b/tools/include/linux/slab.h @@ -25,6 +25,7 @@ enum slab_state { struct slab_sheaf { struct kmem_cache *cache; unsigned int size; + bool oversized; void *objects[]; }; @@ -94,5 +95,12 @@ kmem_cache_alloc_from_sheaf(struct kmem_cache *s, gfp_t gfp, void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, struct slab_sheaf *sheaf); +void kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp, + struct slab_sheaf *sheaf, unsigned long more); + +static inline unsigned int kmem_cache_sheaf_count(struct slab_sheaf *sheaf) +{ + return sheaf->size; +} #endif /* _TOOLS_SLAB_H */ diff --git a/tools/testing/shared/linux.c b/tools/testing/shared/linux.c index c2bd723f878ee..88f85c71de245 100644 --- a/tools/testing/shared/linux.c +++ b/tools/testing/shared/linux.c @@ -277,14 +277,15 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int count) { struct slab_sheaf *sheaf; size_t size; + bool oversized = false; if (count > s->sheaf_capacity) { - printf("No support for over-capacity sheaf %u > %u\n", count, - s->sheaf_capacity); - return NULL; + size = sizeof(*sheaf) + sizeof(void *) * count; + oversized = true; + } else { + size = sizeof(*sheaf) + sizeof(void *) * s->sheaf_capacity; } - size = sizeof(*sheaf) + sizeof(void *) * s->sheaf_capacity; sheaf = malloc(size); if (!sheaf) { return NULL; @@ -292,6 +293,7 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int count) memset(sheaf, 0, size); sheaf->cache = s; + sheaf->oversized = oversized; sheaf->size = kmem_cache_alloc_bulk(s, gfp, count, sheaf->objects); if (!sheaf->size) { free(sheaf); @@ -301,11 +303,26 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int count) return sheaf; } +void kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp, + struct slab_sheaf *sheaf, unsigned long more) +{ + unsigned char refill; + + refill = kmem_cache_alloc_bulk(s, gfp, more, + sheaf->objects[sheaf->size - 1]); + if (!refill) + return; + + sheaf->size += refill; +} + void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, struct slab_sheaf *sheaf) { - if (sheaf->size) + if (sheaf->size) { + //s->non_kernel += sheaf->size; kmem_cache_free_bulk(s, sheaf->size, &sheaf->objects[0]); + } free(sheaf); } -- 2.50.1