* 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. */
| 233 | * managing BLIST_RADIX blocks. |
| 234 | */ |
| 235 | blist_t |
| 236 | blist_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 | |
| 273 | void |
| 274 | blist_destroy(blist_t bl) |
no test coverage detected