void init_swap(){ swap_blk = block_get_role(BLOCK_SWAP); ASSERT(swap_blk!=NULL); uint32_t sectors_num = block_size (swap_blk); // each sector is 512K, one page has 8 sectors uint32_t slots_num = sectors_num/8; size_t bm_pages = DIV_ROUND_UP (bitmap_buf_size (slots_num), PGSIZE); uint8_t* base = palloc_get_multiple (PAL_ZERO|PAL_ASSERT, bm_pages); swap_table = bitmap_create_in_buf (slots_num, base, bm_pages * PGSIZE); lock_init(&swap_lock); }
/* Initializes pool P as starting at START and ending at END, naming it NAME for debugging purposes. */ static void init_pool (struct pool *p, void *base, size_t page_cnt, const char *name) { /* We'll put pool's used_map at its base. Calculate the space needed for the bitmap and subtract it from the pool's size. */ size_t bm_pages = DIV_ROUND_UP (bitmap_buf_size (page_cnt), PGSIZE); if (bm_pages > page_cnt) PANIC ("Not enough memory in %s for bitmap.", name); page_cnt -= bm_pages; printf ("%zu pages available in %s.\n", page_cnt, name); /* Initialize the pool. */ lock_init (&p->lock); p->used_map = bitmap_create_in_buf (page_cnt, base, bm_pages * PGSIZE); p->base = base + bm_pages * PGSIZE; }