2 * Copyright (c) 1998 Matthew Dillon. All Rights Reserved.
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions
6 * 1. Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * 2. Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * 4. Neither the name of the University nor the names of its contributors
12 * may be used to endorse or promote products derived from this software
13 * without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * BLIST.C - Bitmap allocator/deallocator, using a radix tree with hinting
30 * This module implements a general bitmap allocator/deallocator. The
31 * allocator eats around 2 bits per 'block'. The module does not
32 * try to interpret the meaning of a 'block' other then to return
33 * SWAPBLK_NONE on an allocation failure.
35 * A radix tree is used to maintain the bitmap. Two radix constants are
36 * involved: One for the bitmaps contained in the leaf nodes (typically
37 * 32), and one for the meta nodes (typically 16). Both meta and leaf
38 * nodes have a hint field. This field gives us a hint as to the largest
39 * free contiguous range of blocks under the node. It may contain a
40 * value that is too high, but will never contain a value that is too
41 * low. When the radix tree is searched, allocation failures in subtrees
44 * The radix tree also implements two collapsed states for meta nodes:
45 * the ALL-ALLOCATED state and the ALL-FREE state. If a meta node is
46 * in either of these two states, all information contained underneath
47 * the node is considered stale. These states are used to optimize
48 * allocation and freeing operations.
50 * The hinting greatly increases code efficiency for allocations while
51 * the general radix structure optimizes both allocations and frees. The
52 * radix tree should be able to operate well no matter how much
53 * fragmentation there is and no matter how large a bitmap is used.
55 * Unlike the rlist code, the blist code wires all necessary memory at
56 * creation time. Neither allocations nor frees require interaction with
57 * the memory subsystem. In contrast, the rlist code may allocate memory
58 * on an rlist_free() call. The non-blocking features of the blist code
59 * are used to great advantage in the swap code (vm/nswap_pager.c). The
60 * rlist code uses a little less overall memory then the blist code (but
61 * due to swap interleaving not all that much less), but the blist code
62 * scales much, much better.
64 * LAYOUT: The radix tree is layed out recursively using a
65 * linear array. Each meta node is immediately followed (layed out
66 * sequentially in memory) by BLIST_META_RADIX lower level nodes. This
67 * is a recursive structure but one that can be easily scanned through
68 * a very simple 'skip' calculation. In order to support large radixes,
69 * portions of the tree may reside outside our memory allocation. We
70 * handle this with an early-termination optimization (when bighint is
71 * set to -1) on the scan. The memory allocation is only large enough
72 * to cover the number of blocks requested at creation time even if it
73 * must be encompassed in larger root-node radix.
75 * NOTE: the allocator cannot currently allocate more then
76 * BLIST_BMAP_RADIX blocks per call. It will panic with 'allocation too
77 * large' if you try. This is an area that could use improvement. The
78 * radix is large enough that this restriction does not effect the swap
79 * system, though. Currently only the allocation code is effected by
80 * this algorithmic unfeature. The freeing code can handle arbitrary
83 * This code can be compiled stand-alone for debugging.
86 #include <sys/cdefs.h>
87 __FBSDID("$FreeBSD$");
91 #include <sys/param.h>
92 #include <sys/systm.h>
94 #include <sys/kernel.h>
95 #include <sys/blist.h>
96 #include <sys/malloc.h>
98 #include <sys/mutex.h>
102 #ifndef BLIST_NO_DEBUG
106 #define SWAPBLK_NONE ((daddr_t)-1)
108 #include <sys/types.h>
114 #define malloc(a,b,c) calloc(a, 1)
115 #define free(a,b) free(a)
117 typedef unsigned int u_daddr_t
;
119 #include <sys/blist.h>
121 void panic(const char *ctl
, ...);
126 * static support functions
129 static daddr_t
blst_leaf_alloc(blmeta_t
*scan
, daddr_t blk
, int count
);
130 static daddr_t
blst_meta_alloc(blmeta_t
*scan
, daddr_t blk
,
131 daddr_t count
, daddr_t radix
, int skip
);
132 static void blst_leaf_free(blmeta_t
*scan
, daddr_t relblk
, int count
);
133 static void blst_meta_free(blmeta_t
*scan
, daddr_t freeBlk
, daddr_t count
,
134 daddr_t radix
, int skip
, daddr_t blk
);
135 static void blst_copy(blmeta_t
*scan
, daddr_t blk
, daddr_t radix
,
136 daddr_t skip
, blist_t dest
, daddr_t count
);
137 static int blst_leaf_fill(blmeta_t
*scan
, daddr_t blk
, int count
);
138 static int blst_meta_fill(blmeta_t
*scan
, daddr_t allocBlk
, daddr_t count
,
139 daddr_t radix
, int skip
, daddr_t blk
);
140 static daddr_t
blst_radix_init(blmeta_t
*scan
, daddr_t radix
,
141 int skip
, daddr_t count
);
143 static void blst_radix_print(blmeta_t
*scan
, daddr_t blk
,
144 daddr_t radix
, int skip
, int tab
);
148 static MALLOC_DEFINE(M_SWAP
, "SWAP", "Swap space");
152 * blist_create() - create a blist capable of handling up to the specified
155 * blocks - must be greater then 0
156 * flags - malloc flags
158 * The smallest blist consists of a single leaf node capable of
159 * managing BLIST_BMAP_RADIX blocks.
163 blist_create(daddr_t blocks
, int flags
)
170 * Calculate radix and skip field used for scanning.
172 radix
= BLIST_BMAP_RADIX
;
174 while (radix
< blocks
) {
175 radix
*= BLIST_META_RADIX
;
176 skip
= (skip
+ 1) * BLIST_META_RADIX
;
179 bl
= malloc(sizeof(struct blist
), M_SWAP
, flags
| M_ZERO
);
181 bl
->bl_blocks
= blocks
;
182 bl
->bl_radix
= radix
;
184 bl
->bl_rootblks
= 1 +
185 blst_radix_init(NULL
, bl
->bl_radix
, bl
->bl_skip
, blocks
);
186 bl
->bl_root
= malloc(sizeof(blmeta_t
) * bl
->bl_rootblks
, M_SWAP
, flags
);
188 #if defined(BLIST_DEBUG)
190 "BLIST representing %lld blocks (%lld MB of swap)"
191 ", requiring %lldK of ram\n",
192 (long long)bl
->bl_blocks
,
193 (long long)bl
->bl_blocks
* 4 / 1024,
194 (long long)(bl
->bl_rootblks
* sizeof(blmeta_t
) + 1023) / 1024
196 printf("BLIST raw radix tree contains %lld records\n",
197 (long long)bl
->bl_rootblks
);
199 blst_radix_init(bl
->bl_root
, bl
->bl_radix
, bl
->bl_skip
, blocks
);
205 blist_destroy(blist_t bl
)
207 free(bl
->bl_root
, M_SWAP
);
212 * blist_alloc() - reserve space in the block bitmap. Return the base
213 * of a contiguous region or SWAPBLK_NONE if space could
218 blist_alloc(blist_t bl
, daddr_t count
)
220 daddr_t blk
= SWAPBLK_NONE
;
223 if (bl
->bl_radix
== BLIST_BMAP_RADIX
)
224 blk
= blst_leaf_alloc(bl
->bl_root
, 0, count
);
226 blk
= blst_meta_alloc(bl
->bl_root
, 0, count
, bl
->bl_radix
, bl
->bl_skip
);
227 if (blk
!= SWAPBLK_NONE
)
228 bl
->bl_free
-= count
;
234 * blist_free() - free up space in the block bitmap. Return the base
235 * of a contiguous region. Panic if an inconsistancy is
240 blist_free(blist_t bl
, daddr_t blkno
, daddr_t count
)
243 if (bl
->bl_radix
== BLIST_BMAP_RADIX
)
244 blst_leaf_free(bl
->bl_root
, blkno
, count
);
246 blst_meta_free(bl
->bl_root
, blkno
, count
, bl
->bl_radix
, bl
->bl_skip
, 0);
247 bl
->bl_free
+= count
;
252 * blist_fill() - mark a region in the block bitmap as off-limits
253 * to the allocator (i.e. allocate it), ignoring any
254 * existing allocations. Return the number of blocks
255 * actually filled that were free before the call.
259 blist_fill(blist_t bl
, daddr_t blkno
, daddr_t count
)
264 if (bl
->bl_radix
== BLIST_BMAP_RADIX
)
265 filled
= blst_leaf_fill(bl
->bl_root
, blkno
, count
);
267 filled
= blst_meta_fill(bl
->bl_root
, blkno
, count
,
268 bl
->bl_radix
, bl
->bl_skip
, 0);
269 bl
->bl_free
-= filled
;
276 * blist_resize() - resize an existing radix tree to handle the
277 * specified number of blocks. This will reallocate
278 * the tree and transfer the previous bitmap to the new
279 * one. When extending the tree you can specify whether
280 * the new blocks are to left allocated or freed.
284 blist_resize(blist_t
*pbl
, daddr_t count
, int freenew
, int flags
)
286 blist_t newbl
= blist_create(count
, flags
);
290 if (count
> save
->bl_blocks
)
291 count
= save
->bl_blocks
;
292 blst_copy(save
->bl_root
, 0, save
->bl_radix
, save
->bl_skip
, newbl
, count
);
295 * If resizing upwards, should we free the new space or not?
297 if (freenew
&& count
< newbl
->bl_blocks
) {
298 blist_free(newbl
, count
, newbl
->bl_blocks
- count
);
306 * blist_print() - dump radix tree
310 blist_print(blist_t bl
)
313 blst_radix_print(bl
->bl_root
, 0, bl
->bl_radix
, bl
->bl_skip
, 4);
319 /************************************************************************
320 * ALLOCATION SUPPORT FUNCTIONS *
321 ************************************************************************
323 * These support functions do all the actual work. They may seem
324 * rather longish, but that's because I've commented them up. The
325 * actual code is straight forward.
330 * blist_leaf_alloc() - allocate at a leaf in the radix tree (a bitmap).
332 * This is the core of the allocator and is optimized for the 1 block
333 * and the BLIST_BMAP_RADIX block allocation cases. Other cases are
334 * somewhat slower. The 1 block allocation case is log2 and extremely
344 u_daddr_t orig
= scan
->u
.bmu_bitmap
;
348 * Optimize bitmap all-allocated case. Also, count = 1
349 * case assumes at least 1 bit is free in the bitmap, so
350 * we have to take care of this case here.
352 scan
->bm_bighint
= 0;
353 return(SWAPBLK_NONE
);
357 * Optimized code to allocate one bit out of the bitmap
360 int j
= BLIST_BMAP_RADIX
/2;
363 mask
= (u_daddr_t
)-1 >> (BLIST_BMAP_RADIX
/2);
366 if ((orig
& mask
) == 0) {
373 scan
->u
.bmu_bitmap
&= ~(1 << r
);
376 if (count
<= BLIST_BMAP_RADIX
) {
378 * non-optimized code to allocate N bits out of the bitmap.
379 * The more bits, the faster the code runs. It will run
380 * the slowest allocating 2 bits, but since there aren't any
381 * memory ops in the core loop (or shouldn't be, anyway),
382 * you probably won't notice the difference.
385 int n
= BLIST_BMAP_RADIX
- count
;
388 mask
= (u_daddr_t
)-1 >> n
;
390 for (j
= 0; j
<= n
; ++j
) {
391 if ((orig
& mask
) == mask
) {
392 scan
->u
.bmu_bitmap
&= ~mask
;
399 * We couldn't allocate count in this subtree, update bighint.
401 scan
->bm_bighint
= count
- 1;
402 return(SWAPBLK_NONE
);
406 * blist_meta_alloc() - allocate at a meta in the radix tree.
408 * Attempt to allocate at a meta node. If we can't, we update
409 * bighint and return a failure. Updating bighint optimize future
410 * calls that hit this node. We have to check for our collapse cases
411 * and we have a few optimizations strewn in as well.
423 int next_skip
= ((u_int
)skip
/ BLIST_META_RADIX
);
425 if (scan
->u
.bmu_avail
== 0) {
427 * ALL-ALLOCATED special case
429 scan
->bm_bighint
= count
;
430 return(SWAPBLK_NONE
);
433 if (scan
->u
.bmu_avail
== radix
) {
434 radix
/= BLIST_META_RADIX
;
437 * ALL-FREE special case, initialize uninitialize
440 for (i
= 1; i
<= skip
; i
+= next_skip
) {
441 if (scan
[i
].bm_bighint
== (daddr_t
)-1)
443 if (next_skip
== 1) {
444 scan
[i
].u
.bmu_bitmap
= (u_daddr_t
)-1;
445 scan
[i
].bm_bighint
= BLIST_BMAP_RADIX
;
447 scan
[i
].bm_bighint
= radix
;
448 scan
[i
].u
.bmu_avail
= radix
;
452 radix
/= BLIST_META_RADIX
;
455 for (i
= 1; i
<= skip
; i
+= next_skip
) {
456 if (count
<= scan
[i
].bm_bighint
) {
458 * count fits in object
461 if (next_skip
== 1) {
462 r
= blst_leaf_alloc(&scan
[i
], blk
, count
);
464 r
= blst_meta_alloc(&scan
[i
], blk
, count
, radix
, next_skip
- 1);
466 if (r
!= SWAPBLK_NONE
) {
467 scan
->u
.bmu_avail
-= count
;
468 if (scan
->bm_bighint
> scan
->u
.bmu_avail
)
469 scan
->bm_bighint
= scan
->u
.bmu_avail
;
472 } else if (scan
[i
].bm_bighint
== (daddr_t
)-1) {
477 } else if (count
> radix
) {
479 * count does not fit in object even if it were
482 panic("blist_meta_alloc: allocation too large");
488 * We couldn't allocate count in this subtree, update bighint.
490 if (scan
->bm_bighint
>= count
)
491 scan
->bm_bighint
= count
- 1;
492 return(SWAPBLK_NONE
);
496 * BLST_LEAF_FREE() - free allocated block from leaf bitmap
507 * free some data in this bitmap
510 * 0000111111111110000
514 int n
= blk
& (BLIST_BMAP_RADIX
- 1);
517 mask
= ((u_daddr_t
)-1 << n
) &
518 ((u_daddr_t
)-1 >> (BLIST_BMAP_RADIX
- count
- n
));
520 if (scan
->u
.bmu_bitmap
& mask
)
521 panic("blst_radix_free: freeing free block");
522 scan
->u
.bmu_bitmap
|= mask
;
525 * We could probably do a better job here. We are required to make
526 * bighint at least as large as the biggest contiguous block of
527 * data. If we just shoehorn it, a little extra overhead will
528 * be incured on the next allocation (but only that one typically).
530 scan
->bm_bighint
= BLIST_BMAP_RADIX
;
534 * BLST_META_FREE() - free allocated blocks from radix tree meta info
536 * This support routine frees a range of blocks from the bitmap.
537 * The range must be entirely enclosed by this radix node. If a
538 * meta node, we break the range down recursively to free blocks
539 * in subnodes (which means that this code can free an arbitrary
540 * range whereas the allocation code cannot allocate an arbitrary
554 int next_skip
= ((u_int
)skip
/ BLIST_META_RADIX
);
557 printf("FREE (%llx,%lld) FROM (%llx,%lld)\n",
558 (long long)freeBlk
, (long long)count
,
559 (long long)blk
, (long long)radix
563 if (scan
->u
.bmu_avail
== 0) {
565 * ALL-ALLOCATED special case, with possible
566 * shortcut to ALL-FREE special case.
568 scan
->u
.bmu_avail
= count
;
569 scan
->bm_bighint
= count
;
571 if (count
!= radix
) {
572 for (i
= 1; i
<= skip
; i
+= next_skip
) {
573 if (scan
[i
].bm_bighint
== (daddr_t
)-1)
575 scan
[i
].bm_bighint
= 0;
576 if (next_skip
== 1) {
577 scan
[i
].u
.bmu_bitmap
= 0;
579 scan
[i
].u
.bmu_avail
= 0;
585 scan
->u
.bmu_avail
+= count
;
586 /* scan->bm_bighint = radix; */
590 * ALL-FREE special case.
593 if (scan
->u
.bmu_avail
== radix
)
595 if (scan
->u
.bmu_avail
> radix
)
596 panic("blst_meta_free: freeing already free blocks (%lld) %lld/%lld",
597 (long long)count
, (long long)scan
->u
.bmu_avail
,
601 * Break the free down into its components
604 radix
/= BLIST_META_RADIX
;
606 i
= (freeBlk
- blk
) / radix
;
608 i
= i
* next_skip
+ 1;
610 while (i
<= skip
&& blk
< freeBlk
+ count
) {
613 v
= blk
+ radix
- freeBlk
;
617 if (scan
->bm_bighint
== (daddr_t
)-1)
618 panic("blst_meta_free: freeing unexpected range");
620 if (next_skip
== 1) {
621 blst_leaf_free(&scan
[i
], freeBlk
, v
);
623 blst_meta_free(&scan
[i
], freeBlk
, v
, radix
, next_skip
- 1, blk
);
625 if (scan
->bm_bighint
< scan
[i
].bm_bighint
)
626 scan
->bm_bighint
= scan
[i
].bm_bighint
;
635 * BLIST_RADIX_COPY() - copy one radix tree to another
637 * Locates free space in the source tree and frees it in the destination
638 * tree. The space may not already be free in the destination.
641 static void blst_copy(
656 if (radix
== BLIST_BMAP_RADIX
) {
657 u_daddr_t v
= scan
->u
.bmu_bitmap
;
659 if (v
== (u_daddr_t
)-1) {
660 blist_free(dest
, blk
, count
);
664 for (i
= 0; i
< BLIST_BMAP_RADIX
&& i
< count
; ++i
) {
666 blist_free(dest
, blk
+ i
, 1);
676 if (scan
->u
.bmu_avail
== 0) {
678 * Source all allocated, leave dest allocated
682 if (scan
->u
.bmu_avail
== radix
) {
684 * Source all free, free entire dest
687 blist_free(dest
, blk
, count
);
689 blist_free(dest
, blk
, radix
);
694 radix
/= BLIST_META_RADIX
;
695 next_skip
= ((u_int
)skip
/ BLIST_META_RADIX
);
697 for (i
= 1; count
&& i
<= skip
; i
+= next_skip
) {
698 if (scan
[i
].bm_bighint
== (daddr_t
)-1)
701 if (count
>= radix
) {
729 * BLST_LEAF_FILL() - allocate specific blocks in leaf bitmap
731 * This routine allocates all blocks in the specified range
732 * regardless of any existing allocations in that range. Returns
733 * the number of blocks allocated by the call.
737 blst_leaf_fill(blmeta_t
*scan
, daddr_t blk
, int count
)
739 int n
= blk
& (BLIST_BMAP_RADIX
- 1);
741 u_daddr_t mask
, bitmap
;
743 mask
= ((u_daddr_t
)-1 << n
) &
744 ((u_daddr_t
)-1 >> (BLIST_BMAP_RADIX
- count
- n
));
746 /* Count the number of blocks we're about to allocate */
747 bitmap
= scan
->u
.bmu_bitmap
& mask
;
748 for (nblks
= 0; bitmap
!= 0; nblks
++)
749 bitmap
&= bitmap
- 1;
751 scan
->u
.bmu_bitmap
&= ~mask
;
756 * BLIST_META_FILL() - allocate specific blocks at a meta node
758 * This routine allocates the specified range of blocks,
759 * regardless of any existing allocations in the range. The
760 * range must be within the extent of this node. Returns the
761 * number of blocks allocated by the call.
773 int next_skip
= ((u_int
)skip
/ BLIST_META_RADIX
);
776 if (count
== radix
|| scan
->u
.bmu_avail
== 0) {
778 * ALL-ALLOCATED special case
780 nblks
= scan
->u
.bmu_avail
;
781 scan
->u
.bmu_avail
= 0;
782 scan
->bm_bighint
= count
;
786 if (scan
->u
.bmu_avail
== radix
) {
787 radix
/= BLIST_META_RADIX
;
790 * ALL-FREE special case, initialize sublevel
792 for (i
= 1; i
<= skip
; i
+= next_skip
) {
793 if (scan
[i
].bm_bighint
== (daddr_t
)-1)
795 if (next_skip
== 1) {
796 scan
[i
].u
.bmu_bitmap
= (u_daddr_t
)-1;
797 scan
[i
].bm_bighint
= BLIST_BMAP_RADIX
;
799 scan
[i
].bm_bighint
= radix
;
800 scan
[i
].u
.bmu_avail
= radix
;
804 radix
/= BLIST_META_RADIX
;
808 panic("blist_meta_fill: allocation too large");
810 i
= (allocBlk
- blk
) / radix
;
812 i
= i
* next_skip
+ 1;
814 while (i
<= skip
&& blk
< allocBlk
+ count
) {
817 v
= blk
+ radix
- allocBlk
;
821 if (scan
->bm_bighint
== (daddr_t
)-1)
822 panic("blst_meta_fill: filling unexpected range");
824 if (next_skip
== 1) {
825 nblks
+= blst_leaf_fill(&scan
[i
], allocBlk
, v
);
827 nblks
+= blst_meta_fill(&scan
[i
], allocBlk
, v
,
828 radix
, next_skip
- 1, blk
);
835 scan
->u
.bmu_avail
-= nblks
;
840 * BLST_RADIX_INIT() - initialize radix tree
842 * Initialize our meta structures and bitmaps and calculate the exact
843 * amount of space required to manage 'count' blocks - this space may
844 * be considerably less then the calculated radix due to the large
845 * RADIX values we use.
849 blst_radix_init(blmeta_t
*scan
, daddr_t radix
, int skip
, daddr_t count
)
853 daddr_t memindex
= 0;
859 if (radix
== BLIST_BMAP_RADIX
) {
861 scan
->bm_bighint
= 0;
862 scan
->u
.bmu_bitmap
= 0;
868 * Meta node. If allocating the entire object we can special
869 * case it. However, we need to figure out how much memory
870 * is required to manage 'count' blocks, so we continue on anyway.
874 scan
->bm_bighint
= 0;
875 scan
->u
.bmu_avail
= 0;
878 radix
/= BLIST_META_RADIX
;
879 next_skip
= ((u_int
)skip
/ BLIST_META_RADIX
);
881 for (i
= 1; i
<= skip
; i
+= next_skip
) {
882 if (count
>= radix
) {
884 * Allocate the entire object
886 memindex
= i
+ blst_radix_init(
887 ((scan
) ? &scan
[i
] : NULL
),
893 } else if (count
> 0) {
895 * Allocate a partial object
897 memindex
= i
+ blst_radix_init(
898 ((scan
) ? &scan
[i
] : NULL
),
906 * Add terminator and break out
909 scan
[i
].bm_bighint
= (daddr_t
)-1;
921 blst_radix_print(blmeta_t
*scan
, daddr_t blk
, daddr_t radix
, int skip
, int tab
)
927 if (radix
== BLIST_BMAP_RADIX
) {
929 "%*.*s(%08llx,%lld): bitmap %08llx big=%lld\n",
931 (long long)blk
, (long long)radix
,
932 (long long)scan
->u
.bmu_bitmap
,
933 (long long)scan
->bm_bighint
938 if (scan
->u
.bmu_avail
== 0) {
940 "%*.*s(%08llx,%lld) ALL ALLOCATED\n",
947 if (scan
->u
.bmu_avail
== radix
) {
949 "%*.*s(%08llx,%lld) ALL FREE\n",
958 "%*.*s(%08llx,%lld): subtree (%lld/%lld) big=%lld {\n",
960 (long long)blk
, (long long)radix
,
961 (long long)scan
->u
.bmu_avail
,
963 (long long)scan
->bm_bighint
966 radix
/= BLIST_META_RADIX
;
967 next_skip
= ((u_int
)skip
/ BLIST_META_RADIX
);
970 for (i
= 1; i
<= skip
; i
+= next_skip
) {
971 if (scan
[i
].bm_bighint
== (daddr_t
)-1) {
973 "%*.*s(%08llx,%lld): Terminator\n",
975 (long long)blk
, (long long)radix
1002 main(int ac
, char **av
)
1008 for (i
= 1; i
< ac
; ++i
) {
1009 const char *ptr
= av
[i
];
1011 size
= strtol(ptr
, NULL
, 0);
1015 fprintf(stderr
, "Bad option: %s\n", ptr
- 2);
1018 bl
= blist_create(size
, M_WAITOK
);
1019 blist_free(bl
, 0, size
);
1027 printf("%lld/%lld/%lld> ", (long long)bl
->bl_free
,
1028 (long long)size
, (long long)bl
->bl_radix
);
1030 if (fgets(buf
, sizeof(buf
), stdin
) == NULL
)
1034 if (sscanf(buf
+ 1, "%lld", &count
) == 1) {
1035 blist_resize(&bl
, count
, 1);
1043 if (sscanf(buf
+ 1, "%lld", &count
) == 1) {
1044 daddr_t blk
= blist_alloc(bl
, count
);
1045 printf(" R=%08llx\n", (long long)blk
);
1051 if (sscanf(buf
+ 1, "%llx %lld",
1052 (long long *)&da
, (long long *)&count
) == 2) {
1053 blist_free(bl
, da
, count
);
1059 if (sscanf(buf
+ 1, "%llx %lld",
1060 (long long *)&da
, (long long *)&count
) == 2) {
1062 blist_fill(bl
, da
, count
));
1087 panic(const char *ctl
, ...)
1092 vfprintf(stderr
, ctl
, va
);
1093 fprintf(stderr
, "\n");