Skip to contentSkip to conversation

sys_indirect RFC - fast sequential allocator

PATCH In review Davide Libenzi 1 participant 1 message Jun 29, 2007 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 sys_indirect RFC - fast sequential allocator

This file implements a fast, sequential allocator. Chunks of memory are allocated in blocks of pages, and inside these blocks memory is allocated is a sequential fashion. All the allocated memory is released in one single sweep by freeing the backing pages. Indeed, there is not an fsa_free() function to deallocate a single block. The user can provide an initial allocation backing store, if needed, to avoid the alocator to call page allocation functions for the first "in cache" allocations. The FSA allocator provides no locking, so it is up to the caller serialize fsa_alloc() calls if ever needed.

- Davide

---
 include/linux/fsalloc.h |   34 ++++++++++++++++
 lib/Makefile            |    2 
 lib/fsalloc.c           |  102 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 137 insertions(+), 1 deletion(-)
lib/Makefile +1 -1
Index: linux-2.6.mod/lib/Makefile
===================================================================
@@ -5,7 +5,7 @@
 lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 rbtree.o radix-tree.o dump_stack.o \
 	 idr.o int_sqrt.o bitmap.o extable.o prio_tree.o \
-	 sha1.o irq_regs.o reciprocal_div.o
+	 sha1.o irq_regs.o reciprocal_div.o fsalloc.o
 
 lib-$(CONFIG_MMU) += ioremap.o
 lib-$(CONFIG_SMP) += cpumask.o
include/linux/fsalloc.h new file +34 -0
Index: linux-2.6.mod/include/linux/fsalloc.h
===================================================================
@@ -0,0 +1,34 @@
+/*
+ *  include/linux/fsalloc.h
+ *
+ *  Copyright (C) 2007  Davide Libenzi <[email protected]>
+ *
+ */
+
+#ifndef _LINUX_FSALLOC_H
+#define _LINUX_FSALLOC_H
+
+#ifdef __KERNEL__
+
+struct fsa_page {
+	struct fsa_page *next;
+	int order;
+	unsigned long avail;
+	void *data;
+};
+
+struct fsa_context {
+	struct fsa_page *first, *curr;
+	struct fsa_page cached;
+	int order;
+};
+
+void fsa_init(struct fsa_context *ator, void *buffer,
+	      unsigned long csize);
+void fsa_cleanup(struct fsa_context *ator);
+void *fsa_alloc(struct fsa_context *ator, unsigned long size);
+
+#endif /* __KERNEL__ */
+
+#endif /* _LINUX_FSALLOC_H */
+
lib/fsalloc.c new file +102 -0

102 lines not on this page · raw message