_M procs start up at _start/hart_entry for vcore0
[akaros.git] / kern / src / page_alloc.c
index f6a43c2..6531c3a 100644 (file)
@@ -27,13 +27,14 @@ static error_t __page_free(page_t *CT(1) page);
 
 // Global list of colors allocated to the general purpose memory allocator
 uint8_t* global_cache_colors_map;
+size_t global_next_color = 0;
 
 void colored_page_alloc_init()
 {
        global_cache_colors_map = 
               kmalloc(BYTES_FOR_BITMASK(llc_cache->num_colors), 0);
        CLR_BITMASK(global_cache_colors_map, llc_cache->num_colors);
-       for(int i = 0; i < llc_cache->num_colors/2; i++)
+       for(int i = 0; i < llc_cache->num_colors/8; i++)
                cache_color_alloc(llc_cache, global_cache_colors_map);
 }
 
@@ -114,6 +115,7 @@ static error_t __page_alloc_specific(page_t** page, size_t ppn)
  * @return ESUCCESS on success
  * @return -ENOMEM  otherwise
  */
+#ifdef __CONFIG_PAGE_COLORING__
 error_t upage_alloc(struct proc* p, page_t** page, int zero)
 {
        spin_lock_irqsave(&colored_page_free_list_lock);
@@ -130,18 +132,37 @@ error_t upage_alloc(struct proc* p, page_t** page, int zero)
        }
        return ret;
 }
+#else 
+error_t upage_alloc(struct proc* p, page_t** page, int zero)
+{
+       ssize_t ret;
+       spin_lock_irqsave(&colored_page_free_list_lock);
+       if((ret = __page_alloc_from_color_range(page, global_next_color, 
+                                   llc_cache->num_colors - global_next_color)) < 0)
+               ret = __page_alloc_from_color_range(page, 0, global_next_color);
+
+       if(ret >= 0) {
+               if(zero)
+                       memset(page2kva(*page),0,PGSIZE);
+               global_next_color = ret;        
+               ret = ESUCCESS;
+       }
+       spin_unlock_irqsave(&colored_page_free_list_lock);
+       
+       return ret;
+}
+#endif
 
 error_t kpage_alloc(page_t** page) 
 {
-       static size_t next_color = 0;
        ssize_t ret;
        spin_lock_irqsave(&colored_page_free_list_lock);
-       if((ret = __page_alloc_from_color_range(page, next_color, 
-                                   llc_cache->num_colors)) < 0)
-               ret = __page_alloc_from_color_range(page, 0, next_color);
+       if((ret = __page_alloc_from_color_range(page, global_next_color, 
+                                   llc_cache->num_colors - global_next_color)) < 0)
+               ret = __page_alloc_from_color_range(page, 0, global_next_color);
 
        if(ret >= 0) {
-               next_color = ret;        
+               global_next_color = ret;        
                page_incref(*page);
                ret = ESUCCESS;
        }
@@ -264,7 +285,7 @@ error_t page_free(page_t *SAFE page)
 }
 
 /*
- * Check if a page with the given pyhysical page # is free
+ * Check if a page with the given physical page # is free
  */
 int page_is_free(size_t ppn) {
        page_t* page = ppn2page(ppn);