+static void*
+__alloc_cake_pages(unsigned int cake_pg)
+{
+ struct leaflet* leaflet = alloc_leaflet(count_order(cake_pg));
+ if (!leaflet) {
+ return NULL;
+ }
+
+ return (void*)vmap(leaflet, KERNEL_DATA);
+}
+
+static struct cake_fl*
+__alloc_fl(piece_t prev_id, piece_t max_len) {
+ unsigned int i, j;
+ struct cake_fl* cake_fl;
+
+ cake_fl = cake_grab(&fl_pile);
+ for (i = 0, j=prev_id; i < CAKE_FL_MAXLEN && j < max_len; i++, j++)
+ {
+ cake_fl->indices[i] = j + 1;
+ }
+
+ for (i -= 1; j == max_len && i < CAKE_FL_SIZE; i++) {
+ cake_fl->indices[i] = EO_FREE_PIECE;
+ }
+
+ cake_fl->next = NULL;
+ return cake_fl;
+}
+
+static void
+__free_fls(struct cake_s* cake) {
+ unsigned int i, j;
+ struct cake_fl *cake_fl, *next;
+
+ cake_fl = cake->fl;
+ while (cake_fl)
+ {
+ next = cake_fl->next;
+ cake_release(&fl_pile, cake_fl);
+ cake_fl = next;
+ }
+
+ cake->fl = NULL;
+}
+
+static piece_t*
+__fl_slot(struct cake_s* cake, piece_t index)