uvm_amap.h revision 1.7 1 /* $NetBSD: uvm_amap.h,v 1.7 1998/08/13 02:10:59 eeh Exp $ */
2
3 /*
4 * XXXCDC: "ROUGH DRAFT" QUALITY UVM PRE-RELEASE FILE!
5 * >>>USE AT YOUR OWN RISK, WORK IS NOT FINISHED<<<
6 */
7 /*
8 *
9 * Copyright (c) 1997 Charles D. Cranor and Washington University.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by Charles D. Cranor and
23 * Washington University.
24 * 4. The name of the author may not be used to endorse or promote products
25 * derived from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 * from: Id: uvm_amap.h,v 1.1.2.7 1998/01/05 18:12:56 chuck Exp
39 */
40
41 #ifndef _UVM_UVM_AMAP_H_
42 #define _UVM_UVM_AMAP_H_
43
44 /*
45 * uvm_amap.h
46 */
47
48 /*
49 * defines for handling of large sparce amaps.
50 *
51 * currently the kernel likes to allocate large chunks of VM to reserve
52 * them for possible use. for example, it allocates (reserves) a large
53 * chunk of user VM for possible stack growth. most of the time only
54 * a page or two of this VM is actually used. since the stack is anonymous
55 * memory it makes sense for it to live in an amap, but if we allocated
56 * an amap for the entire stack range we could end up wasting a large
57 * amount of malloc'd KVM.
58 *
59 * for example, on the i386 at boot time we allocate two amaps for the stack
60 * of /sbin/init:
61 * 1. a 7680 slot amap at protection 0 (reserve space for stack)
62 * 2. a 512 slot amap at protection 7 (top of stack)
63 *
64 * most of that VM is never mapped or used.
65 *
66 * to avoid allocating amap resources for the whole range we have the
67 * VM system look for maps that are larger than UVM_AMAP_LARGE slots
68 * (note that 1 slot = 1 vm_page). for maps that are large, we attempt
69 * to break them up into UVM_AMAP_CHUNK slot sized amaps.
70 *
71 * so, in the i386 example, the 7680 slot area is never referenced so
72 * nothing gets allocated. the 512 slot area is referenced, and it
73 * gets divided into 16 slot chunks (hopefully with one 16 slot chunk
74 * being enough to handle the whole stack...).
75 */
76
77 #define UVM_AMAP_LARGE 256 /* # of slots in "large" amap */
78 #define UVM_AMAP_CHUNK 16 /* # of slots to chunk large amaps in */
79
80
81 #ifdef DIAGNOSTIC
82 #define AMAP_B2SLOT(S,B) { \
83 if ((B) % PAGE_SIZE) \
84 panic("AMAP_B2SLOT: invalid byte count"); \
85 (S) = (B) / PAGE_SIZE; \
86 }
87 #else
88 #define AMAP_B2SLOT(S,B) (S) = (B) / PAGE_SIZE
89 #endif
90
91 #ifdef VM_AMAP_PPREF
92 #define PPREF_NONE ((int *) -1)
93 #endif
94
95 /*
96 * handle inline options
97 */
98
99 #ifdef UVM_AMAP_INLINE
100 #define AMAP_INLINE static __inline
101 #else
102 #define AMAP_INLINE /* nothing */
103 #endif /* UVM_AMAP_INLINE */
104
105 /*
106 * prototypes: the following prototypes define the interface to amaps
107 */
108
109 AMAP_INLINE vaddr_t amap_add __P((struct vm_aref *, vaddr_t,
110 struct vm_anon *, int));
111 struct vm_amap *amap_alloc __P((vaddr_t, vaddr_t, int));
112 void amap_copy __P((vm_map_t, vm_map_entry_t, int, boolean_t,
113 vaddr_t, vaddr_t));
114 void amap_cow_now __P((vm_map_t, vm_map_entry_t));
115 void amap_extend __P((vm_map_entry_t, vsize_t));
116 void amap_free __P((struct vm_amap *));
117 AMAP_INLINE struct vm_anon *amap_lookup __P((struct vm_aref *, vaddr_t));
118 AMAP_INLINE void amap_lookups __P((struct vm_aref *, vaddr_t,
119 struct vm_anon **, int));
120 #ifdef VM_AMAP_PPREF
121 void amap_pp_adjref __P((struct vm_amap *, int, vsize_t, int));
122 void amap_pp_establish __P((struct vm_amap *));
123 #endif
124 AMAP_INLINE void amap_ref __P((vm_map_entry_t, int));
125 void amap_share_protect __P((vm_map_entry_t, vm_prot_t));
126 void amap_splitref __P((struct vm_aref *, struct vm_aref *, vaddr_t));
127 AMAP_INLINE void amap_unadd __P((struct vm_amap *, vaddr_t));
128 AMAP_INLINE void amap_unref __P((vm_map_entry_t, int));
129 void amap_wipeout __P((struct vm_amap *));
130 #ifdef VM_AMAP_PPREF
131 void amap_wiperange __P((struct vm_amap *, int, int));
132 #endif
133
134 struct vm_anon *uvm_analloc __P((void));
135 void uvm_anfree __P((struct vm_anon *));
136 void uvm_anon_init __P((void));
137 void uvm_anon_add __P((int));
138 struct vm_page *uvm_anon_lockloanpg __P((struct vm_anon *));
139
140 #endif /* _UVM_UVM_AMAP_H_ */
141