FreeBSD/sys/kern/subr_blist.c
/*
 * 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_BMAP_RADIX blocks.
 */
create a blist capable of handling up to the specified
number of blocks

must be greater than 0
flags  - malloc flags

The smallest blist consists of a single leaf node capable of
managing BLIST_BMAP_RADIX blocks.
create a blist capable of handling up to the specified number of blocks must be greater than 0 flags - malloc flags The smallest blist consists of a single leaf node capable of managing BLIST_BMAP_RADIX blocks .
blist_t 
blist_create(daddr_t blocks, int flags)
{
	blist_t bl;
	int radix;
	int skip = 0;
	radix = BLIST_BMAP_RADIX;
	while (radix < blocks) {
		radix *= BLIST_META_RADIX;
		skip = (skip + 1) * BLIST_META_RADIX;
	}
	bl = malloc(sizeof(struct blist), M_SWAP, flags | M_ZERO);
	bl->bl_blocks = blocks;
	bl->bl_radix = radix;
	bl->bl_skip = skip;
	bl->bl_rootblks = 1 +
	    blst_radix_init(NULL, bl->bl_radix, bl->bl_skip, blocks);
	bl->bl_root = malloc(sizeof(blmeta_t) * bl->bl_rootblks, M_SWAP, flags);
#if defined(BLIST_DEBUG)
	printf(
		"BLIST representing %lld blocks (%lld MB of swap)"
		", requiring %lldK of ram\n",
		(long long)bl->bl_blocks,
		(long long)bl->bl_blocks * 4 / 1024,
		(long long)(bl->bl_rootblks * sizeof(blmeta_t) + 1023) / 1024
	);
	printf("BLIST raw radix tree contains %lld records\n",
	    (long long)bl->bl_rootblks);
#endif
	blst_radix_init(bl->bl_root, bl->bl_radix, bl->bl_skip, blocks);
	return(bl);
}
blist_t blist_create ( daddr_t blocks , int flags ) { blist_t bl ; int radix ; int skip = 0 ; radix = BLIST_BMAP_RADIX ; while ( radix < blocks ) { radix *= BLIST_META_RADIX ; skip = ( skip + 1 ) * BLIST_META_RADIX ; } bl = malloc ( sizeof ( struct blist ) , M_SWAP , flags | M_ZERO ) ; bl -> bl_blocks = blocks ; bl -> bl_radix = radix ; bl -> bl_skip = skip ; bl -> bl_rootblks = 1 + blst_radix_init ( NULL , bl -> bl_radix , bl -> bl_skip , blocks ) ; bl -> bl_root = malloc ( sizeof ( blmeta_t ) * bl -> bl_rootblks , M_SWAP , flags ) ; #if defined ( BLIST_DEBUG ) printf ( " " " \n " , ( long long ) bl -> bl_blocks , ( long long ) bl -> bl_blocks * 4 / 1024 , ( long long ) ( bl -> bl_rootblks * sizeof ( blmeta_t ) + 1023 ) / 1024 ) ; printf ( " \n " , ( long long ) bl -> bl_rootblks ) ; #endif blst_radix_init ( bl -> bl_root , bl -> bl_radix , bl -> bl_skip , blocks ) ; return ( bl ) ; }
blist_create() - create a blist capable of handling up to the specified
                  number of blocks
blist_create () - create a blist capable of handling up to the specified number of blocks
/*
	 * Calculate radix and skip field used for scanning.
	 */