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

Function blist_create

freebsd/kern/subr_blist.c:235–271  ·  view source on GitHub ↗

* blist_create() - create a blist capable of handling up to the specified * number of blocks * * blocks - must be greater than 0 * flags - malloc flags * * The smallest blist consists of a single leaf node capable of * managing BLIST_RADIX blocks. */

Source from the content-addressed store, hash-verified

233 * managing BLIST_RADIX blocks.
234 */
235blist_t
236blist_create(daddr_t blocks, int flags)
237{
238 blist_t bl;
239 u_daddr_t nodes, radix;
240
241 KASSERT(blocks > 0, ("invalid block count"));
242
243 /*
244 * Calculate the radix and node count used for scanning.
245 */
246 nodes = 1;
247 for (radix = 1; radix <= blocks / BLIST_RADIX; radix *= BLIST_RADIX)
248 nodes += 1 + (blocks - 1) / radix / BLIST_RADIX;
249
250 bl = malloc(offsetof(struct blist, bl_root[nodes]), M_SWAP, flags |
251 M_ZERO);
252 if (bl == NULL)
253 return (NULL);
254
255 bl->bl_blocks = blocks;
256 bl->bl_radix = radix;
257
258#if defined(BLIST_DEBUG)
259 printf(
260 "BLIST representing %lld blocks (%lld MB of swap)"
261 ", requiring %lldK of ram\n",
262 (long long)bl->bl_blocks,
263 (long long)bl->bl_blocks * 4 / 1024,
264 (long long)(nodes * sizeof(blmeta_t) + 1023) / 1024
265 );
266 printf("BLIST raw radix tree contains %lld records\n",
267 (long long)nodes);
268#endif
269
270 return (bl);
271}
272
273void
274blist_destroy(blist_t bl)

Callers 3

blist_resizeFunction · 0.85
mainFunction · 0.85
swaponsomethingFunction · 0.85

Calls 2

mallocFunction · 0.85
printfFunction · 0.70

Tested by

no test coverage detected