Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys - add a missing cast in the 1-bit optimization case of b...



details:   https://anonhg.NetBSD.org/src/rev/28c845588419
branches:  trunk
changeset: 580044:28c845588419
user:      yamt <yamt%NetBSD.org@localhost>
date:      Wed Apr 06 11:35:54 2005 +0000

description:
- add a missing cast in the 1-bit optimization case of blst_leaf_alloc.
- use uint64_t rather than daddr_t/u_daddr_t and rename SWAP -> BLIST.

XXX 32 bit is enough?  will revisit later.

diffstat:

 sys/kern/subr_blist.c |  281 ++++++++++++++++++++++++-------------------------
 sys/sys/blist.h       |   39 +++---
 2 files changed, 155 insertions(+), 165 deletions(-)

diffs (truncated from 793 to 300 lines):

diff -r d78b61571e04 -r 28c845588419 sys/kern/subr_blist.c
--- a/sys/kern/subr_blist.c     Wed Apr 06 11:33:54 2005 +0000
+++ b/sys/kern/subr_blist.c     Wed Apr 06 11:35:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_blist.c,v 1.2 2005/04/06 11:33:54 yamt Exp $      */
+/*     $NetBSD: subr_blist.c,v 1.3 2005/04/06 11:35:54 yamt Exp $      */
 
 /*-
  * Copyright (c) 1998 Matthew Dillon.  All Rights Reserved.
@@ -32,7 +32,7 @@
  *     This module implements a general bitmap allocator/deallocator.  The
  *     allocator eats around 2 bits per 'block'.  The module does not 
  *     try to interpret the meaning of a 'block' other then to return 
- *     SWAPBLK_NONE on an allocation failure.
+ *     BLIST_NONE on an allocation failure.
  *
  *     A radix tree is used to maintain the bitmap.  Two radix constants are
  *     involved:  One for the bitmaps contained in the leaf nodes (typically
@@ -86,7 +86,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_blist.c,v 1.2 2005/04/06 11:33:54 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_blist.c,v 1.3 2005/04/06 11:35:54 yamt Exp $");
 #if 0
 __FBSDID("$FreeBSD: src/sys/kern/subr_blist.c,v 1.17 2004/06/04 04:03:25 alc Exp $");
 #endif
@@ -107,20 +107,17 @@
 #define BLIST_DEBUG
 #endif
 
-#define SWAPBLK_NONE ((daddr_t)-1)
-
 #include <sys/types.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <inttypes.h>
 
 #define malloc(a,b,c)  calloc(a, 1)
 #define free(a,b)      free(a)
 
-typedef unsigned int u_daddr_t;
-
-#include <sys/blist.h>
+#include "../sys/blist.h"
 
 void panic(const char *ctl, ...);
 
@@ -130,26 +127,26 @@
  * static support functions
  */
 
-static daddr_t blst_leaf_alloc(blmeta_t *scan, daddr_t blk, int count);
-static daddr_t blst_meta_alloc(blmeta_t *scan, daddr_t blk, 
-                               daddr_t count, daddr_t radix, int skip);
-static void blst_leaf_free(blmeta_t *scan, daddr_t relblk, int count);
-static void blst_meta_free(blmeta_t *scan, daddr_t freeBlk, daddr_t count, 
-                                       daddr_t radix, int skip, daddr_t blk);
-static void blst_copy(blmeta_t *scan, daddr_t blk, daddr_t radix, 
-                               daddr_t skip, blist_t dest, daddr_t count);
-static int blst_leaf_fill(blmeta_t *scan, daddr_t blk, int count);
-static int blst_meta_fill(blmeta_t *scan, daddr_t allocBlk, daddr_t count,
-                               daddr_t radix, int skip, daddr_t blk);
-static daddr_t blst_radix_init(blmeta_t *scan, daddr_t radix, 
-                                               int skip, daddr_t count);
+static uint64_t blst_leaf_alloc(blmeta_t *scan, uint64_t blk, int count);
+static uint64_t blst_meta_alloc(blmeta_t *scan, uint64_t blk, 
+                               uint64_t count, uint64_t radix, int skip);
+static void blst_leaf_free(blmeta_t *scan, uint64_t relblk, int count);
+static void blst_meta_free(blmeta_t *scan, uint64_t freeBlk, uint64_t count, 
+                                       uint64_t radix, int skip, uint64_t blk);
+static void blst_copy(blmeta_t *scan, uint64_t blk, uint64_t radix, 
+                               uint64_t skip, blist_t dest, uint64_t count);
+static int blst_leaf_fill(blmeta_t *scan, uint64_t blk, int count);
+static int blst_meta_fill(blmeta_t *scan, uint64_t allocBlk, uint64_t count,
+                               uint64_t radix, int skip, uint64_t blk);
+static uint64_t        blst_radix_init(blmeta_t *scan, uint64_t radix, 
+                                               int skip, uint64_t count);
 #ifndef _KERNEL
-static void    blst_radix_print(blmeta_t *scan, daddr_t blk, 
-                                       daddr_t radix, int skip, int tab);
+static void    blst_radix_print(blmeta_t *scan, uint64_t blk, 
+                                       uint64_t radix, int skip, int tab);
 #endif
 
 #ifdef _KERNEL
-static MALLOC_DEFINE(M_SWAP, "SWAP", "Swap space");
+static MALLOC_DEFINE(M_BLIST, "blist", "Bitmap allocator");
 #endif
 
 /*
@@ -163,7 +160,7 @@
  */
 
 blist_t 
-blist_create(daddr_t blocks)
+blist_create(uint64_t blocks)
 {
        blist_t bl;
        int radix;
@@ -179,25 +176,25 @@
                skip = (skip + 1) * BLIST_META_RADIX;
        }
 
-       bl = malloc(sizeof(struct blist), M_SWAP, M_WAITOK | M_ZERO);
+       bl = malloc(sizeof(struct blist), M_BLIST, M_WAITOK | 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, M_WAITOK);
+       bl->bl_root = malloc(sizeof(blmeta_t) * bl->bl_rootblks, M_BLIST, M_WAITOK);
 
 #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
+               "BLIST representing %" PRIu64 " blocks (%" PRIu64 " MB of swap)"
+               ", requiring %" PRIu64 "K of ram\n",
+               bl->bl_blocks,
+               bl->bl_blocks * 4 / 1024,
+               (bl->bl_rootblks * sizeof(blmeta_t) + 1023) / 1024
        );
-       printf("BLIST raw radix tree contains %lld records\n",
-           (long long)bl->bl_rootblks);
+       printf("BLIST raw radix tree contains %" PRIu64 " records\n",
+           bl->bl_rootblks);
 #endif
        blst_radix_init(bl->bl_root, bl->bl_radix, bl->bl_skip, blocks);
 
@@ -207,27 +204,27 @@
 void 
 blist_destroy(blist_t bl)
 {
-       free(bl->bl_root, M_SWAP);
-       free(bl, M_SWAP);
+       free(bl->bl_root, M_BLIST);
+       free(bl, M_BLIST);
 }
 
 /*
  * blist_alloc() - reserve space in the block bitmap.  Return the base
- *                  of a contiguous region or SWAPBLK_NONE if space could
+ *                  of a contiguous region or BLIST_NONE if space could
  *                  not be allocated.
  */
 
-daddr_t 
-blist_alloc(blist_t bl, daddr_t count)
+uint64_t 
+blist_alloc(blist_t bl, uint64_t count)
 {
-       daddr_t blk = SWAPBLK_NONE;
+       uint64_t blk = BLIST_NONE;
 
        if (bl) {
                if (bl->bl_radix == BLIST_BMAP_RADIX)
                        blk = blst_leaf_alloc(bl->bl_root, 0, count);
                else
                        blk = blst_meta_alloc(bl->bl_root, 0, count, bl->bl_radix, bl->bl_skip);
-               if (blk != SWAPBLK_NONE)
+               if (blk != BLIST_NONE)
                        bl->bl_free -= count;
        }
        return(blk);
@@ -240,7 +237,7 @@
  */
 
 void 
-blist_free(blist_t bl, daddr_t blkno, daddr_t count)
+blist_free(blist_t bl, uint64_t blkno, uint64_t count)
 {
        if (bl) {
                if (bl->bl_radix == BLIST_BMAP_RADIX)
@@ -259,7 +256,7 @@
  */
 
 int
-blist_fill(blist_t bl, daddr_t blkno, daddr_t count)
+blist_fill(blist_t bl, uint64_t blkno, uint64_t count)
 {
        int filled;
 
@@ -284,7 +281,7 @@
  */
 
 void
-blist_resize(blist_t *pbl, daddr_t count, int freenew)
+blist_resize(blist_t *pbl, uint64_t count, int freenew)
 {
     blist_t newbl = blist_create(count);
     blist_t save = *pbl;
@@ -338,13 +335,13 @@
  *     quick.
  */
 
-static daddr_t
+static uint64_t
 blst_leaf_alloc(
        blmeta_t *scan,
-       daddr_t blk,
+       uint64_t blk,
        int count
 ) {
-       u_daddr_t orig = scan->u.bmu_bitmap;
+       uint64_t orig = scan->u.bmu_bitmap;
 
        if (orig == 0) {
                /*
@@ -353,17 +350,17 @@
                 * we have to take care of this case here.
                 */
                scan->bm_bighint = 0;
-               return(SWAPBLK_NONE);
+               return(BLIST_NONE);
        }
        if (count == 1) {
                /*
                 * Optimized code to allocate one bit out of the bitmap
                 */
-               u_daddr_t mask;
+               uint64_t mask;
                int j = BLIST_BMAP_RADIX/2;
                int r = 0;
 
-               mask = (u_daddr_t)-1 >> (BLIST_BMAP_RADIX/2);
+               mask = (uint64_t)-1 >> (BLIST_BMAP_RADIX/2);
 
                while (j) {
                        if ((orig & mask) == 0) {
@@ -373,7 +370,7 @@
                        j >>= 1;
                        mask >>= j;
                }
-               scan->u.bmu_bitmap &= ~(1 << r);
+               scan->u.bmu_bitmap &= ~((uint64_t)1 << r);
                return(blk + r);
        }
        if (count <= BLIST_BMAP_RADIX) {
@@ -386,9 +383,9 @@
                 */
                int j;
                int n = BLIST_BMAP_RADIX - count;
-               u_daddr_t mask;
+               uint64_t mask;
 
-               mask = (u_daddr_t)-1 >> n;
+               mask = (uint64_t)-1 >> n;
 
                for (j = 0; j <= n; ++j) {
                        if ((orig & mask) == mask) {
@@ -402,7 +399,7 @@
         * We couldn't allocate count in this subtree, update bighint.
         */
        scan->bm_bighint = count - 1;
-       return(SWAPBLK_NONE);
+       return(BLIST_NONE);
 }
 
 /*
@@ -414,12 +411,12 @@
  *     and we have a few optimizations strewn in as well.
  */
 
-static daddr_t
+static uint64_t
 blst_meta_alloc(
        blmeta_t *scan, 
-       daddr_t blk,
-       daddr_t count,
-       daddr_t radix, 
+       uint64_t blk,
+       uint64_t count,
+       uint64_t radix, 
        int skip
 ) {
        int i;
@@ -430,7 +427,7 @@
                 * ALL-ALLOCATED special case
                 */
                scan->bm_bighint = count;
-               return(SWAPBLK_NONE);
+               return(BLIST_NONE);
        }
 
        if (scan->u.bmu_avail == radix) {
@@ -441,10 +438,10 @@
                 * sublevel.
                 */
                for (i = 1; i <= skip; i += next_skip) {
-                       if (scan[i].bm_bighint == (daddr_t)-1)
+                       if (scan[i].bm_bighint == (uint64_t)-1)
                                break;



Home | Main Index | Thread Index | Old Index