xref: /openbsd-src/sys/uvm/uvm.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: uvm.h,v 1.61 2016/08/11 01:17:33 dlg Exp $	*/
2 /*	$NetBSD: uvm.h,v 1.24 2000/11/27 08:40:02 chs Exp $	*/
3 
4 /*
5  * Copyright (c) 1997 Charles D. Cranor and Washington University.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * from: Id: uvm.h,v 1.1.2.14 1998/02/02 20:07:19 chuck Exp
29  */
30 
31 #ifndef _UVM_UVM_H_
32 #define _UVM_UVM_H_
33 
34 #include <uvm/uvm_extern.h>
35 #include <uvm/uvm_amap.h>
36 #include <uvm/uvm_aobj.h>
37 #include <uvm/uvm_fault.h>
38 #include <uvm/uvm_glue.h>
39 #include <uvm/uvm_km.h>
40 #include <uvm/uvm_swap.h>
41 
42 #include <uvm/uvm_pmemrange.h>
43 
44 /*
45  * uvm structure (vm global state: collected in one structure for ease
46  * of reference...)
47  */
48 
49 struct uvm {
50 	/* vm_page related parameters */
51 
52 	/* vm_page queues */
53 	struct pglist page_active;	/* allocated pages, in use */
54 	struct pglist page_inactive_swp;/* pages inactive (reclaim or free) */
55 	struct pglist page_inactive_obj;/* pages inactive (reclaim or free) */
56 	/* Lock order: pageqlock, then fpageqlock. */
57 	struct mutex pageqlock;		/* lock for active/inactive page q */
58 	struct mutex fpageqlock;	/* lock for free page q  + pdaemon */
59 	boolean_t page_init_done;	/* TRUE if uvm_page_init() finished */
60 	struct uvm_pmr_control pmr_control; /* pmemrange data */
61 
62 		/* page daemon trigger */
63 	int pagedaemon;			/* daemon sleeps on this */
64 	struct proc *pagedaemon_proc;	/* daemon's pid */
65 
66 		/* aiodone daemon trigger */
67 	int aiodoned;			/* daemon sleeps on this */
68 	struct proc *aiodoned_proc;	/* daemon's pid */
69 	struct mutex aiodoned_lock;
70 
71 	/* static kernel map entry pool */
72 	SLIST_HEAD(, vm_map_entry) kentry_free; /* free page pool */
73 
74 	/* aio_done is locked by uvm.aiodoned_lock. */
75 	TAILQ_HEAD(, buf) aio_done;		/* done async i/o reqs */
76 
77 	/* kernel object: to support anonymous pageable kernel memory */
78 	struct uvm_object *kernel_object;
79 };
80 
81 /*
82  * vm_map_entry etype bits:
83  */
84 
85 #define UVM_ET_OBJ		0x01	/* it is a uvm_object */
86 #define UVM_ET_SUBMAP		0x02	/* it is a vm_map submap */
87 #define UVM_ET_COPYONWRITE 	0x04	/* copy_on_write */
88 #define UVM_ET_NEEDSCOPY	0x08	/* needs_copy */
89 #define UVM_ET_HOLE		0x10	/* no backend */
90 #define UVM_ET_NOFAULT		0x20	/* don't fault */
91 #define UVM_ET_FREEMAPPED	0x80	/* map entry is on free list (DEBUG) */
92 
93 #define UVM_ET_ISOBJ(E)		(((E)->etype & UVM_ET_OBJ) != 0)
94 #define UVM_ET_ISSUBMAP(E)	(((E)->etype & UVM_ET_SUBMAP) != 0)
95 #define UVM_ET_ISCOPYONWRITE(E)	(((E)->etype & UVM_ET_COPYONWRITE) != 0)
96 #define UVM_ET_ISNEEDSCOPY(E)	(((E)->etype & UVM_ET_NEEDSCOPY) != 0)
97 #define UVM_ET_ISHOLE(E)	(((E)->etype & UVM_ET_HOLE) != 0)
98 #define UVM_ET_ISNOFAULT(E)	(((E)->etype & UVM_ET_NOFAULT) != 0)
99 
100 #ifdef _KERNEL
101 
102 /*
103  * holds all the internal UVM data
104  */
105 extern struct uvm uvm;
106 
107 /*
108  * UVM_WAIT: wait... wrapper around the tsleep() function.
109  */
110 
111 #define	UVM_WAIT(event, intr, msg, timo)				\
112 do {									\
113 	tsleep(event, PVM|(intr ? PCATCH : 0), msg, timo);		\
114 } while (0)
115 
116 /*
117  * UVM_PAGE_OWN: track page ownership (only if UVM_PAGE_TRKOWN)
118  */
119 
120 #if defined(UVM_PAGE_TRKOWN)
121 #define UVM_PAGE_OWN(PG, TAG) uvm_page_own(PG, TAG)
122 #else
123 #define UVM_PAGE_OWN(PG, TAG) /* nothing */
124 #endif /* UVM_PAGE_TRKOWN */
125 
126 /*
127  * uvm_map internal functions.
128  * Used by uvm_map address selectors.
129  */
130 struct vm_map_entry	*uvm_map_entrybyaddr(struct uvm_map_addr *, vaddr_t);
131 int			 uvm_map_isavail(struct vm_map *,
132 			    struct uvm_addr_state *,
133 			    struct vm_map_entry **, struct vm_map_entry**,
134 			    vaddr_t, vsize_t);
135 struct uvm_addr_state	*uvm_map_uaddr(struct vm_map *, vaddr_t);
136 struct uvm_addr_state	*uvm_map_uaddr_e(struct vm_map *, struct vm_map_entry *);
137 
138 #define VMMAP_FREE_START(_entry)	((_entry)->end + (_entry)->guard)
139 #define VMMAP_FREE_END(_entry)		((_entry)->end + (_entry)->guard + \
140 					    (_entry)->fspace)
141 
142 #endif /* _KERNEL */
143 
144 #endif /* _UVM_UVM_H_ */
145