Device layer rollup commit.
[dragonfly.git] / sys / sys / blist.h
1 /*
2  * Copyright (c) 1998 Matthew Dillon.  Terms of use and redistribution in all
3  * forms are covered by the BSD copyright in the file "/usr/src/COPYRIGHT".
4  *
5  * Implements bitmap resource lists.
6  *
7  *      Usage:
8  *              blist = blist_create(blocks)
9  *              (void)  blist_destroy(blist)
10  *              blkno = blist_alloc(blist, count)
11  *              (void)  blist_free(blist, blkno, count)
12  *              (void)  blist_resize(&blist, count, freeextra)
13  *              
14  *
15  *      Notes:
16  *              on creation, the entire list is marked reserved.  You should
17  *              first blist_free() the sections you want to make available
18  *              for allocation before doing general blist_alloc()/free()
19  *              ops.
20  *
21  *              SWAPBLK_NONE is returned on failure.  This module is typically
22  *              capable of managing up to (2^31) blocks per blist, though
23  *              the memory utilization would be insane if you actually did
24  *              that.  Managing something like 512MB worth of 4K blocks 
25  *              eats around 32 KBytes of memory. 
26  *
27  * $FreeBSD: src/sys/sys/blist.h,v 1.2.2.1 2003/01/12 09:23:12 dillon Exp $
28  * $DragonFly: src/sys/sys/blist.h,v 1.2 2003/06/17 04:28:58 dillon Exp $
29  */
30
31 #ifndef _SYS_BLIST_H_
32 #define _SYS_BLIST_H_
33
34 /*
35  * blmeta and bl_bitmap_t MUST be a power of 2 in size.
36  */
37
38 typedef struct blmeta {
39         union {
40             daddr_t     bmu_avail;      /* space available under us     */
41             u_daddr_t   bmu_bitmap;     /* bitmap if we are a leaf      */
42         } u;
43         daddr_t         bm_bighint;     /* biggest contiguous block hint*/
44 } blmeta_t;
45
46 typedef struct blist {
47         daddr_t         bl_blocks;      /* area of coverage             */
48         daddr_t         bl_radix;       /* coverage radix               */
49         daddr_t         bl_skip;        /* starting skip                */
50         daddr_t         bl_free;        /* number of free blocks        */
51         blmeta_t        *bl_root;       /* root of radix tree           */
52         daddr_t         bl_rootblks;    /* daddr_t blks allocated for tree */
53 } *blist_t;
54
55 #define BLIST_META_RADIX        16
56 #define BLIST_BMAP_RADIX        (sizeof(u_daddr_t)*8)
57
58 #define BLIST_MAX_ALLOC         BLIST_BMAP_RADIX
59
60 extern blist_t blist_create(daddr_t blocks);
61 extern void blist_destroy(blist_t blist);
62 extern daddr_t blist_alloc(blist_t blist, daddr_t count);
63 extern void blist_free(blist_t blist, daddr_t blkno, daddr_t count);
64 extern void blist_print(blist_t blist);
65 extern void blist_resize(blist_t *pblist, daddr_t count, int freenew);
66
67 #endif  /* _SYS_BLIST_H_ */
68