MCPcopy Create free account
hub / github.com/F-Stack/f-stack / blist_alloc

Function blist_alloc

freebsd/kern/subr_blist.c:285–314  ·  view source on GitHub ↗

* blist_alloc() - reserve space in the block bitmap. Return the base * of a contiguous region or SWAPBLK_NONE if space could * not be allocated. */

Source from the content-addressed store, hash-verified

283 * not be allocated.
284 */
285daddr_t
286blist_alloc(blist_t bl, int *count, int maxcount)
287{
288 daddr_t blk, cursor;
289
290 KASSERT(*count <= maxcount,
291 ("invalid parameters %d > %d", *count, maxcount));
292 KASSERT(*count <= BLIST_MAX_ALLOC,
293 ("minimum allocation too large: %d", *count));
294
295 /*
296 * This loop iterates at most twice. An allocation failure in the
297 * first iteration leads to a second iteration only if the cursor was
298 * non-zero. When the cursor is zero, an allocation failure will
299 * stop further iterations.
300 */
301 for (cursor = bl->bl_cursor;; cursor = 0) {
302 blk = blst_meta_alloc(bl->bl_root, cursor, count, maxcount,
303 bl->bl_radix);
304 if (blk != SWAPBLK_NONE) {
305 bl->bl_avail -= *count;
306 bl->bl_cursor = blk + *count;
307 if (bl->bl_cursor == bl->bl_blocks)
308 bl->bl_cursor = 0;
309 return (blk);
310 }
311 if (cursor == 0)
312 return (SWAPBLK_NONE);
313 }
314}
315
316/*
317 * blist_avail() - return the number of free blocks.

Callers 2

mainFunction · 0.85
swp_pager_getswapspaceFunction · 0.85

Calls 1

blst_meta_allocFunction · 0.85

Tested by

no test coverage detected