xref: /freebsd/sys/vm/vm.h (revision 0dd7789512a11019bc958efaaedfeada434dea8f)
160727d8bSWarner Losh /*-
2796df753SPedro F. Giffuni  * SPDX-License-Identifier: (BSD-3-Clause AND MIT-CMU)
351369649SPedro F. Giffuni  *
4df8bae1dSRodney W. Grimes  * Copyright (c) 1991, 1993
5df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
6df8bae1dSRodney W. Grimes  *
7df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
8df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
9df8bae1dSRodney W. Grimes  * are met:
10df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
12df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
13df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
14df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
16df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
17df8bae1dSRodney W. Grimes  *    without specific prior written permission.
18df8bae1dSRodney W. Grimes  *
19df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
30df8bae1dSRodney W. Grimes  *
31923502ffSPoul-Henning Kamp  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
32923502ffSPoul-Henning Kamp  * All rights reserved.
33923502ffSPoul-Henning Kamp  *
34923502ffSPoul-Henning Kamp  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
35923502ffSPoul-Henning Kamp  *
36923502ffSPoul-Henning Kamp  * Permission to use, copy, modify and distribute this software and
37923502ffSPoul-Henning Kamp  * its documentation is hereby granted, provided that both the copyright
38923502ffSPoul-Henning Kamp  * notice and this permission notice appear in all copies of the
39923502ffSPoul-Henning Kamp  * software, derivative works or modified versions, and any portions
40923502ffSPoul-Henning Kamp  * thereof, and that both notices appear in supporting documentation.
41923502ffSPoul-Henning Kamp  *
42923502ffSPoul-Henning Kamp  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43923502ffSPoul-Henning Kamp  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
44923502ffSPoul-Henning Kamp  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45923502ffSPoul-Henning Kamp  *
46923502ffSPoul-Henning Kamp  * Carnegie Mellon requests users of this software to return to
47923502ffSPoul-Henning Kamp  *
48923502ffSPoul-Henning Kamp  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
49923502ffSPoul-Henning Kamp  *  School of Computer Science
50923502ffSPoul-Henning Kamp  *  Carnegie Mellon University
51923502ffSPoul-Henning Kamp  *  Pittsburgh PA 15213-3890
52923502ffSPoul-Henning Kamp  *
53923502ffSPoul-Henning Kamp  * any improvements or extensions that they make and grant Carnegie the
54923502ffSPoul-Henning Kamp  * rights to redistribute these changes.
55df8bae1dSRodney W. Grimes  */
56df8bae1dSRodney W. Grimes 
57df8bae1dSRodney W. Grimes #ifndef VM_H
58df8bae1dSRodney W. Grimes #define VM_H
59df8bae1dSRodney W. Grimes 
60e999111aSAlan Cox #include <machine/vm.h>
61e999111aSAlan Cox 
62923502ffSPoul-Henning Kamp typedef char vm_inherit_t;	/* inheritance codes */
63923502ffSPoul-Henning Kamp 
64923502ffSPoul-Henning Kamp #define	VM_INHERIT_SHARE	((vm_inherit_t) 0)
65923502ffSPoul-Henning Kamp #define	VM_INHERIT_COPY		((vm_inherit_t) 1)
66923502ffSPoul-Henning Kamp #define	VM_INHERIT_NONE		((vm_inherit_t) 2)
6778d7964bSXin LI #define	VM_INHERIT_ZERO		((vm_inherit_t) 3)
68923502ffSPoul-Henning Kamp #define	VM_INHERIT_DEFAULT	VM_INHERIT_COPY
69923502ffSPoul-Henning Kamp 
70efeaf95aSDavid Greenman typedef u_char vm_prot_t;	/* protection codes */
71df8bae1dSRodney W. Grimes 
72923502ffSPoul-Henning Kamp #define	VM_PROT_NONE		((vm_prot_t) 0x00)
73923502ffSPoul-Henning Kamp #define	VM_PROT_READ		((vm_prot_t) 0x01)
74923502ffSPoul-Henning Kamp #define	VM_PROT_WRITE		((vm_prot_t) 0x02)
75923502ffSPoul-Henning Kamp #define	VM_PROT_EXECUTE		((vm_prot_t) 0x04)
76a6d42a0dSAlan Cox #define	VM_PROT_COPY		((vm_prot_t) 0x08)	/* copy-on-read */
778ec533d3SKonstantin Belousov #define	VM_PROT_PRIV_FLAG	((vm_prot_t) 0x10)
788ec533d3SKonstantin Belousov #define	VM_PROT_FAULT_LOOKUP	VM_PROT_PRIV_FLAG
79*f1d73aacSAlan Cox #define	VM_PROT_NO_PROMOTE	VM_PROT_PRIV_FLAG
808ec533d3SKonstantin Belousov #define	VM_PROT_QUICK_NOFAULT	VM_PROT_PRIV_FLAG	/* same to save bits */
81923502ffSPoul-Henning Kamp 
82923502ffSPoul-Henning Kamp #define	VM_PROT_ALL		(VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE)
83fa7dd9c5SMatthew Dillon #define VM_PROT_RW		(VM_PROT_READ|VM_PROT_WRITE)
84923502ffSPoul-Henning Kamp #define	VM_PROT_DEFAULT		VM_PROT_ALL
85923502ffSPoul-Henning Kamp 
86838adc53SKonstantin Belousov enum obj_type {
871424f65bSMark Johnston 	OBJT_RESERVED = 0,	/* was OBJT_DEFAULT */
88838adc53SKonstantin Belousov 	OBJT_SWAP,
891424f65bSMark Johnston 	OBJT_DEFAULT = OBJT_SWAP,
90838adc53SKonstantin Belousov 	OBJT_VNODE,
91838adc53SKonstantin Belousov 	OBJT_DEVICE,
92838adc53SKonstantin Belousov 	OBJT_PHYS,
93838adc53SKonstantin Belousov 	OBJT_DEAD,
94838adc53SKonstantin Belousov 	OBJT_SG,
95838adc53SKonstantin Belousov 	OBJT_MGTDEVICE,
96b730fd30SKonstantin Belousov 	OBJT_FIRST_DYN,
97838adc53SKonstantin Belousov };
9898df9218SJohn Baldwin typedef u_char objtype_t;
9998df9218SJohn Baldwin 
100df8bae1dSRodney W. Grimes union vm_map_object;
101df8bae1dSRodney W. Grimes typedef union vm_map_object vm_map_object_t;
102df8bae1dSRodney W. Grimes 
103df8bae1dSRodney W. Grimes struct vm_map_entry;
104df8bae1dSRodney W. Grimes typedef struct vm_map_entry *vm_map_entry_t;
105df8bae1dSRodney W. Grimes 
106df8bae1dSRodney W. Grimes struct vm_map;
107df8bae1dSRodney W. Grimes typedef struct vm_map *vm_map_t;
108df8bae1dSRodney W. Grimes 
109df8bae1dSRodney W. Grimes struct vm_object;
110df8bae1dSRodney W. Grimes typedef struct vm_object *vm_object_t;
111df8bae1dSRodney W. Grimes 
112c4473420SPeter Wemm #ifndef _KERNEL
1130ff89d5bSBruce Evans /*
1145ad9d5a7SBruce Evans  * This is defined in <sys/types.h> for the kernel so that non-vm kernel
1155ad9d5a7SBruce Evans  * sources (mainly Mach-derived ones such as ddb) don't have to include
1165ad9d5a7SBruce Evans  * vm stuff.  Defining it there for applications might break things.
1175ad9d5a7SBruce Evans  * Define it here for "applications" that include vm headers (e.g.,
1185ad9d5a7SBruce Evans  * genassym).
1195ad9d5a7SBruce Evans  */
1209e5787d2SMatt Macy #ifndef HAVE_BOOLEAN
1215ad9d5a7SBruce Evans typedef int boolean_t;
1229e5787d2SMatt Macy #endif
1235ad9d5a7SBruce Evans 
1245ad9d5a7SBruce Evans /*
125cc981af2SJohn Baldwin  * The exact set of memory attributes is machine dependent.  However,
126cc981af2SJohn Baldwin  * every machine is required to define VM_MEMATTR_DEFAULT and
127cc981af2SJohn Baldwin  * VM_MEMATTR_UNCACHEABLE.
1282fa8c8d2SJohn Baldwin  */
1292fa8c8d2SJohn Baldwin typedef	char vm_memattr_t;	/* memory attribute codes */
1302fa8c8d2SJohn Baldwin 
1312fa8c8d2SJohn Baldwin /*
1320ff89d5bSBruce Evans  * This is defined in <sys/types.h> for the kernel so that vnode_if.h
1330ff89d5bSBruce Evans  * doesn't have to include <vm/vm.h>.
1340ff89d5bSBruce Evans  */
135df8bae1dSRodney W. Grimes struct vm_page;
136df8bae1dSRodney W. Grimes typedef struct vm_page *vm_page_t;
137a1287949SEivind Eklund #endif				/* _KERNEL */
138df8bae1dSRodney W. Grimes 
139ae0fee95SAlan Cox struct vm_reserv;
140ae0fee95SAlan Cox typedef struct vm_reserv *vm_reserv_t;
141ae0fee95SAlan Cox 
142219d632cSMatthew Dillon /*
143860740aeSGordon Bergling  * Information passed from the machine-independent VM initialization code
144219d632cSMatthew Dillon  * for use by machine-dependant code (mainly for MMU support)
145219d632cSMatthew Dillon  */
146219d632cSMatthew Dillon struct kva_md_info {
147219d632cSMatthew Dillon 	vm_offset_t	buffer_sva;
148219d632cSMatthew Dillon 	vm_offset_t	buffer_eva;
149219d632cSMatthew Dillon 	vm_offset_t	clean_sva;
150219d632cSMatthew Dillon 	vm_offset_t	clean_eva;
151219d632cSMatthew Dillon };
152219d632cSMatthew Dillon 
153a6cc4c6eSKonstantin Belousov /* bits from overcommit */
154a6cc4c6eSKonstantin Belousov #define	SWAP_RESERVE_FORCE_ON		(1 << 0)
155a6cc4c6eSKonstantin Belousov #define	SWAP_RESERVE_RLIMIT_ON		(1 << 1)
156a6cc4c6eSKonstantin Belousov #define	SWAP_RESERVE_ALLOW_NONWIRED	(1 << 2)
157a6cc4c6eSKonstantin Belousov 
158cb20a74cSStephen J. Kiernan #ifdef NUMA
159cb20a74cSStephen J. Kiernan #define	__numa_used
160cb20a74cSStephen J. Kiernan #else
161cb20a74cSStephen J. Kiernan #define	__numa_used	__unused
162cb20a74cSStephen J. Kiernan #endif
163cb20a74cSStephen J. Kiernan 
164ee744122SMateusz Guzik #ifdef _KERNEL
165ef694c1aSEdward Tomasz Napierala struct ucred;
16655c52165SKonstantin Belousov 
16755c52165SKonstantin Belousov void vm_ksubmap_init(struct kva_md_info *);
168ee744122SMateusz Guzik bool swap_reserve(vm_ooffset_t incr);
169ee744122SMateusz Guzik bool swap_reserve_by_cred(vm_ooffset_t incr, struct ucred *cred);
1703364c323SKonstantin Belousov void swap_reserve_force(vm_ooffset_t incr);
1713364c323SKonstantin Belousov void swap_release(vm_ooffset_t decr);
172ef694c1aSEdward Tomasz Napierala void swap_release_by_cred(vm_ooffset_t decr, struct ucred *cred);
17355c52165SKonstantin Belousov 
17455c52165SKonstantin Belousov extern struct kva_md_info	kmi;
17555c52165SKonstantin Belousov #define VA_IS_CLEANMAP(va)					\
17655c52165SKonstantin Belousov 	((va) >= kmi.clean_sva && (va) < kmi.clean_eva)
17755c52165SKonstantin Belousov 
17855c52165SKonstantin Belousov extern int old_mlock;
17955c52165SKonstantin Belousov extern int vm_ndomains;
18055c52165SKonstantin Belousov extern int vm_overcommit;
18155c52165SKonstantin Belousov #endif				/* _KERNEL */
1823364c323SKonstantin Belousov 
183df8bae1dSRodney W. Grimes #endif				/* VM_H */
184