]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
tools: Add other sheaf functions
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 4 Dec 2024 20:26:10 +0000 (15:26 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 4 Dec 2024 20:26:10 +0000 (15:26 -0500)
who knows if they're needed?

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
tools/include/linux/slab.h
tools/testing/shared/linux.c

index 46ae97e875177aef901876a7669a3814e590ee37..49363a7c7105c97113fab64a4b6517b644dd9d61 100644 (file)
@@ -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 */
index c2bd723f878ee047def496d1a50155ed60c6eb8c..88f85c71de245529934f3392c9672eae18dd2340 100644 (file)
@@ -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);
 }