Uses kref for struct page
[akaros.git] / kern / arch / sparc / page_alloc.c
index f0afaf0..843a782 100644 (file)
 #include <pmap.h>
 #include <kmalloc.h>
 #include <multiboot.h>
+#include <colored_caches.h>
 
-// llc stands for last-level-cache
-uint16_t llc_num_colors;
-page_list_t *COUNT(llc_num_colors) colored_page_free_list = NULL;
+page_list_t *COUNT(llc_cache->num_colors) colored_page_free_list = NULL;
 spinlock_t colored_page_free_list_lock;
 
-void page_alloc_bootstrap(cache_t* llc) {
-        // Initialize the properties of the last level cache used by this allocator
-        llc_num_colors = get_cache_num_page_colors(llc);
-
+void page_alloc_bootstrap() {
         // Allocate space for the array required to manage the free lists
-        size_t list_size = llc_num_colors*sizeof(page_list_t);
+        size_t list_size = llc_cache->num_colors*sizeof(page_list_t);
         colored_page_free_list = (page_list_t*) boot_alloc(list_size, PGSIZE);
 }
 
@@ -41,17 +37,16 @@ void page_alloc_bootstrap(cache_t* llc) {
  */
 void page_alloc_init() 
 {
-        cache_t* llc = available_caches.llc;
-
         // First Bootstrap the page alloc process
         static bool bootstrapped = FALSE;
         if(!bootstrapped) {
                 bootstrapped = TRUE;
-                page_alloc_bootstrap(llc);
+                page_alloc_bootstrap();
         }
 
-        // Then, initialize the array required to manage the colored page free list
-        for(int i=0; i<llc_num_colors; i++) {
+        // Then, initialize the array required to manage the 
+               // colored page free list
+        for(int i=0; i<llc_cache->num_colors; i++) {
                 LIST_INIT(&(colored_page_free_list[i]));
         }
        
@@ -68,21 +63,21 @@ void page_alloc_init()
        physaddr_t physaddr_after_kernel = PADDR(ROUNDUP(boot_freemem, PGSIZE));
 
        // mark [0, physaddr_after_kernel) as in-use
-       for(i = 0; i < PPN(physaddr_after_kernel); i++)
-               pages[i].page_ref = 1;
+       for(i = 0; i < LA2PPN(physaddr_after_kernel); i++)
+               page_setref(&pages[i], 1);
 
        // mark [physaddr_after_kernel, maxaddrpa) as free
-       for(i = PPN(physaddr_after_kernel); i < PPN(maxaddrpa); i++)
+       for(i = LA2PPN(physaddr_after_kernel); i < LA2PPN(maxaddrpa); i++)
        {
-               pages[i].page_ref = 0;
+               page_setref(&pages[i], 0);
                 LIST_INSERT_HEAD(
-                   &(colored_page_free_list[get_page_color(page2ppn(&pages[i]), llc)]),
+                   &(colored_page_free_list[get_page_color(i,llc_cache)]),
                    &pages[i],
-                   page_link
+                   pg_link
                 );
        }
 
        // mark [maxaddrpa, ...) as in-use (as they are invalid)
-       for(i = PPN(maxaddrpa); i < npages; i++)
-               pages[i].page_ref = 1;
+       for(i = LA2PPN(maxaddrpa); i < npages; i++)
+               page_setref(&pages[i], 1);
 }