Index: sys/kern/subr_blist.c =================================================================== --- sys/kern/subr_blist.c +++ sys/kern/subr_blist.c @@ -606,13 +606,17 @@ blst_next_leaf_alloc(blmeta_t *scan, daddr_t blk, int count) { blmeta_t *next; - daddr_t skip; u_daddr_t radix; int digit; next = scan + 1; blk += BLIST_BMAP_RADIX; radix = BLIST_BMAP_RADIX; + + /* + * Skip meta-nodes, and find the position of the next leaf and their + * least common ancestor. + */ while ((digit = ((blk / radix) & BLIST_META_MASK)) == 0 && (next->bm_bitmap & 1) == 1) { next++; @@ -629,15 +633,21 @@ next->bm_bitmap &= (u_daddr_t)-1 << count; /* - * Update bitmaps of next-ancestors, up to least common ancestor. + * Update meta-node bitmaps of next-ancestors, up to the least common + * ancestor of scan and next. */ - skip = radix_to_skip(radix); - while (radix != BLIST_BMAP_RADIX && next->bm_bitmap == 0) { - (--next)->bm_bitmap ^= 1; - radix /= BLIST_META_RADIX; + while (next->bm_bitmap == 0) { + if (--next == scan) { + /* + * In their least common ancestor, mark the node + * containing next as full. + */ + next[-digit * radix_to_skip(radix)].bm_bitmap ^= + (u_daddr_t)1 << digit; + break; + } + next->bm_bitmap ^= 1; } - if (next->bm_bitmap == 0) - scan[-digit * skip].bm_bitmap ^= (u_daddr_t)1 << digit; return (0); } Index: sys/sys/blist.h =================================================================== --- sys/sys/blist.h +++ sys/sys/blist.h @@ -69,11 +69,11 @@ #define SWAPBLK_NONE ((daddr_t)((u_daddr_t)SWAPBLK_MASK + 1))/* flag */ /* - * Both blmeta and bmu_bitmap MUST be a power of 2 in size. + * Both blmeta and bm_bitmap MUST be a power of 2 in size. */ typedef struct blmeta { - u_daddr_t bm_bitmap; /* bitmap if we are a leaf */ + u_daddr_t bm_bitmap; /* bitmap marking unfilled block sets*/ daddr_t bm_bighint; /* biggest contiguous block hint*/ } blmeta_t;