diff options
author | Sebastien Marie <semarie@cvs.openbsd.org> | 2022-08-06 13:44:05 +0000 |
---|---|---|
committer | Sebastien Marie <semarie@cvs.openbsd.org> | 2022-08-06 13:44:05 +0000 |
commit | 3d6de5c3ae83c3fb87d8aabc7cce1cddc56c9473 (patch) | |
tree | 9f1873ee69f8bc462ca370668aea231b05c5962a | |
parent | 425a7c659631babafd753a850dceeab8b5b24a63 (diff) |
blist: use swblk_t type (defined in sys/blist.h)
reduce the diff with DragonFlyBSD by using swblk_t and u_swblk_t types.
while here, move bitmap type (u_swblk_t) to u_int64_t on all archs. it makes the
regress the same on 64 and 32bits archs (and it success on both).
ok mpi@
-rw-r--r-- | regress/sys/uvm/Makefile | 3 | ||||
-rw-r--r-- | sys/kern/subr_blist.c | 297 | ||||
-rw-r--r-- | sys/sys/blist.h | 51 | ||||
-rw-r--r-- | sys/uvm/uvm_swap.c | 4 |
4 files changed, 179 insertions, 176 deletions
diff --git a/regress/sys/uvm/Makefile b/regress/sys/uvm/Makefile index 65ce0d6194b..04a005b0a53 100644 --- a/regress/sys/uvm/Makefile +++ b/regress/sys/uvm/Makefile @@ -1,5 +1,6 @@ -# $OpenBSD: Makefile,v 1.17 2020/10/26 19:55:01 anton Exp $ +# $OpenBSD: Makefile,v 1.18 2022/08/06 13:44:04 semarie Exp $ +SUBDIR+= blist SUBDIR+= minherit_zero SUBDIR+= mmap_4g mmap_size mmap_fixed mmap_mod SUBDIR+= mmap_noreplace mmap_write_self diff --git a/sys/kern/subr_blist.c b/sys/kern/subr_blist.c index 4cf6259417d..fdceb294d8f 100644 --- a/sys/kern/subr_blist.c +++ b/sys/kern/subr_blist.c @@ -1,4 +1,5 @@ -/* $OpenBSD: subr_blist.c,v 1.1 2022/07/29 17:47:12 semarie Exp $ */ +/* $OpenBSD: subr_blist.c,v 1.2 2022/08/06 13:44:04 semarie Exp $ */ +/* DragonFlyBSD:7b80531f545c7d3c51c1660130c71d01f6bccbe0:/sys/kern/subr_blist.c */ /* * BLIST.C - Bitmap allocator/deallocator, using a radix tree with hinting * @@ -133,29 +134,29 @@ * static support functions */ -static bsblk_t blst_leaf_alloc(blmeta_t *scan, bsblk_t blkat, - bsblk_t blk, bsblk_t count); -static bsblk_t blst_meta_alloc(blmeta_t *scan, bsblk_t blkat, - bsblk_t blk, bsblk_t count, - bsblk_t radix, bsblk_t skip); -static void blst_leaf_free(blmeta_t *scan, bsblk_t relblk, bsblk_t count); -static void blst_meta_free(blmeta_t *scan, bsblk_t freeBlk, bsblk_t count, - bsblk_t radix, bsblk_t skip, - bsblk_t blk); -static bsblk_t blst_leaf_fill(blmeta_t *scan, bsblk_t blk, bsblk_t count); -static bsblk_t blst_meta_fill(blmeta_t *scan, bsblk_t fillBlk, bsblk_t count, - bsblk_t radix, bsblk_t skip, - bsblk_t blk); -static void blst_copy(blmeta_t *scan, bsblk_t blk, bsblk_t radix, - bsblk_t skip, blist_t dest, bsblk_t count); -static bsblk_t blst_radix_init(blmeta_t *scan, bsblk_t radix, - bsblk_t skip, bsblk_t count); -static int blst_radix_gapfind(blmeta_t *scan, bsblk_t blk, bsblk_t radix, bsblk_t skip, - int state, bsblk_t *maxbp, bsblk_t *maxep, bsblk_t *bp, bsblk_t *ep); +static swblk_t blst_leaf_alloc(blmeta_t *scan, swblk_t blkat, + swblk_t blk, swblk_t count); +static swblk_t blst_meta_alloc(blmeta_t *scan, swblk_t blkat, + swblk_t blk, swblk_t count, + swblk_t radix, swblk_t skip); +static void blst_leaf_free(blmeta_t *scan, swblk_t relblk, swblk_t count); +static void blst_meta_free(blmeta_t *scan, swblk_t freeBlk, swblk_t count, + swblk_t radix, swblk_t skip, + swblk_t blk); +static swblk_t blst_leaf_fill(blmeta_t *scan, swblk_t blk, swblk_t count); +static swblk_t blst_meta_fill(blmeta_t *scan, swblk_t fillBlk, swblk_t count, + swblk_t radix, swblk_t skip, + swblk_t blk); +static void blst_copy(blmeta_t *scan, swblk_t blk, swblk_t radix, + swblk_t skip, blist_t dest, swblk_t count); +static swblk_t blst_radix_init(blmeta_t *scan, swblk_t radix, + swblk_t skip, swblk_t count); +static int blst_radix_gapfind(blmeta_t *scan, swblk_t blk, swblk_t radix, swblk_t skip, + int state, swblk_t *maxbp, swblk_t *maxep, swblk_t *bp, swblk_t *ep); #if defined(BLIST_DEBUG) || defined(DDB) -static void blst_radix_print(blmeta_t *scan, bsblk_t blk, - bsblk_t radix, bsblk_t skip, int tab); +static void blst_radix_print(blmeta_t *scan, swblk_t blk, + swblk_t radix, swblk_t skip, int tab); #endif /* @@ -171,18 +172,18 @@ static void blst_radix_print(blmeta_t *scan, bsblk_t blk, */ blist_t -blist_create(bsblk_t blocks) +blist_create(swblk_t blocks) { blist_t bl; - bsblk_t radix; - bsblk_t skip = 0; + swblk_t radix; + swblk_t skip = 0; KASSERT(blocks > 0); /* * Calculate radix and skip field used for scanning. * - * Radix can exceed BLIST_BMAP_RADIX bits even if bsblk_t is limited + * Radix can exceed BLIST_BMAP_RADIX bits even if swblk_t is limited * to BLIST_BMAP_RADIX bits. * * XXX check overflow @@ -236,10 +237,10 @@ blist_destroy(blist_t bl) * not be allocated. */ -bsblk_t -blist_alloc(blist_t bl, bsblk_t count) +swblk_t +blist_alloc(blist_t bl, swblk_t count) { - bsblk_t blk = SWAPBLK_NONE; + swblk_t blk = SWAPBLK_NONE; if (bl) { if (bl->bl_radix == BLIST_BMAP_RADIX) @@ -253,10 +254,10 @@ blist_alloc(blist_t bl, bsblk_t count) return(blk); } -bsblk_t -blist_allocat(blist_t bl, bsblk_t count, bsblk_t blkat) +swblk_t +blist_allocat(blist_t bl, swblk_t count, swblk_t blkat) { - bsblk_t blk = SWAPBLK_NONE; + swblk_t blk = SWAPBLK_NONE; if (bl) { KASSERT(blkat < bl->bl_blocks); @@ -280,7 +281,7 @@ blist_allocat(blist_t bl, bsblk_t count, bsblk_t blkat) */ void -blist_free(blist_t bl, bsblk_t blkno, bsblk_t count) +blist_free(blist_t bl, swblk_t blkno, swblk_t count) { if (bl) { KASSERT(blkno < bl->bl_blocks); @@ -301,10 +302,10 @@ blist_free(blist_t bl, bsblk_t blkno, bsblk_t count) * actually filled that were free before the call. */ -bsblk_t -blist_fill(blist_t bl, bsblk_t blkno, bsblk_t count) +swblk_t +blist_fill(blist_t bl, swblk_t blkno, swblk_t count) { - bsblk_t filled; + swblk_t filled; if (bl) { KASSERT(blkno < bl->bl_blocks); @@ -332,7 +333,7 @@ blist_fill(blist_t bl, bsblk_t blkno, bsblk_t count) */ void -blist_resize(blist_t *pbl, bsblk_t count, int freenew) +blist_resize(blist_t *pbl, swblk_t count, int freenew) { blist_t newbl = blist_create(count); blist_t save = *pbl; @@ -362,10 +363,10 @@ blist_resize(blist_t *pbl, bsblk_t count, int freenew) */ void -blist_gapfind(blist_t bl, bsblk_t *maxbp, bsblk_t *maxep) +blist_gapfind(blist_t bl, swblk_t *maxbp, swblk_t *maxep) { int state; - bsblk_t b, e; + swblk_t b, e; /* initialize gaps (max and current) */ *maxbp = *maxep = 0; @@ -398,16 +399,16 @@ blist_gapfind(blist_t bl, bsblk_t *maxbp, bsblk_t *maxep) * - max is the larger free gap */ static int -blst_radix_gapfind(blmeta_t *scan, bsblk_t blk, bsblk_t radix, bsblk_t skip, - int state, bsblk_t *maxbp, bsblk_t *maxep, bsblk_t *bp, bsblk_t *ep) +blst_radix_gapfind(blmeta_t *scan, swblk_t blk, swblk_t radix, swblk_t skip, + int state, swblk_t *maxbp, swblk_t *maxep, swblk_t *bp, swblk_t *ep) { - bsblk_t i; - bsblk_t next_skip; + swblk_t i; + swblk_t next_skip; if (radix == BLIST_BMAP_RADIX) { /* leaf node: we considere only completely free bitmap as free */ if (state == GAPFIND_FIRSTFREE) { - if (scan->u.bmu_bitmap == (bsbmp_t)-1) { + if (scan->u.bmu_bitmap == (u_swblk_t)-1) { /* node is fully free */ *bp = blk; return GAPFIND_FIRSTUSED; @@ -417,7 +418,7 @@ blst_radix_gapfind(blmeta_t *scan, bsblk_t blk, bsblk_t radix, bsblk_t skip, return state; } else if (state == GAPFIND_FIRSTUSED) { - if (scan->u.bmu_bitmap == (bsbmp_t)-1) { + if (scan->u.bmu_bitmap == (u_swblk_t)-1) { /* it is free, not found, keep state */ return state; } @@ -466,7 +467,7 @@ blst_radix_gapfind(blmeta_t *scan, bsblk_t blk, bsblk_t radix, bsblk_t skip, next_skip = (skip / BLIST_META_RADIX); for (i = 1; i <= skip; i += next_skip) { - if (scan[i].bm_bighint == (bsblk_t)-1) + if (scan[i].bm_bighint == (swblk_t)-1) /* Terminator */ break; @@ -514,11 +515,11 @@ blist_print(blist_t bl) * quick. */ -static bsblk_t -blst_leaf_alloc(blmeta_t *scan, bsblk_t blkat __unused, bsblk_t blk, - bsblk_t count) +static swblk_t +blst_leaf_alloc(blmeta_t *scan, swblk_t blkat __unused, swblk_t blk, + swblk_t count) { - bsbmp_t orig = scan->u.bmu_bitmap; + u_swblk_t orig = scan->u.bmu_bitmap; if (orig == 0) { /* @@ -533,11 +534,11 @@ blst_leaf_alloc(blmeta_t *scan, bsblk_t blkat __unused, bsblk_t blk, /* * Optimized code to allocate one bit out of the bitmap */ - bsbmp_t mask; + u_swblk_t mask; int j = BLIST_BMAP_RADIX/2; int r = 0; - mask = (bsbmp_t)-1 >> (BLIST_BMAP_RADIX/2); + mask = (u_swblk_t)-1 >> (BLIST_BMAP_RADIX/2); while (j) { if ((orig & mask) == 0) { @@ -547,7 +548,7 @@ blst_leaf_alloc(blmeta_t *scan, bsblk_t blkat __unused, bsblk_t blk, j >>= 1; mask >>= j; } - scan->u.bmu_bitmap &= ~((bsbmp_t)1 << r); + scan->u.bmu_bitmap &= ~((u_swblk_t)1 << r); return(blk + r); } if (count <= BLIST_BMAP_RADIX) { @@ -560,9 +561,9 @@ blst_leaf_alloc(blmeta_t *scan, bsblk_t blkat __unused, bsblk_t blk, */ int j; int n = (int)(BLIST_BMAP_RADIX - count); - bsbmp_t mask; + u_swblk_t mask; - mask = (bsbmp_t)-1 >> n; + mask = (u_swblk_t)-1 >> n; for (j = 0; j <= n; ++j) { if ((orig & mask) == mask) { @@ -589,14 +590,14 @@ blst_leaf_alloc(blmeta_t *scan, bsblk_t blkat __unused, bsblk_t blk, * calls that hit this node. We have to check for our collapse cases * and we have a few optimizations strewn in as well. */ -static bsblk_t -blst_meta_alloc(blmeta_t *scan, bsblk_t blkat, - bsblk_t blk, bsblk_t count, - bsblk_t radix, bsblk_t skip) +static swblk_t +blst_meta_alloc(blmeta_t *scan, swblk_t blkat, + swblk_t blk, swblk_t count, + swblk_t radix, swblk_t skip) { int hintok = (blk >= blkat); - bsblk_t next_skip = ((bsblk_t)skip / BLIST_META_RADIX); - bsblk_t i; + swblk_t next_skip = ((swblk_t)skip / BLIST_META_RADIX); + swblk_t i; #ifndef _KERNEL printf("blist_meta_alloc blkat %lu blk %lu count %lu radix %lu\n", @@ -622,14 +623,14 @@ blst_meta_alloc(blmeta_t *scan, bsblk_t blkat, radix /= BLIST_META_RADIX; for (i = 1; i <= skip; i += next_skip) { - if (scan[i].bm_bighint == (bsblk_t)-1) + if (scan[i].bm_bighint == (swblk_t)-1) break; if (next_skip == 1) { - scan[i].u.bmu_bitmap = (bsbmp_t)-1; + scan[i].u.bmu_bitmap = (u_swblk_t)-1; scan[i].bm_bighint = BLIST_BMAP_RADIX; } else { - scan[i].bm_bighint = (bsblk_t)radix; - scan[i].u.bmu_avail = (bsblk_t)radix; + scan[i].bm_bighint = (swblk_t)radix; + scan[i].u.bmu_avail = (swblk_t)radix; } } } else { @@ -638,11 +639,11 @@ blst_meta_alloc(blmeta_t *scan, bsblk_t blkat, for (i = 1; i <= skip; i += next_skip) { if (count <= scan[i].bm_bighint && - blk + (bsblk_t)radix > blkat) { + blk + (swblk_t)radix > blkat) { /* * count fits in object */ - bsblk_t r; + swblk_t r; if (next_skip == 1) { r = blst_leaf_alloc(&scan[i], blkat, blk, count); @@ -658,12 +659,12 @@ blst_meta_alloc(blmeta_t *scan, bsblk_t blkat, return(r); } /* bighint was updated by recursion */ - } else if (scan[i].bm_bighint == (bsblk_t)-1) { + } else if (scan[i].bm_bighint == (swblk_t)-1) { /* * Terminator */ break; - } else if (count > (bsblk_t)radix) { + } else if (count > (swblk_t)radix) { /* * count does not fit in object even if it were * complete free. @@ -671,7 +672,7 @@ blst_meta_alloc(blmeta_t *scan, bsblk_t blkat, panic("%s: allocation too large %lu/%lu", __func__, count, radix); } - blk += (bsblk_t)radix; + blk += (swblk_t)radix; } /* @@ -686,7 +687,7 @@ blst_meta_alloc(blmeta_t *scan, bsblk_t blkat, * BLST_LEAF_FREE() - free allocated block from leaf bitmap */ static void -blst_leaf_free(blmeta_t *scan, bsblk_t blk, bsblk_t count) +blst_leaf_free(blmeta_t *scan, swblk_t blk, swblk_t count) { /* * free some data in this bitmap @@ -697,10 +698,10 @@ blst_leaf_free(blmeta_t *scan, bsblk_t blk, bsblk_t count) * v n */ int n = blk & (BLIST_BMAP_RADIX - 1); - bsbmp_t mask; + u_swblk_t mask; - mask = ((bsbmp_t)-1 << n) & - ((bsbmp_t)-1 >> (BLIST_BMAP_RADIX - count - n)); + mask = ((u_swblk_t)-1 << n) & + ((u_swblk_t)-1 >> (BLIST_BMAP_RADIX - count - n)); if (scan->u.bmu_bitmap & mask) panic("%s: freeing free block", __func__); @@ -727,11 +728,11 @@ blst_leaf_free(blmeta_t *scan, bsblk_t blk, bsblk_t count) */ static void -blst_meta_free(blmeta_t *scan, bsblk_t freeBlk, bsblk_t count, - bsblk_t radix, bsblk_t skip, bsblk_t blk) +blst_meta_free(blmeta_t *scan, swblk_t freeBlk, swblk_t count, + swblk_t radix, swblk_t skip, swblk_t blk) { - bsblk_t i; - bsblk_t next_skip = ((bsblk_t)skip / BLIST_META_RADIX); + swblk_t i; + swblk_t next_skip = ((swblk_t)skip / BLIST_META_RADIX); #if 0 printf("FREE (%04lx,%lu) FROM (%04lx,%lu)\n", @@ -751,7 +752,7 @@ blst_meta_free(blmeta_t *scan, bsblk_t freeBlk, bsblk_t count, if (count != radix) { for (i = 1; i <= skip; i += next_skip) { - if (scan[i].bm_bighint == (bsblk_t)-1) + if (scan[i].bm_bighint == (swblk_t)-1) break; scan[i].bm_bighint = 0; if (next_skip == 1) { @@ -788,18 +789,18 @@ blst_meta_free(blmeta_t *scan, bsblk_t freeBlk, bsblk_t count, radix /= BLIST_META_RADIX; - i = (freeBlk - blk) / (bsblk_t)radix; - blk += i * (bsblk_t)radix; + i = (freeBlk - blk) / (swblk_t)radix; + blk += i * (swblk_t)radix; i = i * next_skip + 1; while (i <= skip && blk < freeBlk + count) { - bsblk_t v; + swblk_t v; - v = blk + (bsblk_t)radix - freeBlk; + v = blk + (swblk_t)radix - freeBlk; if (v > count) v = count; - if (scan->bm_bighint == (bsblk_t)-1) + if (scan->bm_bighint == (swblk_t)-1) panic("%s: freeing unexpected range", __func__); if (next_skip == 1) { @@ -822,7 +823,7 @@ blst_meta_free(blmeta_t *scan, bsblk_t freeBlk, bsblk_t count, } count -= v; freeBlk += v; - blk += (bsblk_t)radix; + blk += (swblk_t)radix; i += next_skip; } } @@ -834,15 +835,15 @@ blst_meta_free(blmeta_t *scan, bsblk_t freeBlk, bsblk_t count, * any existing allocations in that range. Returns the number * of blocks allocated by the call. */ -static bsblk_t -blst_leaf_fill(blmeta_t *scan, bsblk_t blk, bsblk_t count) +static swblk_t +blst_leaf_fill(blmeta_t *scan, swblk_t blk, swblk_t count) { int n = blk & (BLIST_BMAP_RADIX - 1); - bsblk_t nblks; - bsbmp_t mask, bitmap; + swblk_t nblks; + u_swblk_t mask, bitmap; - mask = ((bsbmp_t)-1 << n) & - ((bsbmp_t)-1 >> (BLIST_BMAP_RADIX - count - n)); + mask = ((u_swblk_t)-1 << n) & + ((u_swblk_t)-1 >> (BLIST_BMAP_RADIX - count - n)); /* Count the number of blocks we're about to allocate */ bitmap = scan->u.bmu_bitmap & mask; @@ -861,13 +862,13 @@ blst_leaf_fill(blmeta_t *scan, bsblk_t blk, bsblk_t count) * be within the extent of this node. Returns the number * of blocks allocated by the call. */ -static bsblk_t -blst_meta_fill(blmeta_t *scan, bsblk_t fillBlk, bsblk_t count, - bsblk_t radix, bsblk_t skip, bsblk_t blk) +static swblk_t +blst_meta_fill(blmeta_t *scan, swblk_t fillBlk, swblk_t count, + swblk_t radix, swblk_t skip, swblk_t blk) { - bsblk_t i; - bsblk_t next_skip = ((bsblk_t)skip / BLIST_META_RADIX); - bsblk_t nblks = 0; + swblk_t i; + swblk_t next_skip = ((swblk_t)skip / BLIST_META_RADIX); + swblk_t nblks = 0; if (count == radix || scan->u.bmu_avail == 0) { /* @@ -886,35 +887,35 @@ blst_meta_fill(blmeta_t *scan, bsblk_t fillBlk, bsblk_t count, * ALL-FREE special case, initialize sublevel */ for (i = 1; i <= skip; i += next_skip) { - if (scan[i].bm_bighint == (bsblk_t)-1) + if (scan[i].bm_bighint == (swblk_t)-1) break; if (next_skip == 1) { - scan[i].u.bmu_bitmap = (bsbmp_t)-1; + scan[i].u.bmu_bitmap = (u_swblk_t)-1; scan[i].bm_bighint = BLIST_BMAP_RADIX; } else { - scan[i].bm_bighint = (bsblk_t)radix; - scan[i].u.bmu_avail = (bsblk_t)radix; + scan[i].bm_bighint = (swblk_t)radix; + scan[i].u.bmu_avail = (swblk_t)radix; } } } else { radix /= BLIST_META_RADIX; } - if (count > (bsblk_t)radix) + if (count > (swblk_t)radix) panic("%s: allocation too large", __func__); - i = (fillBlk - blk) / (bsblk_t)radix; - blk += i * (bsblk_t)radix; + i = (fillBlk - blk) / (swblk_t)radix; + blk += i * (swblk_t)radix; i = i * next_skip + 1; while (i <= skip && blk < fillBlk + count) { - bsblk_t v; + swblk_t v; - v = blk + (bsblk_t)radix - fillBlk; + v = blk + (swblk_t)radix - fillBlk; if (v > count) v = count; - if (scan->bm_bighint == (bsblk_t)-1) + if (scan->bm_bighint == (swblk_t)-1) panic("%s: filling unexpected range", __func__); if (next_skip == 1) { @@ -925,7 +926,7 @@ blst_meta_fill(blmeta_t *scan, bsblk_t fillBlk, bsblk_t count, } count -= v; fillBlk += v; - blk += (bsblk_t)radix; + blk += (swblk_t)radix; i += next_skip; } scan->u.bmu_avail -= nblks; @@ -940,24 +941,24 @@ blst_meta_fill(blmeta_t *scan, bsblk_t fillBlk, bsblk_t count, */ static void -blst_copy(blmeta_t *scan, bsblk_t blk, bsblk_t radix, - bsblk_t skip, blist_t dest, bsblk_t count) +blst_copy(blmeta_t *scan, swblk_t blk, swblk_t radix, + swblk_t skip, blist_t dest, swblk_t count) { - bsblk_t next_skip; - bsblk_t i; + swblk_t next_skip; + swblk_t i; /* * Leaf node */ if (radix == BLIST_BMAP_RADIX) { - bsbmp_t v = scan->u.bmu_bitmap; + u_swblk_t v = scan->u.bmu_bitmap; - if (v == (bsbmp_t)-1) { + if (v == (u_swblk_t)-1) { blist_free(dest, blk, count); } else if (v != 0) { for (i = 0; i < BLIST_BMAP_RADIX && i < count; ++i) { - if (v & ((bsblk_t)1 << i)) + if (v & ((swblk_t)1 << i)) blist_free(dest, blk + i, 1); } } @@ -981,28 +982,28 @@ blst_copy(blmeta_t *scan, bsblk_t blk, bsblk_t radix, if (count < radix) blist_free(dest, blk, count); else - blist_free(dest, blk, (bsblk_t)radix); + blist_free(dest, blk, (swblk_t)radix); return; } radix /= BLIST_META_RADIX; - next_skip = ((bsbmp_t)skip / BLIST_META_RADIX); + next_skip = ((u_swblk_t)skip / BLIST_META_RADIX); for (i = 1; count && i <= skip; i += next_skip) { - if (scan[i].bm_bighint == (bsblk_t)-1) + if (scan[i].bm_bighint == (swblk_t)-1) break; - if (count >= (bsblk_t)radix) { + if (count >= (swblk_t)radix) { blst_copy( &scan[i], blk, radix, next_skip - 1, dest, - (bsblk_t)radix + (swblk_t)radix ); - count -= (bsblk_t)radix; + count -= (swblk_t)radix; } else { if (count) { blst_copy( @@ -1016,7 +1017,7 @@ blst_copy(blmeta_t *scan, bsblk_t blk, bsblk_t radix, } count = 0; } - blk += (bsblk_t)radix; + blk += (swblk_t)radix; } } @@ -1029,12 +1030,12 @@ blst_copy(blmeta_t *scan, bsblk_t blk, bsblk_t radix, * RADIX values we use. */ -static bsblk_t -blst_radix_init(blmeta_t *scan, bsblk_t radix, bsblk_t skip, bsblk_t count) +static swblk_t +blst_radix_init(blmeta_t *scan, swblk_t radix, swblk_t skip, swblk_t count) { - bsblk_t i; - bsblk_t next_skip; - bsblk_t memindex = 0; + swblk_t i; + swblk_t next_skip; + swblk_t memindex = 0; /* * Leaf node @@ -1060,10 +1061,10 @@ blst_radix_init(blmeta_t *scan, bsblk_t radix, bsblk_t skip, bsblk_t count) } radix /= BLIST_META_RADIX; - next_skip = ((bsbmp_t)skip / BLIST_META_RADIX); + next_skip = ((u_swblk_t)skip / BLIST_META_RADIX); for (i = 1; i <= skip; i += next_skip) { - if (count >= (bsblk_t)radix) { + if (count >= (swblk_t)radix) { /* * Allocate the entire object */ @@ -1071,9 +1072,9 @@ blst_radix_init(blmeta_t *scan, bsblk_t radix, bsblk_t skip, bsblk_t count) ((scan) ? &scan[i] : NULL), radix, next_skip - 1, - (bsblk_t)radix + (swblk_t)radix ); - count -= (bsblk_t)radix; + count -= (swblk_t)radix; } else if (count > 0) { /* * Allocate a partial object @@ -1090,7 +1091,7 @@ blst_radix_init(blmeta_t *scan, bsblk_t radix, bsblk_t skip, bsblk_t count) * Add terminator and break out */ if (scan) - scan[i].bm_bighint = (bsblk_t)-1; + scan[i].bm_bighint = (swblk_t)-1; break; } } @@ -1102,14 +1103,14 @@ blst_radix_init(blmeta_t *scan, bsblk_t radix, bsblk_t skip, bsblk_t count) #if defined(BLIST_DEBUG) || defined(DDB) static void -blst_radix_print(blmeta_t *scan, bsblk_t blk, bsblk_t radix, bsblk_t skip, int tab) +blst_radix_print(blmeta_t *scan, swblk_t blk, swblk_t radix, swblk_t skip, int tab) { - bsblk_t i; - bsblk_t next_skip; + swblk_t i; + swblk_t next_skip; if (radix == BLIST_BMAP_RADIX) { printf( - "%*.*s(%04lx,%lu): bitmap %0*lx big=%lu\n", + "%*.*s(%04lx,%lu): bitmap %0*llx big=%lu\n", tab, tab, "", blk, radix, (int)(1 + (BLIST_BMAP_RADIX - 1) / 4), @@ -1148,11 +1149,11 @@ blst_radix_print(blmeta_t *scan, bsblk_t blk, bsblk_t radix, bsblk_t skip, int t ); radix /= BLIST_META_RADIX; - next_skip = ((bsbmp_t)skip / BLIST_META_RADIX); + next_skip = ((u_swblk_t)skip / BLIST_META_RADIX); tab += 4; for (i = 1; i <= skip; i += next_skip) { - if (scan[i].bm_bighint == (bsblk_t)-1) { + if (scan[i].bm_bighint == (swblk_t)-1) { printf( "%*.*s(%04lx,%lu): Terminator\n", tab, tab, "", @@ -1167,7 +1168,7 @@ blst_radix_print(blmeta_t *scan, bsblk_t blk, bsblk_t radix, bsblk_t skip, int t next_skip - 1, tab ); - blk += (bsblk_t)radix; + blk += (swblk_t)radix; } tab -= 4; @@ -1184,11 +1185,11 @@ blst_radix_print(blmeta_t *scan, bsblk_t blk, bsblk_t radix, bsblk_t skip, int t int main(int ac, char **av) { - bsblk_t size = 1024; - bsblk_t i; + swblk_t size = 1024; + swblk_t i; blist_t bl; - for (i = 1; i < (bsblk_t)ac; ++i) { + for (i = 1; i < (swblk_t)ac; ++i) { const char *ptr = av[i]; if (*ptr != '-') { size = strtol(ptr, NULL, 0); @@ -1203,9 +1204,9 @@ main(int ac, char **av) for (;;) { char buf[1024]; - bsblk_t da = 0; - bsblk_t count = 0; - bsblk_t blkat; + swblk_t da = 0; + swblk_t count = 0; + swblk_t blkat; printf("%lu/%lu/%lu> ", @@ -1229,10 +1230,10 @@ main(int ac, char **av) case 'a': if (sscanf(buf + 1, "%li %li", &count, &blkat) == 1) { printf("count %lu\n", count); - bsblk_t blk = blist_alloc(bl, count); + swblk_t blk = blist_alloc(bl, count); printf(" R=%04lx\n", blk); } else if (sscanf(buf + 1, "%li %li", &count, &blkat) == 2) { - bsblk_t blk = blist_allocat(bl, count, blkat); + swblk_t blk = blist_allocat(bl, count, blkat); printf(" R=%04lx\n", blk); } else { printf("?\n"); @@ -1246,7 +1247,7 @@ main(int ac, char **av) } break; case 'g': { - bsblk_t b, e; + swblk_t b, e; blist_gapfind(bl, &b, &e); printf("gapfind: begin=%04lx end=%04lx size=%lu\n", b, e, e-b); diff --git a/sys/sys/blist.h b/sys/sys/blist.h index 102ca95dd45..24e1faf5e32 100644 --- a/sys/sys/blist.h +++ b/sys/sys/blist.h @@ -1,4 +1,5 @@ -/* $OpenBSD: blist.h,v 1.1 2022/07/29 17:47:12 semarie Exp $ */ +/* $OpenBSD: blist.h,v 1.2 2022/08/06 13:44:04 semarie Exp $ */ +/* DragonFlyBSD:7b80531f545c7d3c51c1660130c71d01f6bccbe0:/sys/sys/blist.h */ /* * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved. * @@ -65,15 +66,14 @@ #include <sys/types.h> #endif -#define SWBLK_BITS 64 -typedef u_long bsbmp_t; -typedef u_long bsblk_t; +typedef u_long swblk_t; +typedef u_int64_t u_swblk_t; /* * note: currently use SWAPBLK_NONE as an absolute value rather then * a flag bit. */ -#define SWAPBLK_NONE ((bsblk_t)-1) +#define SWAPBLK_NONE ((swblk_t)-1) /* * blmeta and bl_bitmap_t MUST be a power of 2 in size. @@ -81,39 +81,40 @@ typedef u_long bsblk_t; typedef struct blmeta { union { - bsblk_t bmu_avail; /* space available under us */ - bsbmp_t bmu_bitmap; /* bitmap if we are a leaf */ + swblk_t bmu_avail; /* space available under us */ + u_swblk_t bmu_bitmap; /* bitmap if we are a leaf */ } u; - bsblk_t bm_bighint; /* biggest contiguous block hint*/ + swblk_t bm_bighint; /* biggest contiguous block hint*/ } blmeta_t; typedef struct blist { - bsblk_t bl_blocks; /* area of coverage */ + swblk_t bl_blocks; /* area of coverage */ /* XXX int64_t bl_radix */ - bsblk_t bl_radix; /* coverage radix */ - bsblk_t bl_skip; /* starting skip */ - bsblk_t bl_free; /* number of free blocks */ + swblk_t bl_radix; /* coverage radix */ + swblk_t bl_skip; /* starting skip */ + swblk_t bl_free; /* number of free blocks */ blmeta_t *bl_root; /* root of radix tree */ - bsblk_t bl_rootblks; /* bsblk_t blks allocated for tree */ + swblk_t bl_rootblks; /* swblk_t blks allocated for tree */ } *blist_t; -#define BLIST_META_RADIX (sizeof(bsbmp_t)*8/2) /* 2 bits per */ -#define BLIST_BMAP_RADIX (sizeof(bsbmp_t)*8) /* 1 bit per */ +#define BLIST_META_RADIX (sizeof(u_swblk_t)*8/2) /* 2 bits per */ +#define BLIST_BMAP_RADIX (sizeof(u_swblk_t)*8) /* 1 bit per */ /* * The radix may exceed the size of a 64 bit signed (or unsigned) int - * when the maximal number of blocks is allocated. With a 32-bit bsblk_t + * when the maximal number of blocks is allocated. With a 32-bit swblk_t * this corresponds to ~1G x PAGE_SIZE = 4096GB. The swap code usually * divides this by 4, leaving us with a capability of up to four 1TB swap * devices. * - * With a 64-bit bsblk_t the limitation is some insane number. + * With a 64-bit swblk_t the limitation is some insane number. * * NOTE: For now I don't trust that we overflow-detect properly so we divide * out to ensure that no overflow occurs. */ -#if SWBLK_BITS == 64 +#if defined(_LP64) +/* swblk_t 64bits */ #define BLIST_MAXBLKS (0x4000000000000000LL / \ (BLIST_BMAP_RADIX / BLIST_META_RADIX)) #else @@ -123,14 +124,14 @@ typedef struct blist { #define BLIST_MAX_ALLOC BLIST_BMAP_RADIX -blist_t blist_create(bsblk_t); +blist_t blist_create(swblk_t); void blist_destroy(blist_t); -bsblk_t blist_alloc(blist_t, bsblk_t); -bsblk_t blist_allocat(blist_t, bsblk_t, bsblk_t); -void blist_free(blist_t, bsblk_t, bsblk_t); -bsblk_t blist_fill(blist_t, bsblk_t, bsblk_t); +swblk_t blist_alloc(blist_t, swblk_t); +swblk_t blist_allocat(blist_t, swblk_t, swblk_t); +void blist_free(blist_t, swblk_t, swblk_t); +swblk_t blist_fill(blist_t, swblk_t, swblk_t); void blist_print(blist_t); -void blist_resize(blist_t *, bsblk_t, int); -void blist_gapfind(blist_t, bsblk_t *, bsblk_t *); +void blist_resize(blist_t *, swblk_t, int); +void blist_gapfind(blist_t, swblk_t *, swblk_t *); #endif /* _SYS_BLIST_H_ */ diff --git a/sys/uvm/uvm_swap.c b/sys/uvm/uvm_swap.c index ad2437600ee..79d38cdc4bb 100644 --- a/sys/uvm/uvm_swap.c +++ b/sys/uvm/uvm_swap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_swap.c,v 1.162 2022/07/29 17:47:12 semarie Exp $ */ +/* $OpenBSD: uvm_swap.c,v 1.163 2022/08/06 13:44:04 semarie Exp $ */ /* $NetBSD: uvm_swap.c,v 1.40 2000/11/17 11:39:39 mrg Exp $ */ /* @@ -1428,7 +1428,7 @@ uvm_swap_alloc(int *nslots, boolean_t lessok) ReTry: /* XXXMRG */ LIST_FOREACH(spp, &swap_priority, spi_swappri) { TAILQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) { - bsblk_t result; + swblk_t result; /* if it's not enabled, then we can't swap from it */ if ((sdp->swd_flags & SWF_ENABLE) == 0) |