uvm_anon.h revision 1.2 1 1.2 thorpej /* $NetBSD: uvm_anon.h,v 1.2 1998/02/06 22:31:35 thorpej Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * XXXCDC: "ROUGH DRAFT" QUALITY UVM PRE-RELEASE FILE!
5 1.1 mrg * >>>USE AT YOUR OWN RISK, WORK IS NOT FINISHED<<<
6 1.1 mrg */
7 1.1 mrg /*
8 1.1 mrg *
9 1.1 mrg * Copyright (c) 1997 Charles D. Cranor and Washington University.
10 1.1 mrg * All rights reserved.
11 1.1 mrg *
12 1.1 mrg * Redistribution and use in source and binary forms, with or without
13 1.1 mrg * modification, are permitted provided that the following conditions
14 1.1 mrg * are met:
15 1.1 mrg * 1. Redistributions of source code must retain the above copyright
16 1.1 mrg * notice, this list of conditions and the following disclaimer.
17 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 mrg * notice, this list of conditions and the following disclaimer in the
19 1.1 mrg * documentation and/or other materials provided with the distribution.
20 1.1 mrg * 3. All advertising materials mentioning features or use of this software
21 1.1 mrg * must display the following acknowledgement:
22 1.1 mrg * This product includes software developed by Charles D. Cranor and
23 1.1 mrg * Washington University.
24 1.1 mrg * 4. The name of the author may not be used to endorse or promote products
25 1.1 mrg * derived from this software without specific prior written permission.
26 1.1 mrg *
27 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 1.1 mrg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 1.1 mrg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 1.1 mrg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 1.1 mrg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 1.1 mrg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 1.1 mrg */
38 1.1 mrg
39 1.1 mrg /*
40 1.1 mrg * uvm_anon.h
41 1.1 mrg */
42 1.1 mrg
43 1.1 mrg /*
44 1.1 mrg * anonymous memory management
45 1.1 mrg *
46 1.1 mrg * anonymous virtual memory is short term virtual memory that goes away
47 1.1 mrg * when the processes referencing it go away. an anonymous page of
48 1.1 mrg * virtual memory is described by the following data structure:
49 1.1 mrg */
50 1.1 mrg
51 1.1 mrg struct vm_anon {
52 1.1 mrg int an_ref; /* reference count [an_lock] */
53 1.1 mrg #if NCPU > 1
54 1.1 mrg simple_lock_data_t an_lock; /* lock for an_ref */
55 1.1 mrg #endif
56 1.1 mrg union {
57 1.1 mrg struct vm_anon *an_nxt; /* if on free list [afreelock] */
58 1.1 mrg struct vm_page *an_page; /* if in RAM [pageqlock] */
59 1.1 mrg } u;
60 1.1 mrg int an_swslot; /* drum swap slot # (if != 0) [pageqlock] */
61 1.1 mrg };
62 1.1 mrg
63 1.1 mrg /*
64 1.1 mrg * a pool of vm_anon data structures is allocated and put on a global
65 1.1 mrg * free list at boot time. vm_anon's on the free list use "an_nxt" as
66 1.1 mrg * a pointer to the next item on the free list. for active vm_anon's
67 1.1 mrg * the data can be in one of the following state: [1] in a vm_page
68 1.1 mrg * with no backing store allocated yet, [2] in a vm_page with backing
69 1.1 mrg * store allocated, or [3] paged out to backing store (no vm_page).
70 1.1 mrg *
71 1.1 mrg * for pageout in case [2]: if the page has been modified then we must
72 1.1 mrg * flush it out to backing store, otherwise we can just dump the
73 1.1 mrg * vm_page.
74 1.1 mrg */
75 1.1 mrg
76 1.1 mrg /*
77 1.1 mrg * anonymous virtual memory pages (vm_anon's) live in anonymous memory
78 1.1 mrg * maps. anonymous memory maps can be shared between processes.
79 1.1 mrg * different subsets of an anonymous memory map can be referenced by
80 1.1 mrg * processes (see below). an anonymous map is described by the following
81 1.1 mrg * data structure:
82 1.1 mrg */
83 1.1 mrg
84 1.1 mrg #define VM_AMAP_PPREF /* use a per-page reference count for split
85 1.1 mrg vm_map_entry_t's. */
86 1.1 mrg
87 1.1 mrg struct vm_amap {
88 1.1 mrg #if NCPU > 1
89 1.1 mrg simple_lock_data_t am_l; /* simple lock [locks all vm_amap fields] */
90 1.1 mrg #endif
91 1.1 mrg int am_ref; /* reference count */
92 1.1 mrg int am_flags; /* flags */
93 1.1 mrg int am_maxslot; /* max # of slots allocated */
94 1.1 mrg int am_nslot; /* # of slots currently in map ( <= maxslot) */
95 1.1 mrg int am_nused; /* # of slots currently in use */
96 1.1 mrg int *am_slots; /* contig array of active slots */
97 1.1 mrg int *am_bckptr; /* back pointer array to am_slots */
98 1.1 mrg struct vm_anon **am_anon; /* array of anonymous pages */
99 1.1 mrg #ifdef VM_AMAP_PPREF
100 1.1 mrg int *am_ppref; /* per page reference count (if !NULL) */
101 1.1 mrg #endif
102 1.1 mrg };
103 1.1 mrg
104 1.1 mrg #define AMAP_SHARED 0x1 /* am_flags: shared amap */
105 1.1 mrg #define AMAP_REFALL 0x2 /* flag to amap_ref() */
106 1.1 mrg
107 1.1 mrg /*
108 1.1 mrg * note that am_slots, am_bckptr, and am_anon are arrays. this allows
109 1.1 mrg * fast lookup of pages based on their virual address at the expense of
110 1.1 mrg * some extra memory. [XXX: for memory starved systems provide alternate
111 1.1 mrg * functions?]
112 1.1 mrg *
113 1.1 mrg * 4 slot/page example, with slots 1 and 3 in use:
114 1.1 mrg * ("D/C" == don't care what the value is)
115 1.1 mrg *
116 1.1 mrg * 0 1 2 3
117 1.1 mrg * am_anon: NULL, anon0, NULL, anon1 (actual pointers to anons)
118 1.1 mrg * am_bckptr: D/C, 1, D/C, 0 (points to am_slots entry)
119 1.1 mrg *
120 1.1 mrg * am_slots: 3, 1, D/C, D/C (says slots 3 and 1 are in use)
121 1.1 mrg *
122 1.1 mrg * note that am_bckptr is D/C if the slot in am_anon is set to NULL.
123 1.1 mrg * to find the entry in am_slots for an anon, look at am_bckptr[slot],
124 1.1 mrg * thus the entry for slot 3 in am_slots[] is at am_slots[am_bckptr[3]].
125 1.1 mrg * in general, if am_anon[X] is non-NULL, then the following must be
126 1.1 mrg * true: am_slots[am_bckptr[X]] == X
127 1.1 mrg *
128 1.1 mrg * note that am_slots is always contig-packed.
129 1.1 mrg */
130 1.1 mrg
131 1.1 mrg /*
132 1.1 mrg * processes reference anonymous virtual memory maps with an anonymous
133 1.1 mrg * reference structure:
134 1.1 mrg */
135 1.1 mrg
136 1.1 mrg struct vm_aref {
137 1.1 mrg int ar_slotoff; /* slot offset into amap we start */
138 1.1 mrg struct vm_amap *ar_amap; /* pointer to amap */
139 1.1 mrg };
140 1.1 mrg
141 1.1 mrg /*
142 1.1 mrg * the offset field indicates which part of the amap we are referencing.
143 1.1 mrg * locked by vm_map lock.
144 1.1 mrg */
145 1.1 mrg
146