Allocate and remove memcache. master
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Wed, 9 Dec 2009 10:47:40 +0000 (08:47 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Wed, 9 Dec 2009 10:47:40 +0000 (08:47 -0200)
Makefile [new file with mode: 0644]
memcache.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..310c723
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+ifneq ($(KERNELRELEASE),)
+       obj-m := memcache.o
+else
+       KERNELDIR ?= /lib/modules/$(shell uname -r)/build
+       PWD := $(shell pwd)
+default:
+       $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
+
+clean:
+       $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
+endif
diff --git a/memcache.c b/memcache.c
new file mode 100644 (file)
index 0000000..f4504eb
--- /dev/null
@@ -0,0 +1,23 @@
+#include <linux/module.h>
+#include <linux/slab.h>
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>");
+
+static struct kmem_cache *memcache;
+
+static int memcache_init(void)
+{
+       memcache = kmem_cache_create("memcache", 32, 0, 0, NULL);
+       if (!memcache)
+               return -ENOMEM;
+       return 0;
+}
+
+static void memcache_exit(void)
+{
+       kmem_cache_destroy(memcache);
+}
+
+module_init(memcache_init);
+module_exit(memcache_exit);