Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/subr_blist.c
Show First 20 Lines • Show All 289 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* blist_alloc() - reserve space in the block bitmap. Return the base | * blist_alloc() - reserve space in the block bitmap. Return the base | ||||
* of a contiguous region or SWAPBLK_NONE if space could | * of a contiguous region or SWAPBLK_NONE if space could | ||||
* not be allocated. | * not be allocated. | ||||
*/ | */ | ||||
daddr_t | daddr_t | ||||
blist_alloc(blist_t bl, int *count, int maxcount) | blist_alloc(blist_t bl, daddr_t *io_cursor, int *count, int maxcount) | ||||
{ | { | ||||
daddr_t blk, cursor; | daddr_t blk, cursor; | ||||
KASSERT(*count <= maxcount, | KASSERT(*count <= maxcount, | ||||
("invalid parameters %d > %d", *count, maxcount)); | ("invalid parameters %d > %d", *count, maxcount)); | ||||
KASSERT(*count <= BLIST_MAX_ALLOC, | KASSERT(*count <= BLIST_MAX_ALLOC, | ||||
("minimum allocation too large: %d", *count)); | ("minimum allocation too large: %d", *count)); | ||||
/* | /* | ||||
* This loop iterates at most twice. An allocation failure in the | * This loop iterates at most twice. An allocation failure in the | ||||
* first iteration leads to a second iteration only if the cursor was | * first iteration leads to a second iteration only if the cursor was | ||||
* non-zero. When the cursor is zero, an allocation failure will | * non-zero. When the cursor is zero, an allocation failure will | ||||
* stop further iterations. | * stop further iterations. | ||||
*/ | */ | ||||
for (cursor = bl->bl_cursor;; cursor = 0) { | for (cursor = *io_cursor;; cursor = 0) { | ||||
blk = blst_meta_alloc(bl->bl_root, cursor, count, maxcount, | blk = blst_meta_alloc(bl->bl_root, cursor, count, maxcount, | ||||
bl->bl_radix); | bl->bl_radix); | ||||
if (blk != SWAPBLK_NONE) { | if (blk != SWAPBLK_NONE) { | ||||
bl->bl_avail -= *count; | bl->bl_avail -= *count; | ||||
bl->bl_cursor = blk + *count; | *io_cursor = blk + *count; | ||||
if (bl->bl_cursor == bl->bl_blocks) | if (*io_cursor == bl->bl_blocks) | ||||
bl->bl_cursor = 0; | *io_cursor = 0; | ||||
return (blk); | return (blk); | ||||
} | } | ||||
if (cursor == 0) | if (cursor == 0) | ||||
return (SWAPBLK_NONE); | return (SWAPBLK_NONE); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | |||||
#ifdef BLIST_DEBUG | #ifdef BLIST_DEBUG | ||||
/* | /* | ||||
* blist_print() - dump radix tree | * blist_print() - dump radix tree | ||||
*/ | */ | ||||
void | void | ||||
blist_print(blist_t bl) | blist_print(blist_t bl) | ||||
{ | { | ||||
printf("BLIST avail = %jd, cursor = %08jx {\n", | printf("BLIST avail = %jd {\n", (uintmax_t)bl->bl_avail); | ||||
(uintmax_t)bl->bl_avail, (uintmax_t)bl->bl_cursor); | |||||
if (bl->bl_root->bm_bitmap != 0) | if (bl->bl_root->bm_bitmap != 0) | ||||
blst_radix_print(bl->bl_root, 0, bl->bl_radix, 4); | blst_radix_print(bl->bl_root, 0, bl->bl_radix, 4); | ||||
printf("}\n"); | printf("}\n"); | ||||
} | } | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 813 Lines • Show Last 20 Lines |