Skip to contentSkip to conversation

Slab cache bulk alloc/free

PATCH New Momchil Velikov 1 participant 1 message Dec 5, 2001

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Slab cache bulk alloc/free

Hi there,

This patch adds two new functions

    int kmem_cache_alloc_bulk (kmem_cache_t *, int, unsigned int, void **);
    void kmem_cache_free_bulk (kmem_cache_t *, unsigned int, void **);

to slab.c, which provide for allocation/deallocation of several objects at once. These functions can speed up allocation in cases where it is know in advance that several objects will be allocated, or to preallocate several objects for later use, when an allocation would be impossible, e.g. with spin lock held.

BTW, the latter is the case with the (hopefully) upcoming page cache patch, which uses per-mapping radix trees, which need allocation during insertion and the maximum possible number of allocations is known at compile time and that number is small, say, 3 - 7.

Regards,
-velco

include/linux/slab.h +2 -0
diff -Nru a/include/linux/slab.h b/include/linux/slab.h
@@ -56,7 +56,9 @@
 extern int kmem_cache_destroy(kmem_cache_t *);
 extern int kmem_cache_shrink(kmem_cache_t *);
 extern void *kmem_cache_alloc(kmem_cache_t *, int);
+extern int kmem_cache_alloc_bulk (kmem_cache_t *, int, unsigned int, void **);
 extern void kmem_cache_free(kmem_cache_t *, void *);
+extern void kmem_cache_free_bulk (kmem_cache_t *, unsigned int, void **);
 
 extern void *kmalloc(size_t, int);
 extern void kfree(const void *);
mm/slab.c +133 -28

258 lines not on this page · raw message