- size_t bitmap_size;
- size_t page_cnt;
-
- ASSERT (pg_ofs (start) == 0);
- ASSERT (pg_ofs (end) == 0);
- ASSERT (end > start);
-
- page_cnt = pg_no (end) - pg_no (start);
- printf ("%d kB allocated for %s.\n", (PGSIZE / 1024) * page_cnt, name);
-
- lock_init (&p->lock, name);
- bitmap_size = ROUND_UP (bitmap_needed_bytes (page_cnt), PGSIZE);
- p->used_map = bitmap_create_preallocated (page_cnt, start, bitmap_size);
- p->start = start + bitmap_size;
- p->end = end;
- ASSERT (p->end > p->start);
+ /* We'll put the 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;