slab: Add an arena pointer to the interface
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 1 Nov 2016 21:13:19 +0000 (17:13 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 29 Nov 2016 16:27:40 +0000 (11:27 -0500)
The pointer doesn't do anything yet; that'll come later.

The transformation outside slab files was done with:

@@
expression A;
expression B;
expression C;
expression D;
expression E;
expression F;
@@
-kmem_cache_create(A, B, C, D, E, F)
+kmem_cache_create(A, B, C, D, NULL, E, F)

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
15 files changed:
kern/include/slab.h
kern/src/blockdev.c
kern/src/ext2fs.c
kern/src/frontend.c
kern/src/hashtable.c
kern/src/kfs.c
kern/src/kmalloc.c
kern/src/ktest/pb_ktests.c
kern/src/kthread.c
kern/src/mm.c
kern/src/process.c
kern/src/radix.c
kern/src/slab.c
kern/src/trap.c
kern/src/vfs.c

index 157531c..7f1e7d0 100644 (file)
@@ -33,6 +33,7 @@
 #include <sys/queue.h>
 #include <atomic.h>
 #include <hash_helper.h>
+#include <arena.h>
 
 /* Back in the day, their cutoff for "large objects" was 512B, based on
  * measurements and on not wanting more than 1/8 of internal fragmentation. */
@@ -73,6 +74,7 @@ struct kmem_cache {
        size_t obj_size;
        int align;
        int flags;
+       struct arena *source;
        struct kmem_slab_list full_slab_list;
        struct kmem_slab_list partial_slab_list;
        struct kmem_slab_list empty_slab_list;
@@ -91,6 +93,7 @@ extern struct kmem_cache_list kmem_caches;
 /* Cache management */
 struct kmem_cache *kmem_cache_create(const char *name, size_t obj_size,
                                      int align, int flags,
+                                     struct arena *source,
                                      void (*ctor)(void *, size_t),
                                      void (*dtor)(void *, size_t));
 void kmem_cache_destroy(struct kmem_cache *cp);
@@ -103,6 +106,7 @@ void kmem_cache_reap(struct kmem_cache *cp);
 /* Low-level interface for initializing a cache. */
 void __kmem_cache_create(struct kmem_cache *kc, const char *name,
                          size_t obj_size, int align, int flags,
+                         struct arena *source,
                          void (*ctor)(void *, size_t),
                          void (*dtor)(void *, size_t));
 
index 8b0c672..73c7c60 100644 (file)
@@ -20,10 +20,14 @@ struct kmem_cache *breq_kcache;
 
 void block_init(void)
 {
-       breq_kcache = kmem_cache_create("block_reqs", sizeof(struct block_request),
-                                       __alignof__(struct block_request), 0, 0, 0);
-       bh_kcache = kmem_cache_create("buffer_heads", sizeof(struct buffer_head),
-                                     __alignof__(struct buffer_head), 0, 0, 0);
+       breq_kcache = kmem_cache_create("block_reqs",
+                                       sizeof(struct block_request),
+                                       __alignof__(struct block_request), 0,
+                                       NULL, 0, 0);
+       bh_kcache = kmem_cache_create("buffer_heads",
+                                     sizeof(struct buffer_head),
+                                     __alignof__(struct buffer_head), 0,
+                                     NULL, 0, 0);
 
        #ifdef CONFIG_EXT2FS
        /* Now probe for and init the block device for the ext2 ram disk */
index 5c7476f..75790a2 100644 (file)
@@ -98,8 +98,10 @@ struct kmem_cache *ext2_i_kcache;
 /* One-time init for all ext2 instances */
 void ext2_init(void)
 {
-       ext2_i_kcache = kmem_cache_create("ext2_i_info", sizeof(struct ext2_i_info),
-                                         __alignof__(struct ext2_i_info), 0, 0, 0);
+       ext2_i_kcache = kmem_cache_create("ext2_i_info",
+                                         sizeof(struct ext2_i_info),
+                                         __alignof__(struct ext2_i_info), 0,
+                                         NULL, 0, 0);
 }
 
 /* Block management */
index 6dccae5..5beb3df 100644 (file)
@@ -35,7 +35,8 @@ struct kmem_cache* struct_file_cache;
 void file_init()
 {
        struct_file_cache = kmem_cache_create("struct_file",
-                                             sizeof(struct file), 8, 0, 0, 0);
+                                             sizeof(struct file), 8, 0,
+                                             NULL, 0, 0);
 }
 
 /* will zero anything in the page after the EOF */
index 5f24cc0..9d150ab 100644 (file)
@@ -39,8 +39,10 @@ struct kmem_cache *hentry_cache;
 /* Call this once on bootup, after initializing the slab allocator.  */
 void hashtable_init(void)
 {
-       hentry_cache = kmem_cache_create("hash_entry", sizeof(struct hash_entry),
-                                        __alignof__(struct hash_entry), 0, 0, 0);
+       hentry_cache = kmem_cache_create("hash_entry",
+                                        sizeof(struct hash_entry),
+                                        __alignof__(struct hash_entry), 0,
+                                        NULL, 0, 0);
 }
 
 /* Common hash/equals functions.  Don't call these directly. */
index adb73b6..eb6459a 100644 (file)
@@ -47,8 +47,10 @@ struct kmem_cache *kfs_i_kcache;
 
 static void kfs_init(void)
 {
-       kfs_i_kcache = kmem_cache_create("kfs_ino_info", sizeof(struct kfs_i_info),
-                                        __alignof__(struct kfs_i_info), 0, 0, 0);
+       kfs_i_kcache = kmem_cache_create("kfs_ino_info",
+                                        sizeof(struct kfs_i_info),
+                                        __alignof__(struct kfs_i_info), 0,
+                                        NULL, 0, 0);
 }
 
 /* Creates the SB (normally would read in from disc and create).  Passes its
index 44dfca7..0346d60 100644 (file)
@@ -34,7 +34,8 @@ void kmalloc_init(void)
        size_t ksize = KMALLOC_SMALLEST;
        for (int i = 0; i < NUM_KMALLOC_CACHES; i++) {
                kmalloc_caches[i] = kmem_cache_create("kmalloc_cache", ksize,
-                                                     KMALLOC_ALIGNMENT, 0, 0, 0);
+                                                     KMALLOC_ALIGNMENT, 0,
+                                                     NULL, 0, 0);
                ksize <<= 1;
        }
 }
index 35146c3..3be4a78 100644 (file)
@@ -574,7 +574,8 @@ static void test_single_cache(int iters, size_t size, int align, int flags,
 {
        struct kmem_cache *test_cache;
        void *objects[iters];
-       test_cache = kmem_cache_create("test_cache", size, align, flags, ctor, dtor);
+       test_cache = kmem_cache_create("test_cache", size, align, flags,
+                                      NULL, ctor, dtor);
        printk("Testing Kmem Cache:\n");
        print_kmem_cache(test_cache);
        for (int i = 0; i < iters; i++) {
index b8ba447..e5c9422 100644 (file)
@@ -46,7 +46,8 @@ struct kmem_cache *kthread_kcache;
 void kthread_init(void)
 {
        kthread_kcache = kmem_cache_create("kthread", sizeof(struct kthread),
-                                          __alignof__(struct kthread), 0, 0, 0);
+                                          __alignof__(struct kthread), 0,
+                                          NULL, 0, 0);
 }
 
 /* Used by early init routines (smp_boot, etc) */
index 0bef158..45f4839 100644 (file)
@@ -43,8 +43,10 @@ static struct page_map *file2pm(struct file *file)
 
 void vmr_init(void)
 {
-       vmr_kcache = kmem_cache_create("vm_regions", sizeof(struct vm_region),
-                                      __alignof__(struct dentry), 0, 0, 0);
+       vmr_kcache = kmem_cache_create("vm_regions",
+                                      sizeof(struct vm_region),
+                                      __alignof__(struct dentry), 0, NULL,
+                                      0, 0);
 }
 
 /* For now, the caller will set the prot, flags, file, and offset.  In the
index 09f9682..6e5cd17 100644 (file)
@@ -245,7 +245,9 @@ void proc_init(void)
        /* Catch issues with the vcoremap and TAILQ_ENTRY sizes */
        static_assert(sizeof(TAILQ_ENTRY(vcore)) == sizeof(void*) * 2);
        proc_cache = kmem_cache_create("proc", sizeof(struct proc),
-                    MAX(ARCH_CL_SIZE, __alignof__(struct proc)), 0, 0, 0);
+                                      MAX(ARCH_CL_SIZE,
+                                      __alignof__(struct proc)), 0, NULL, 0,
+                                      0);
        /* Init PID mask and hash.  pid 0 is reserved. */
        SET_BITMASK_BIT(pid_bmask, 0);
        spinlock_init(&pid_hash_lock);
index 6fe6d1d..e26e7a8 100644 (file)
@@ -19,8 +19,10 @@ static void __radix_remove_slot(struct radix_node *r_node, struct radix_node **s
 /* Initializes the radix tree system, mostly just builds the kcache */
 void radix_init(void)
 {
-       radix_kcache = kmem_cache_create("radix_nodes", sizeof(struct radix_node),
-                                        __alignof__(struct radix_node), 0, 0, 0);
+       radix_kcache = kmem_cache_create("radix_nodes",
+                                        sizeof(struct radix_node),
+                                        __alignof__(struct radix_node), 0,
+                                        NULL, 0, 0);
 }
 
 /* Initializes a tree dynamically */
index 1afe157..e458176 100644 (file)
@@ -29,6 +29,7 @@ struct kmem_cache kmem_bufctl_cache[1];
 
 void __kmem_cache_create(struct kmem_cache *kc, const char *name,
                          size_t obj_size, int align, int flags,
+                         struct arena *source,
                          void (*ctor)(void *, size_t),
                          void (*dtor)(void *, size_t))
 {
@@ -39,6 +40,7 @@ void __kmem_cache_create(struct kmem_cache *kc, const char *name,
        kc->obj_size = obj_size;
        kc->align = align;
        kc->flags = flags;
+       kc->source = source;
        TAILQ_INIT(&kc->full_slab_list);
        TAILQ_INIT(&kc->partial_slab_list);
        TAILQ_INIT(&kc->empty_slab_list);
@@ -72,23 +74,27 @@ void kmem_cache_init(void)
        SLIST_INIT(&kmem_caches);
        __kmem_cache_create(kmem_cache_cache, "kmem_cache",
                            sizeof(struct kmem_cache),
-                           __alignof__(struct kmem_cache), 0, NULL, NULL);
+                           __alignof__(struct kmem_cache), 0, base_arena,
+                           NULL, NULL);
        __kmem_cache_create(kmem_slab_cache, "kmem_slab",
                            sizeof(struct kmem_slab),
-                           __alignof__(struct kmem_slab), 0, NULL, NULL);
+                           __alignof__(struct kmem_slab), 0, base_arena,
+                           NULL, NULL);
        __kmem_cache_create(kmem_bufctl_cache, "kmem_bufctl",
                            sizeof(struct kmem_bufctl),
-                           __alignof__(struct kmem_bufctl), 0, NULL, NULL);
+                           __alignof__(struct kmem_bufctl), 0, base_arena,
+                           NULL, NULL);
 }
 
 /* Cache management */
 struct kmem_cache *kmem_cache_create(const char *name, size_t obj_size,
                                      int align, int flags,
+                                     struct arena *source,
                                      void (*ctor)(void *, size_t),
                                      void (*dtor)(void *, size_t))
 {
        struct kmem_cache *kc = kmem_cache_alloc(kmem_cache_cache, 0);
-       __kmem_cache_create(kc, name, obj_size, align, flags, ctor, dtor);
+       __kmem_cache_create(kc, name, obj_size, align, flags, source, ctor, dtor);
        return kc;
 }
 
index 4a6f494..41e1155 100644 (file)
@@ -110,7 +110,8 @@ struct kmem_cache *kernel_msg_cache;
 void kernel_msg_init(void)
 {
        kernel_msg_cache = kmem_cache_create("kernel_msgs",
-                          sizeof(struct kernel_message), ARCH_CL_SIZE, 0, 0, 0);
+                                            sizeof(struct kernel_message),
+                                            ARCH_CL_SIZE, 0, NULL, 0, 0);
 }
 
 uint32_t send_kernel_message(uint32_t dst, amr_t pc, long arg0, long arg1,
index 5005d38..1f21e29 100644 (file)
@@ -88,11 +88,14 @@ void vfs_init(void)
        struct fs_type *fs;
 
        dentry_kcache = kmem_cache_create("dentry", sizeof(struct dentry),
-                                         __alignof__(struct dentry), 0, 0, 0);
+                                         __alignof__(struct dentry), 0,
+                                         NULL, 0, 0);
        inode_kcache = kmem_cache_create("inode", sizeof(struct inode),
-                                        __alignof__(struct inode), 0, 0, 0);
+                                        __alignof__(struct inode), 0, NULL,
+                                        0, 0);
        file_kcache = kmem_cache_create("file", sizeof(struct file),
-                                       __alignof__(struct file), 0, 0, 0);
+                                       __alignof__(struct file), 0, NULL, 0,
+                                       0);
        /* default NS never dies, +1 to exist */
        kref_init(&default_ns.kref, fake_release, 1);
        spinlock_init(&default_ns.lock);