slab: Bootstrap before setting up kpages_arena
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 2 Nov 2016 22:05:23 +0000 (18:05 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 29 Nov 2016 16:27:40 +0000 (11:27 -0500)
Kpages will use kmem_cache, so we should at least run the init function
first.  While we're at it, we can statically initialize the lock and list.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/src/init.c
kern/src/pmap.c
kern/src/slab.c

index b1fe12f..50bb32a 100644 (file)
@@ -141,7 +141,6 @@ void kernel_init(multiboot_info_t *mboot_info)
        exception_table_init();
        num_cores = get_early_num_cores();
        pmem_init(multiboot_kaddr);
-       kmem_cache_init();              // Sets up slab allocator
        kmalloc_init();
        hashtable_init();
        radix_init();
index cbb6c86..3e92489 100644 (file)
@@ -85,6 +85,9 @@ void pmem_init(struct multiboot_info *mbi)
        pages = (struct page*)boot_zalloc(max_nr_pages * sizeof(struct page),
                                          PGSIZE);
        base_arena_init(mbi);
+       /* kpages will use some of the basic slab caches.  kmem_cache_init needs to
+        * not do memory allocations (which it doesn't, and it can base_alloc()). */
+       kmem_cache_init();
        kpages_arena_init();
        printk("Base arena total mem: %lu\n", arena_amt_total(base_arena));
        vm_init();
index ee8288d..a91e9c4 100644 (file)
@@ -15,8 +15,8 @@
 #include <hash.h>
 #include <arena.h>
 
-struct kmem_cache_list kmem_caches;
-spinlock_t kmem_caches_lock;
+struct kmem_cache_list kmem_caches = SLIST_HEAD_INITIALIZER(kmem_caches);
+spinlock_t kmem_caches_lock = SPINLOCK_INITIALIZER_IRQSAVE;
 
 /* Backend/internal functions, defined later.  Grab the lock before calling
  * these. */
@@ -89,8 +89,6 @@ void __kmem_cache_create(struct kmem_cache *kc, const char *name,
 
 void kmem_cache_init(void)
 {
-       spinlock_init_irqsave(&kmem_caches_lock);
-       SLIST_INIT(&kmem_caches);
        __kmem_cache_create(kmem_cache_cache, "kmem_cache",
                            sizeof(struct kmem_cache),
                            __alignof__(struct kmem_cache), 0, base_arena,