FreeBSD/Linux Kernel Cross Reference
sys/sys/blist.h
1 /*-
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
5 * are met:
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.
14 *
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.
26 *
27 * Implements bitmap resource lists.
28 *
29 * Usage:
30 * blist = blist_create(blocks)
31 * (void) blist_destroy(blist)
32 * blkno = blist_alloc(blist, count)
33 * (void) blist_free(blist, blkno, count)
34 * nblks = blist_fill(blist, blkno, count)
35 * (void) blist_resize(&blist, count, freeextra)
36 *
37 *
38 * Notes:
39 * on creation, the entire list is marked reserved. You should
40 * first blist_free() the sections you want to make available
41 * for allocation before doing general blist_alloc()/free()
42 * ops.
43 *
44 * SWAPBLK_NONE is returned on failure. This module is typically
45 * capable of managing up to (2^31) blocks per blist, though
46 * the memory utilization would be insane if you actually did
47 * that. Managing something like 512MB worth of 4K blocks
48 * eats around 32 KBytes of memory.
49 *
50 * $FreeBSD: releng/5.3/sys/sys/blist.h 136588 2004-10-16 08:43:07Z cvs2svn $
51 */
52
53 #ifndef _SYS_BLIST_H_
54 #define _SYS_BLIST_H_
55
56 typedef u_int32_t u_daddr_t; /* unsigned disk address */
57
58 /*
59 * note: currently use SWAPBLK_NONE as an absolute value rather then
60 * a flag bit.
61 */
62
63 #define SWAPBLK_MASK ((daddr_t)((u_daddr_t)-1 >> 1)) /* mask */
64 #define SWAPBLK_NONE ((daddr_t)((u_daddr_t)SWAPBLK_MASK + 1))/* flag */
65
66 /*
67 * blmeta and bl_bitmap_t MUST be a power of 2 in size.
68 */
69
70 typedef struct blmeta {
71 union {
72 daddr_t bmu_avail; /* space available under us */
73 u_daddr_t bmu_bitmap; /* bitmap if we are a leaf */
74 } u;
75 daddr_t bm_bighint; /* biggest contiguous block hint*/
76 } blmeta_t;
77
78 typedef struct blist {
79 daddr_t bl_blocks; /* area of coverage */
80 daddr_t bl_radix; /* coverage radix */
81 daddr_t bl_skip; /* starting skip */
82 daddr_t bl_free; /* number of free blocks */
83 blmeta_t *bl_root; /* root of radix tree */
84 daddr_t bl_rootblks; /* daddr_t blks allocated for tree */
85 } *blist_t;
86
87 #define BLIST_META_RADIX 16
88 #define BLIST_BMAP_RADIX (sizeof(u_daddr_t)*8)
89
90 #define BLIST_MAX_ALLOC BLIST_BMAP_RADIX
91
92 extern blist_t blist_create(daddr_t blocks);
93 extern void blist_destroy(blist_t blist);
94 extern daddr_t blist_alloc(blist_t blist, daddr_t count);
95 extern void blist_free(blist_t blist, daddr_t blkno, daddr_t count);
96 extern int blist_fill(blist_t bl, daddr_t blkno, daddr_t count);
97 extern void blist_print(blist_t blist);
98 extern void blist_resize(blist_t *pblist, daddr_t count, int freenew);
99
100 #endif /* _SYS_BLIST_H_ */
101
Cache object: 6ea24263b0d5041e1203bcb5858eb09b
|